Package org.codehaus.groovy.ast

# Class ClassCodeExpressionTransformer

java.lang.Object
org.codehaus.groovy.ast.CodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeExpressionTransformer

All Implemented Interfaces:
  `ExpressionTransformer`, `GroovyClassVisitor`, `GroovyCodeVisitor`, `ErrorCollecting`

Direct Known Subclasses:
  `FieldASTTransformation`, `NewifyASTTransformation`, `OperatorRenameASTTransformation`, `OptimizerVisitor`, `ResolveVisitor`, `SafeRegexASTTransformation`, `StaticCompilationTransformer`, `StaticImportVisitor`

public abstract class ClassCodeExpressionTransformer extends ClassCodeVisitorSupport implements ExpressionTransformer
Transforms expressions in a whole class. Transformed expressions are usually not visited.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ClassCodeExpressionTransformer()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected static void`
  `setSourcePosition(Expression target, Expression source)`
  Transfers the source position to target including its property expression if it has one.
  `Expression`
  `transform(Expression expr)`
  NOTE: This method does not visit Expressions within Closures, for performance and historical reasons.
  `protected void`
  `visitAnnotation(AnnotationNode node)`
  Visits an individual `AnnotationNode`, traversing all member expression values.
  `void`
  `visitAssertStatement(AssertStatement stmt)`
  Visits an `AssertStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitCaseStatement(CaseStatement stmt)`
  Visits a `CaseStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitClosureExpression(ClosureExpression expr)`
  Visits a `ClosureExpression` with annotation processing, traversing parameter annotations before delegating to parent traversal.
  `protected void`
  `visitConstructorOrMethod(MethodNode node, boolean isConstructor)`
  Visits a constructor or method node (implementation detail for both visit methods).
  `void`
  `visitDoWhileLoop(DoWhileStatement stmt)`
  Visits a `DoWhileStatement`, invoking statement hooks before parent traversal.
  `void`
  `visitExpressionStatement(ExpressionStatement stmt)`
  Visits an `ExpressionStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitField(FieldNode node)`
  Visits a `FieldNode`, processing its annotations and initial value expression if present.
  `void`
  `visitForLoop(ForStatement stmt)`
  Visits a `ForStatement`, invoking statement hooks and processing loop variable annotations.
  `void`
  `visitIfElse(IfStatement stmt)`
  Visits an `IfStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitProperty(PropertyNode node)`
  Visits a `PropertyNode`, processing its annotations, initial value expression, and getter/setter blocks if present.
  `void`
  `visitReturnStatement(ReturnStatement stmt)`
  Visits a `ReturnStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitSwitch(SwitchStatement stmt)`
  Visits a `SwitchStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitSwitchExpression(SwitchExpression expression)`
  Visits a `SwitchExpression`, traversing the selector, case arms, and default arm (GROOVY-12255).
  `void`
  `visitSynchronizedStatement(SynchronizedStatement stmt)`
  Visits a `SynchronizedStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitThrowStatement(ThrowStatement stmt)`
  Visits a `ThrowStatement`, invoking the statement hook before parent traversal.
  `void`
  `visitWhileLoop(WhileStatement stmt)`
  Visits a `WhileStatement`, invoking statement hooks before parent traversal.
  `void`
  `visitYieldStatement(YieldStatement stmt)`
  Visits a `YieldStatement`, invoking the statement hook before parent traversal (GROOVY-12255).

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

  `addError, getSourceUnit, visitAnnotations, visitAnnotations, visitBlockStatement, visitBreakStatement, visitCatchStatement, visitClass, visitClassCodeContainer, visitConstructor, visitContinueStatement, visitDeclarationExpression, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitStatement, visitStatementAnnotations, visitTryCatchFinally`

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

- ## Constructor Details

  - ### ClassCodeExpressionTransformer

    public ClassCodeExpressionTransformer()

- ## Method Details

  - ### transform

    public Expression transform(Expression expr)
    NOTE: This method does not visit Expressions within Closures, for performance and historical reasons. If you want those Expressions to be visited, you can do this:

         public class YourTransformer extends ClassCodeExpressionTransformer {
           ...

           @Override
           public Expression transform(final Expression expr) {
             if (expr instanceof ClosureExpression) {
               expr.visit(this);

               return expr;
             }
             // ...
           }
         }

    Specified by:
      `transform` in interface `ExpressionTransformer`
    Parameters:
      `expr` - the expression to transform, may be null
    Returns:
      the transformed expression, may be the same instance, a new instance, or null

  - ### visitAnnotation

    protected void visitAnnotation(AnnotationNode node)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits an individual `AnnotationNode`, traversing all member expression values. Subclasses may override to perform custom annotation processing.
    Overrides:
      `visitAnnotation` in class `ClassCodeVisitorSupport`
    Parameters:
      `node` - the annotation node to visit

  - ### visitConstructorOrMethod

    protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a constructor or method node (implementation detail for both visit methods). Processes the node's annotations, all parameter annotations, and code block.
    Overrides:
      `visitConstructorOrMethod` in class `ClassCodeVisitorSupport`
    Parameters:
      `node` - the method or constructor node
      `isConstructor` - true if node is a constructor, false if it is a method

  - ### visitClosureExpression

    public void visitClosureExpression(ClosureExpression expr)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a `ClosureExpression` with annotation processing, traversing parameter annotations before delegating to parent traversal.
    Specified by:
      `visitClosureExpression` in interface `GroovyCodeVisitor`
    Overrides:
      `visitClosureExpression` in class `ClassCodeVisitorSupport`
    Parameters:
      `expr` - the closure expression to visit

  - ### visitField

    public void visitField(FieldNode node)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a `FieldNode`, processing its annotations and initial value expression if present.
    Specified by:
      `visitField` in interface `GroovyClassVisitor`
    Overrides:
      `visitField` in class `ClassCodeVisitorSupport`
    Parameters:
      `node` - the field node to visit

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

  - ### visitAssertStatement

    public void visitAssertStatement(AssertStatement stmt)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits an `AssertStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitAssertStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitAssertStatement` in class `ClassCodeVisitorSupport`
    Parameters:
      `stmt` - the assert statement to visit

  - ### visitCaseStatement

    public void visitCaseStatement(CaseStatement stmt)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a `CaseStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitCaseStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitCaseStatement` in class `ClassCodeVisitorSupport`
    Parameters:
      `stmt` - the case statement to visit

  - ### visitDoWhileLoop

    public void visitDoWhileLoop(DoWhileStatement stmt)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a `DoWhileStatement`, invoking statement hooks before parent traversal.
    Specified by:
      `visitDoWhileLoop` in interface `GroovyCodeVisitor`
    Overrides:
      `visitDoWhileLoop` in class `ClassCodeVisitorSupport`
    Parameters:
      `stmt` - the do-while statement to visit

  - ### visitExpressionStatement

    public void visitExpressionStatement(ExpressionStatement stmt)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits an `ExpressionStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitExpressionStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitExpressionStatement` in class `ClassCodeVisitorSupport`
    Parameters:
      `stmt` - the expression statement to visit

  - ### visitForLoop

    public void visitForLoop(ForStatement stmt)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a `ForStatement`, invoking statement hooks and processing loop variable annotations.
    Specified by:
      `visitForLoop` in interface `GroovyCodeVisitor`
    Overrides:
      `visitForLoop` in class `ClassCodeVisitorSupport`
    Parameters:
      `stmt` - the for statement to visit

  - ### visitIfElse

    public void visitIfElse(IfStatement stmt)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits an `IfStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitIfElse` in interface `GroovyCodeVisitor`
    Overrides:
      `visitIfElse` in class `ClassCodeVisitorSupport`
    Parameters:
      `stmt` - the if statement to visit

  - ### visitReturnStatement

    public void visitReturnStatement(ReturnStatement stmt)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a `ReturnStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitReturnStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitReturnStatement` in class `ClassCodeVisitorSupport`
    Parameters:
      `stmt` - the return statement to visit

  - ### visitSwitch

    public void visitSwitch(SwitchStatement stmt)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a `SwitchStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitSwitch` in interface `GroovyCodeVisitor`
    Overrides:
      `visitSwitch` in class `ClassCodeVisitorSupport`
    Parameters:
      `stmt` - the switch statement to visit

  - ### visitSynchronizedStatement

    public void visitSynchronizedStatement(SynchronizedStatement stmt)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a `SynchronizedStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitSynchronizedStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitSynchronizedStatement` in class `ClassCodeVisitorSupport`
    Parameters:
      `stmt` - the synchronized statement to visit

  - ### visitThrowStatement

    public void visitThrowStatement(ThrowStatement stmt)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a `ThrowStatement`, invoking the statement hook before parent traversal.
    Specified by:
      `visitThrowStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitThrowStatement` in class `ClassCodeVisitorSupport`
    Parameters:
      `stmt` - the throw statement to visit

  - ### visitYieldStatement

    public void visitYieldStatement(YieldStatement stmt)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a `YieldStatement`, invoking the statement hook before parent traversal (GROOVY-12255).
    Specified by:
      `visitYieldStatement` in interface `GroovyCodeVisitor`
    Overrides:
      `visitYieldStatement` in class `ClassCodeVisitorSupport`
    Parameters:
      `stmt` - the yield statement to visit

  - ### visitSwitchExpression

    public void visitSwitchExpression(SwitchExpression expression)
    Description copied from class: `CodeVisitorSupport`
    Visits a `SwitchExpression`, traversing the selector, case arms, and default arm (GROOVY-12255).
    Specified by:
      `visitSwitchExpression` in interface `GroovyCodeVisitor`
    Overrides:
      `visitSwitchExpression` in class `CodeVisitorSupport`
    Parameters:
      `expression` - the switch expression

  - ### visitWhileLoop

    public void visitWhileLoop(WhileStatement stmt)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a `WhileStatement`, invoking statement hooks before parent traversal.
    Specified by:
      `visitWhileLoop` in interface `GroovyCodeVisitor`
    Overrides:
      `visitWhileLoop` in class `ClassCodeVisitorSupport`
    Parameters:
      `stmt` - the while statement to visit

  - ### setSourcePosition

    protected static void setSourcePosition(Expression target, Expression source)
    Transfers the source position to target including its property expression if it has one.
    Parameters:
      `target` - resulting node
      `source` - original node