Package 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`, `ErrorCollecting`

public final 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 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).

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static void`
  `addGlobalTransforms(ASTTransformationsContext context)`
  `static void`
  `addGlobalTransformsAfterGrab(ASTTransformationsContext context)`
  `static void`
  `addNewPhaseOperation(CompilationUnit compilationUnit, SourceUnit sourceUnit, ClassNode classNode)`
  Enables transforms for class that was added during current phase.
  `static void`
  `addPhaseOperations(CompilationUnit compilationUnit)`
  `protected SourceUnit`
  `getSourceUnit()`
  Provides access to the `SourceUnit` for error reporting during visitation.
  `static void`
  `invokeTransformsForClass(CompilePhase phase, ASTTransformationsContext context, SourceUnit source, ClassNode classNode)`
  Invokes any AST transformations registered for `phase` on the given class using the standard `ASTTransformationVisitor` walk.
  `void`
  `visitAnnotations(AnnotatedNode node)`
  Adds the annotation to the internal target list if a match is found.
  `void`
  `visitClass(ClassNode classNode)`
  Main loop entry.
  `void`
  `visitProperty(PropertyNode node)`
  Visits a `PropertyNode`, processing its annotations, initial value expression, and getter/setter blocks if present.
  `protected void`
  `visitStatementAnnotations(Statement statement)`
  Adds annotated loop statements to the target list so that the registered AST transformation is invoked with `nodes[1]` being the loop statement.

  ### Methods inherited from class org.codehaus.groovy.ast.ClassCodeVisitorSupport

  `addError, visitAnnotation, visitAnnotations, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCaseStatement, visitCatchStatement, visitClassCodeContainer, visitClosureExpression, visitConstructor, visitConstructorOrMethod, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitReturnStatement, visitStatement, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitTryCatchFinally, visitWhileLoop, visitYieldStatement`

  ### Methods inherited from class org.codehaus.groovy.ast.CodeVisitorSupport

  `afterSwitchCaseStatementsVisited, afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBooleanExpression, visitBytecodeExpression, visitCastExpression, visitClassExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitEmptyStatement, visitFieldExpression, visitGStringExpression, visitLambdaExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitSwitchExpression, visitTernaryExpression, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.codehaus.groovy.ast.GroovyCodeVisitor

  `visit, visit, visitEmptyExpression, visitListOfExpressions`

- ## Method Details

  - ### invokeTransformsForClass

    public static void invokeTransformsForClass(CompilePhase phase, ASTTransformationsContext context, SourceUnit source, ClassNode classNode)
    Invokes any AST transformations registered for `phase` on the given class using the standard `ASTTransformationVisitor` walk. Intended for callers that need to drive transform invocation outside the standard phase wiring (for example, `JavaAwareCompilationUnit` runs CONVERSION-phase transforms before the stub generator emits stubs — see GEP-21).
    Since:
      6.0.0

  - ### getSourceUnit

    protected SourceUnit getSourceUnit()
    Description copied from class: `ClassCodeVisitorSupport`
    Provides access to the `SourceUnit` for error reporting during visitation. Implementations must override this method.
    Specified by:
      `getSourceUnit` in class `ClassCodeVisitorSupport`
    Returns:
      the source unit for this visitor

  - ### 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

  - ### visitStatementAnnotations

    protected void visitStatementAnnotations(Statement statement)
    Adds annotated loop statements to the target list so that the registered AST transformation is invoked with `nodes[1]` being the loop statement.
    Overrides:
      `visitStatementAnnotations` in class `ClassCodeVisitorSupport`
    Parameters:
      `statement` - the loop statement that may have statement-level annotations

  - ### visitProperty

    public void visitProperty(PropertyNode node)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a `PropertyNode`, processing its annotations, initial value expression, and getter/setter blocks if present.
    Specified by:
      `visitProperty` in interface `GroovyClassVisitor`
    Overrides:
      `visitProperty` in class `ClassCodeVisitorSupport`
    Parameters:
      `node` - the property node to visit

  - ### addPhaseOperations

    public static void addPhaseOperations(CompilationUnit compilationUnit)

  - ### addNewPhaseOperation

    public static void addNewPhaseOperation(CompilationUnit compilationUnit, SourceUnit sourceUnit, ClassNode classNode)
    Enables transforms for class that was added during current phase.

  - ### addGlobalTransformsAfterGrab

    public static void addGlobalTransformsAfterGrab(ASTTransformationsContext context)

  - ### addGlobalTransforms

    public static void addGlobalTransforms(ASTTransformationsContext context)