org.codehaus.groovy.transform
Class ASTTransformationVisitor
java.lang.Object
org.codehaus.groovy.ast.CodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeVisitorSupport
org.codehaus.groovy.transform.ASTTransformationVisitor
- All Implemented Interfaces:
- GroovyClassVisitor, GroovyCodeVisitor
public class ASTTransformationVisitor
- extends ClassCodeVisitorSupport
This class handles the invocation of the ASTAnnotationTransformation
when it is encountered by a tree walk. One instance of each exists
for each phase of the compilation it applies to. Before invocation the
ASTTransformationCollectorCodeVisitor
will add a list
of annotations that this visitor should be concerned about. All other
annotations are ignored, whether or not they are GroovyASTTransformation
annotated or not.
A Two-pass method is used. First all candidate annotations are added to a
list then the transformations are called on those collected annotations.
This is done to avoid concurrent modification exceptions during the AST tree
walk and allows the transformations to alter any portion of the AST tree.
Hence annotations that are added in this phase will not be processed as
transformations. They will only be handled in later phases (and then only
if the type was in the AST prior to any AST transformations being run
against it).
- Author:
- Danno Ferrin (shemnon)
Methods inherited from class org.codehaus.groovy.ast.ClassCodeVisitorSupport |
addError, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCaseStatement, visitCatchStatement, visitClassCodeContainer, visitConstructor, visitConstructorOrMethod, visitContinueStatement, visitDoWhileLoop, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitMethod, visitProperty, visitReturnStatement, visitStatement, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitTryCatchFinally, visitWhileLoop |
Methods inherited from class org.codehaus.groovy.ast.CodeVisitorSupport |
visitArgumentlistExpression, visitArrayExpression, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBooleanExpression, visitBytecodeExpression, visitCastExpression, visitClassExpression, visitClosureExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitDeclarationExpression, visitFieldExpression, visitGStringExpression, visitListExpression, visitListOfExpressions, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitRegexExpression, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitTernaryExpression, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
phase
private CompilePhase phase
source
private SourceUnit source
targetNodes
private java.util.List<ASTNode[]> targetNodes
transforms
private java.util.Map<ASTNode,java.util.List<ASTTransformation>> transforms
transformInstances
private java.util.Map<java.lang.Class<? extends ASTTransformation>,ASTTransformation> transformInstances
ASTTransformationVisitor
private ASTTransformationVisitor(CompilePhase phase)
getSourceUnit
protected SourceUnit getSourceUnit()
- Specified by:
getSourceUnit
in class ClassCodeVisitorSupport
visitClass
public void visitClass(ClassNode classNode)
- Main loop entry.
First, it delegates to the super visitClass so we can collect the
relevant annotations in an AST tree walk.
Second, it calls the visit method on the transformation for each relevant
annotation found.
- Specified by:
visitClass
in interface GroovyClassVisitor
- Overrides:
visitClass
in class ClassCodeVisitorSupport
- Parameters:
classNode
- the class to visit
visitAnnotations
public void visitAnnotations(AnnotatedNode node)
- Adds the annotation to the internal target list if a match is found.
- Overrides:
visitAnnotations
in class ClassCodeVisitorSupport
- Parameters:
node
- the node to be processed
addPhaseOperations
public static void addPhaseOperations(CompilationUnit compilationUnit)
addGlobalTransforms
public static void addGlobalTransforms(CompilationUnit compilationUnit)
Copyright © ${year} The Codehaus. All Rights Reserved.