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`
  Class node for `ScriptBytecodeAdapter`.
  `protected static final Map<Integer,MethodNode>`
  `BYTECODE_BINARY_ADAPTERS`
  Comparison helpers on `ScriptBytecodeAdapter` keyed by Groovy token type.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `StaticCompilationTransformer(SourceUnit unit, StaticTypeCheckingVisitor visitor)`
  Creates a static compilation transformer for the supplied source unit and visitor.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `ClassNode`
  `getClassNode()`
  Returns the class currently enclosing the transformation context.
  `protected SourceUnit`
  `getSourceUnit()`
  Returns the source unit currently being transformed.
  `StaticTypesTypeChooser`
  `getTypeChooser()`
  Returns the type chooser used by this transformer.
  `Expression`
  `transform(Expression expr)`
  Dispatches expression transformation to the specialized helper for the expression type.
  `void`
  `visitClass(ClassNode node)`
  Visits a class and then recursively visits its inner classes.
  `void`
  `visitClassCodeContainer(Statement code)`
  Visits a statement container within the current class or method.
  `protected void`
  `visitConstructorOrMethod(MethodNode node, boolean isConstructor)`
  Visits a constructor or method unless it is explicitly marked to skip static compilation.
  `void`
  `visitField(FieldNode node)`
  Preserves constant field initializers that must remain inline for later compilation phases.

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

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

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

- ## Field Details

  - ### BYTECODE_ADAPTER_CLASS

    protected static final ClassNode BYTECODE_ADAPTER_CLASS
    Class node for `ScriptBytecodeAdapter`.

  - ### BYTECODE_BINARY_ADAPTERS

    protected static final Map<Integer,MethodNode> BYTECODE_BINARY_ADAPTERS
    Comparison helpers on `ScriptBytecodeAdapter` keyed by Groovy token type.

- ## Constructor Details

  - ### StaticCompilationTransformer

    public StaticCompilationTransformer(SourceUnit unit, StaticTypeCheckingVisitor visitor)
    Creates a static compilation transformer for the supplied source unit and visitor.
    Parameters:
      `unit` - the source unit being transformed
      `visitor` - the visitor providing type-checking metadata

- ## Method Details

  - ### getSourceUnit

    protected SourceUnit getSourceUnit()
    Returns the source unit currently being transformed.
    Specified by:
      `getSourceUnit` in class `ClassCodeVisitorSupport`
    Returns:
      the active source unit

  - ### getTypeChooser

    public StaticTypesTypeChooser getTypeChooser()
    Returns the type chooser used by this transformer.
    Returns:
      the static types type chooser

  - ### getClassNode

    public ClassNode getClassNode()
    Returns the class currently enclosing the transformation context.
    Returns:
      the current enclosing class node

  - ### visitClassCodeContainer

    public void visitClassCodeContainer(Statement code)
    Visits a statement container within the current class or method.
    Overrides:
      `visitClassCodeContainer` in class `ClassCodeVisitorSupport`
    Parameters:
      `code` - the code container to visit

  - ### transform

    public Expression transform(Expression expr)
    Dispatches expression transformation to the specialized helper for the expression type.
    Specified by:
      `transform` in interface `ExpressionTransformer`
    Overrides:
      `transform` in class `ClassCodeExpressionTransformer`
    Parameters:
      `expr` - the expression to transform
    Returns:
      the transformed expression

  - ### visitClass

    public void visitClass(ClassNode node)
    Visits a class and then recursively visits its inner classes.
    Specified by:
      `visitClass` in interface `GroovyClassVisitor`
    Overrides:
      `visitClass` in class `ClassCodeVisitorSupport`
    Parameters:
      `node` - the class node to process

  - ### visitField

    public void visitField(FieldNode node)
    Preserves constant field initializers that must remain inline for later compilation phases.
    Specified by:
      `visitField` in interface `GroovyClassVisitor`
    Overrides:
      `visitField` in class `ClassCodeExpressionTransformer`
    Parameters:
      `node` - the field to process

  - ### visitConstructorOrMethod

    protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor)
    Visits a constructor or method unless it is explicitly marked to skip static compilation.
    Overrides:
      `visitConstructorOrMethod` in class `ClassCodeExpressionTransformer`
    Parameters:
      `node` - the method or constructor to process
      `isConstructor` - whether `node` is a constructor