org.codehaus.groovy.transform.sc

## Class StaticCompilationVisitor

- java.lang.Object
- - org.codehaus.groovy.ast.CodeVisitorSupport
  - - org.codehaus.groovy.ast.ClassCodeVisitorSupport
    - - org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor
      - - org.codehaus.groovy.transform.sc.StaticCompilationVisitor

All Implemented Interfaces:
  GroovyClassVisitor, GroovyCodeVisitor

    public class StaticCompilationVisitor
    extends StaticTypeCheckingVisitor

This visitor is responsible for amending the AST with static compilation metadata or transform the AST so that a class or a method can be statically compiled. It may also throw errors specific to static compilation which are not considered as an error at the type check pass. For example, usage of spread operator is not allowed in statically compiled portions of code, while it may be statically checked. Static compilation relies on static type checking, which explains why this visitor extends the type checker visitor.

### Nested Class Summary

### Nested classes/interfaces inherited from class org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor

`StaticTypeCheckingVisitor.SignatureCodec, StaticTypeCheckingVisitor.SignatureCodecFactory`

### Field Summary

Fields
`static MethodNode` `ARRAYLIST_ADD_METHOD`
`static ClassNode` `ARRAYLIST_CLASSNODE`
`static MethodNode` `ARRAYLIST_CONSTRUCTOR`

### Fields inherited from class org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor

`CLOSURE_CALL_NO_ARG, CLOSURE_CALL_ONE_ARG, CLOSURE_CALL_VARGS`

### Constructor Summary

Constructors
Constructor and Description
`StaticCompilationVisitor(SourceUnit unit, ClassNode node, TypeCheckerPluginFactory pluginFactory)`

### Method Summary

Methods
`protected boolean` `existsProperty(PropertyExpression pexp, boolean checkForReadOnly, ClassCodeVisitorSupport visitor)` Checks whether a property exists on the receiver, or on any of the possible receiver classes (found in the temporary type information table)
`protected MethodNode` `findMethodOrFail(Expression expr, ClassNode receiver, java.lang.String name, ClassNode... args)`
`protected ClassNode[]` `getTypeCheckingAnnotations()` Returns the list of type checking annotations class nodes.
`static boolean` `isStaticallyCompiled(AnnotatedNode node)`
`void` `visitBinaryExpression(BinaryExpression expression)`
`void` `visitClass(ClassNode node)` Visit a ClassNode.
`void` `visitConstructorCallExpression(ConstructorCallExpression call)`
`void` `visitForLoop(ForStatement forLoop)`
`void` `visitMethod(MethodNode node)` Visit a MethodNode.
`void` `visitMethodCallExpression(MethodCallExpression call)`
`void` `visitSpreadExpression(SpreadExpression expression)`

### Methods inherited from class org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor

`addError, addStaticTypeError, addTypeCheckingInfoAnnotation, getSourceUnit, getType, hasSetter, inferComponentType, inferLoopElementType, isSkipMode, performSecondPass, setErrorCollector, setMethodsToBeVisited, shouldSkipClassNode, shouldSkipMethodNode, visitAttributeExpression, visitBitwiseNegationExpression, visitCastExpression, visitClassExpression, visitClosureExpression, visitConstructorOrMethod, visitField, visitIfElse, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitReturnStatement, visitStaticMethodCallExpression, visitTernaryExpression, visitTryCatchFinally, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression, visitWhileLoop`

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

`visitAnnotations, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCaseStatement, visitCatchStatement, visitClassCodeContainer, visitConstructor, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitExpressionStatement, visitImports, visitObjectInitializerStatements, visitPackage, visitProperty, visitStatement, visitSwitch, visitSynchronizedStatement, visitThrowStatement`

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

`visitArgumentlistExpression, visitArrayExpression, visitBooleanExpression, visitBytecodeExpression, visitClosureListExpression, visitConstantExpression, visitEmptyStatement, visitFieldExpression, visitGStringExpression, visitListExpression, visitListOfExpressions, visitMapEntryExpression, visitMapExpression, visitMethodPointerExpression, visitNotExpression, visitShortTernaryExpression, visitSpreadMapExpression, visitTupleExpression`

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

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

### Field Detail

#### ARRAYLIST_CLASSNODE

    public static final ClassNode ARRAYLIST_CLASSNODE

#### ARRAYLIST_CONSTRUCTOR

    public static final MethodNode ARRAYLIST_CONSTRUCTOR

#### ARRAYLIST_ADD_METHOD

    public static final MethodNode ARRAYLIST_ADD_METHOD

### Constructor Detail

#### StaticCompilationVisitor

    public StaticCompilationVisitor(SourceUnit unit,
                            ClassNode node,
                            TypeCheckerPluginFactory pluginFactory)

### Method Detail

#### getTypeCheckingAnnotations

    protected ClassNode[] getTypeCheckingAnnotations()

Description copied from class: `StaticTypeCheckingVisitor`
Returns the list of type checking annotations class nodes. Subclasses may override this method in order to provide additional classes which must be looked up when checking if a method or a class node should be skipped.

The default implementation returns `TypeChecked`.

Overrides:
  `getTypeCheckingAnnotations` in class `StaticTypeCheckingVisitor`
Returns:
  array of class nodes

#### isStaticallyCompiled

    public static boolean isStaticallyCompiled(AnnotatedNode node)

#### visitClass

    public void visitClass(ClassNode node)

Description copied from interface: `GroovyClassVisitor`
Visit a ClassNode.

Specified by:
  `visitClass` in interface `GroovyClassVisitor`
Overrides:
  `visitClass` in class `StaticTypeCheckingVisitor`

#### visitMethod

    public void visitMethod(MethodNode node)

Description copied from interface: `GroovyClassVisitor`
Visit a MethodNode.

Specified by:
  `visitMethod` in interface `GroovyClassVisitor`
Overrides:
  `visitMethod` in class `StaticTypeCheckingVisitor`

#### visitSpreadExpression

    public void visitSpreadExpression(SpreadExpression expression)

Specified by:
  `visitSpreadExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitSpreadExpression` in class `CodeVisitorSupport`

#### visitMethodCallExpression

    public void visitMethodCallExpression(MethodCallExpression call)

Specified by:
  `visitMethodCallExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitMethodCallExpression` in class `StaticTypeCheckingVisitor`

#### visitConstructorCallExpression

    public void visitConstructorCallExpression(ConstructorCallExpression call)

Specified by:
  `visitConstructorCallExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitConstructorCallExpression` in class `StaticTypeCheckingVisitor`

#### visitForLoop

    public void visitForLoop(ForStatement forLoop)

Specified by:
  `visitForLoop` in interface `GroovyCodeVisitor`
Overrides:
  `visitForLoop` in class `StaticTypeCheckingVisitor`

#### findMethodOrFail

    protected MethodNode findMethodOrFail(Expression expr,
                              ClassNode receiver,
                              java.lang.String name,
                              ClassNode... args)

Overrides:
  `findMethodOrFail` in class `StaticTypeCheckingVisitor`

#### existsProperty

    protected boolean existsProperty(PropertyExpression pexp,
                         boolean checkForReadOnly,
                         ClassCodeVisitorSupport visitor)

Description copied from class: `StaticTypeCheckingVisitor`
Checks whether a property exists on the receiver, or on any of the possible receiver classes (found in the temporary type information table)

Overrides:
  `existsProperty` in class `StaticTypeCheckingVisitor`
Parameters:
  `pexp` - a property expression
  `checkForReadOnly` - also lookup for read only properties
  `visitor` - if not null, when the property node is found, visit it with the provided visitor
Returns:
  true if the property is defined in any of the possible receiver classes

#### visitBinaryExpression

    public void visitBinaryExpression(BinaryExpression expression)

Specified by:
  `visitBinaryExpression` in interface `GroovyCodeVisitor`
Overrides:
  `visitBinaryExpression` in class `StaticTypeCheckingVisitor`