public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(source, JavaAwareCompilationUnit.this.getTransformLoader()); collector.visitClass(classNode); } }, Phases.CONVERSION);
int index = 0; for (AnnotationNode annotation : node.getAnnotations()) { findCollectedAnnotations(annotation, node, index, modes, existing, replacements); index++; Integer replacementIndex = entry.getKey(); List<AnnotationNode> annotationNodeList = entry.getValue(); mergeCollectedAnnotations(modes.get(replacementIndex), existing, annotationNodeList); existing.put(replacementIndex, annotationNodeList); Annotation transformClassAnnotation = getTransformClassAnnotation(annotation.getClassNode()); if (transformClassAnnotation == null) { addTransformsToClassNode(annotation, transformClassAnnotation);
private void addTransformsToClassNode(AnnotationNode annotation, Annotation transformClassAnnotation) { List<String> transformClassNames = getTransformClassNames(annotation, transformClassAnnotation); if (transformClassNames.isEmpty()) { source.getErrorCollector().addError(new SimpleMessage("@GroovyASTTransformationClass in " + annotation.getClassNode().getName() + " does not specify any transform class names/classes", source)); } for (String transformClass : transformClassNames) { Class klass = loadTransformClass(transformClass, annotation); if (klass != null) { verifyAndAddTransform(annotation, klass); } } }
private void verifyAndAddTransform(AnnotationNode annotation, Class klass) { verifyClass(annotation, klass); verifyCompilePhase(annotation, klass); addTransform(annotation, klass); }
/** * If the annotation is annotated with {@link GroovyASTTransformation} * the annotation is added to <code>stageVisitors</code> at the appropriate processor visitor. * * @param node the node to process */ public void visitAnnotations(AnnotatedNode node) { super.visitAnnotations(node); for (AnnotationNode annotation : (Collection<AnnotationNode>) node.getAnnotations()) { Annotation transformClassAnnotation = getTransformClassAnnotation(annotation.getClassNode()); if (transformClassAnnotation == null) { // skip if there is no such annotation continue; } addTransformsToClassNode(annotation, transformClassAnnotation); } }
private void addTransformsToClassNode(AnnotationNode annotation, Annotation transformClassAnnotation) { String[] transformClassNames = getTransformClassNames(transformClassAnnotation); Class[] transformClasses = getTransformClasses(transformClassAnnotation); if(transformClassNames.length == 0 && transformClasses.length == 0) { source.getErrorCollector().addError(new SimpleMessage("@GroovyASTTransformationClass in " + annotation.getClassNode().getName() + " does not specify any transform class names/classes", source)); } if(transformClassNames.length > 0 && transformClasses.length > 0) { source.getErrorCollector().addError(new SimpleMessage("@GroovyASTTransformationClass in " + annotation.getClassNode().getName() + " should specify transforms only by class names or by classes and not by both", source)); } for (String transformClass : transformClassNames) { try { Class klass = transformLoader.loadClass(transformClass, false, true, false); verifyClassAndAddTransform(annotation, klass); } catch (ClassNotFoundException e) { source.getErrorCollector().addErrorAndContinue( new SimpleMessage( "Could not find class for Transformation Processor " + transformClass + " declared by " + annotation.getClassNode().getName(), source)); } } for (Class klass : transformClasses) { verifyClassAndAddTransform(annotation, klass); } }
super.visitAnnotations(node); for (AnnotationNode annotation : (Collection<AnnotationNode>) node.getAnnotations()) { Annotation transformClassAnnotation = getTransformClassAnnotation(annotation.getClassNode()); if (transformClassAnnotation == null) { for (String transformClass : getTransformClasses(transformClassAnnotation)) { try { Class klass = transformLoader.loadClass(transformClass, false, true, false);
private void addTransformsToClassNode(AnnotationNode annotation, Annotation transformClassAnnotation) { List<String> transformClassNames = getTransformClassNames(annotation, transformClassAnnotation); if(transformClassNames.isEmpty()) { source.getErrorCollector().addError(new SimpleMessage("@GroovyASTTransformationClass in " + annotation.getClassNode().getName() + " does not specify any transform class names/classes", source)); } for (String transformClass : transformClassNames) { try { Class klass = transformLoader.loadClass(transformClass, false, true, false); verifyAndAddTransform(annotation, klass); } catch (ClassNotFoundException e) { source.getErrorCollector().addErrorAndContinue( new SimpleMessage( "Could not find class for Transformation Processor " + transformClass + " declared by " + annotation.getClassNode().getName(), source)); } } }
/** * If the annotation is annotated with {@link GroovyASTTransformation} * the annotation is added to <code>stageVisitors</code> at the appropriate processor visitor. * * @param node the node to process */ public void visitAnnotations(AnnotatedNode node) { super.visitAnnotations(node); for (AnnotationNode annotation : node.getAnnotations()) { Annotation transformClassAnnotation = getTransformClassAnnotation(annotation.getClassNode()); if (transformClassAnnotation == null) { // skip if there is no such annotation continue; } addTransformsToClassNode(annotation, transformClassAnnotation); } }
private void verifyAndAddTransform(AnnotationNode annotation, Class klass) { verifyClass(annotation, klass); verifyCompilePhase(annotation, klass); addTransform(annotation, klass); }
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(source, compilationUnit.getTransformLoader()); collector.visitClass(classNode); } }, Phases.SEMANTIC_ANALYSIS);
private void registerASTTransformations(final ClassNode helper) { ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor( unit, compilationUnit.getTransformLoader() ); collector.visitClass(helper); // Perform an additional phase which has to be done *after* type checking compilationUnit.addPhaseOperation(new CompilationUnit.PrimaryClassNodeOperation() { @Override public void call(final SourceUnit source, final GeneratorContext context, final ClassNode classNode) throws CompilationFailedException { if (classNode==helper) { PostTypeCheckingExpressionReplacer replacer = new PostTypeCheckingExpressionReplacer(source); replacer.visitClass(helper); } } }, CompilePhase.INSTRUCTION_SELECTION.getPhaseNumber()); }
/** * Given a class node, if this class node implements a trait, then generate all the appropriate * code which delegates calls to the trait. It is safe to call this method on a class node which * does not implement a trait. * @param cNode a class node * @param unit the source unit */ public static void doExtendTraits(final ClassNode cNode, final SourceUnit unit, final CompilationUnit cu) { if (cNode.isInterface()) return; boolean isItselfTrait = Traits.isTrait(cNode); SuperCallTraitTransformer superCallTransformer = new SuperCallTraitTransformer(unit); if (isItselfTrait) { checkTraitAllowed(cNode, unit); return; } if (!cNode.getNameWithoutPackage().endsWith(Traits.TRAIT_HELPER)) { List<ClassNode> traits = findTraits(cNode); for (ClassNode trait : traits) { TraitHelpersTuple helpers = Traits.findHelpers(trait); applyTrait(trait, cNode, helpers, unit); superCallTransformer.visitClass(cNode); if (unit!=null) { ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(unit, cu.getTransformLoader()); collector.visitClass(cNode); } } } }
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(source, compilationUnit.getTransformLoader()); collector.visitClass(classNode); } }, Phases.SEMANTIC_ANALYSIS);
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(source, compilationUnit.getTransformLoader()); collector.visitClass(classNode); } }, Phases.SEMANTIC_ANALYSIS);
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode) throws CompilationFailedException { ASTTransformationCollectorCodeVisitor collector = new ASTTransformationCollectorCodeVisitor(source, compilationUnit.getTransformLoader()); collector.visitClass(classNode); } }, Phases.SEMANTIC_ANALYSIS);