Java Code Examples for org.codehaus.groovy.ast.ClassNode#addInterface()
The following examples show how to use
org.codehaus.groovy.ast.ClassNode#addInterface() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExternalizeMethodsASTTransformation.java From groovy with Apache License 2.0 | 6 votes |
public void visit(ASTNode[] nodes, SourceUnit source) { init(nodes, source); AnnotatedNode parent = (AnnotatedNode) nodes[1]; AnnotationNode anno = (AnnotationNode) nodes[0]; if (!MY_TYPE.equals(anno.getClassNode())) return; if (parent instanceof ClassNode) { ClassNode cNode = (ClassNode) parent; if (!checkNotInterface(cNode, MY_TYPE_NAME)) return; cNode.addInterface(EXTERNALIZABLE_TYPE); boolean includeFields = memberHasValue(anno, "includeFields", true); List<String> excludes = getMemberStringList(anno, "excludes"); if (!checkPropertyList(cNode, excludes, "excludes", anno, MY_TYPE_NAME, includeFields)) return; List<FieldNode> list = getInstancePropertyFields(cNode); if (includeFields) { list.addAll(getInstanceNonPropertyFields(cNode)); } createWriteExternal(cNode, excludes, list); createReadExternal(cNode, excludes, list); } }
Example 2
Source File: InnerClassVisitor.java From groovy with Apache License 2.0 | 6 votes |
@Override public void visitClass(ClassNode node) { classNode = node; InnerClassNode innerClass = null; if (!node.isEnum() && !node.isInterface() && node instanceof InnerClassNode) { innerClass = (InnerClassNode) node; if (innerClass.getVariableScope() == null && (innerClass.getModifiers() & ACC_STATIC) == 0) { innerClass.addField("this$0", ACC_FINAL | ACC_SYNTHETIC, node.getOuterClass().getPlainNodeReference(), null); } } super.visitClass(node); if (node.isEnum() || node.isInterface()) return; if (innerClass == null) return; if (node.getSuperClass().isInterface() || Traits.isAnnotatedWithTrait(node.getSuperClass())) { node.addInterface(node.getUnresolvedSuperClass()); node.setUnresolvedSuperClass(ClassHelper.OBJECT_TYPE); } }
Example 3
Source File: AutoCloneASTTransformation.java From groovy with Apache License 2.0 | 5 votes |
public void visit(ASTNode[] nodes, SourceUnit source) { init(nodes, source); AnnotatedNode parent = (AnnotatedNode) nodes[1]; AnnotationNode anno = (AnnotationNode) nodes[0]; if (!MY_TYPE.equals(anno.getClassNode())) return; if (parent instanceof ClassNode) { ClassNode cNode = (ClassNode) parent; if (!checkNotInterface(cNode, MY_TYPE_NAME)) return; cNode.addInterface(CLONEABLE_TYPE); boolean includeFields = memberHasValue(anno, "includeFields", true); AutoCloneStyle style = getStyle(anno, "style"); List<String> excludes = getMemberStringList(anno, "excludes"); if (!checkPropertyList(cNode, excludes, "excludes", anno, MY_TYPE_NAME, includeFields)) return; List<FieldNode> list = getInstancePropertyFields(cNode); if (includeFields) { list.addAll(getInstanceNonPropertyFields(cNode)); } if (style == null) style = AutoCloneStyle.CLONE; switch (style) { case COPY_CONSTRUCTOR: createCloneCopyConstructor(cNode, list, excludes); break; case SERIALIZATION: createCloneSerialization(cNode); break; case SIMPLE: createSimpleClone(cNode, list, excludes); break; default: createClone(cNode, list, excludes); break; } } }
Example 4
Source File: TraitASTTransformation.java From groovy with Apache License 2.0 | 5 votes |
private void replaceExtendsByImplements(final ClassNode cNode) { ClassNode superClass = cNode.getUnresolvedSuperClass(); if (Traits.isTrait(superClass)) { // move from super class to interface; cNode.setSuperClass(ClassHelper.OBJECT_TYPE); cNode.setUnresolvedSuperClass(ClassHelper.OBJECT_TYPE); cNode.addInterface(superClass); resolveScope(cNode); } }
Example 5
Source File: ClosureWriter.java From groovy with Apache License 2.0 | 5 votes |
public ClassNode getOrAddClosureClass(final ClosureExpression expression, final int modifiers) { ClassNode closureClass = closureClasses.get(expression); if (closureClass == null) { closureClass = createClosureClass(expression, modifiers); closureClasses.put(expression, closureClass); controller.getAcg().addInnerClass(closureClass); closureClass.addInterface(ClassHelper.GENERATED_CLOSURE_Type); closureClass.putNodeMetaData(WriterControllerFactory.class, (WriterControllerFactory) x -> controller); } return closureClass; }
Example 6
Source File: SortableASTTransformation.java From groovy with Apache License 2.0 | 4 votes |
private static void implementComparable(ClassNode classNode) { if (!classNode.implementsInterface(COMPARABLE_TYPE)) { classNode.addInterface(makeClassSafeWithGenerics(Comparable.class, classNode)); } }