Package org.codehaus.groovy.transform.sc.transformers

# Class StaticCompilationTransformer

java.lang.Object
org.codehaus.groovy.ast.CodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeExpressionTransformer
org.codehaus.groovy.transform.sc.transformers.StaticCompilationTransformer

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

public class StaticCompilationTransformer extends ClassCodeExpressionTransformer
Some expressions use symbols as aliases to method calls (<<, +=, ...). In static compilation, if such a method call is found, we transform the original binary expression into a method call expression so that the call gets statically compiled.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected static final ClassNode`
  `BYTECODE_ADAPTER_CLASS`
  `protected static final Map<Integer,MethodNode>`
  `BYTECODE_BINARY_ADAPTERS`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `StaticCompilationTransformer(SourceUnit unit, StaticTypeCheckingVisitor visitor)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ClassNode`
  `getClassNode()`
  `protected SourceUnit`
  `getSourceUnit()`
  Provides access to the `SourceUnit` for error reporting during visitation.
  `StaticTypesTypeChooser`
  `getTypeChooser()`
  `Expression`
  `transform(Expression expr)`
  NOTE: This method does not visit Expressions within Closures, for performance and historical reasons.
  `void`
  `visitClass(ClassNode node)`
  Visits a `ClassNode`, processing its annotations, package, imports, contents, and object initializers.
  `void`
  `visitClassCodeContainer(Statement code)`
  Visits a code statement container, traversing it if present.
  `protected void`
  `visitConstructorOrMethod(MethodNode node, boolean isConstructor)`
  Visits a constructor or method node (implementation detail for both visit methods).
  `void`
  `visitField(FieldNode node)`
  Visits a `FieldNode`, processing its annotations and initial value expression if present.

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

  `setSourcePosition, visitAnnotation, visitAssertStatement, visitCaseStatement, visitClosureExpression, visitDoWhileLoop, visitExpressionStatement, visitForLoop, visitIfElse, visitProperty, visitReturnStatement, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitWhileLoop`

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

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

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

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

- ## Field Details

  - ### BYTECODE_ADAPTER_CLASS

    protected static final ClassNode BYTECODE_ADAPTER_CLASS

  - ### BYTECODE_BINARY_ADAPTERS

    protected static final Map<Integer,MethodNode> BYTECODE_BINARY_ADAPTERS

- ## Constructor Details

  - ### StaticCompilationTransformer

    public StaticCompilationTransformer(SourceUnit unit, StaticTypeCheckingVisitor visitor)

- ## Method Details

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

  - ### getTypeChooser

    public StaticTypesTypeChooser getTypeChooser()

  - ### getClassNode

    public ClassNode getClassNode()

  - ### visitClassCodeContainer

    public void visitClassCodeContainer(Statement code)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a code statement container, traversing it if present.
    Overrides:
      `visitClassCodeContainer` in class `ClassCodeVisitorSupport`
    Parameters:
      `code` - the statement to visit, may be null

  - ### transform

    public Expression transform(Expression expr)
    Description copied from class: `ClassCodeExpressionTransformer`
    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`
    Overrides:
      `transform` in class `ClassCodeExpressionTransformer`
    Parameters:
      `expr` - the expression to transform, may be null
    Returns:
      the transformed expression, may be the same instance, a new instance, or null

  - ### visitClass

    public void visitClass(ClassNode node)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a `ClassNode`, processing its annotations, package, imports, contents, and object initializers.
    Specified by:
      `visitClass` in interface `GroovyClassVisitor`
    Overrides:
      `visitClass` in class `ClassCodeVisitorSupport`
    Parameters:
      `node` - the class node 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 `ClassCodeExpressionTransformer`
    Parameters:
      `node` - the field 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 `ClassCodeExpressionTransformer`
    Parameters:
      `node` - the method or constructor node
      `isConstructor` - true if node is a constructor, false if it is a method