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

      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.SignatureCodecFactory, StaticTypeCheckingVisitor.VariableExpressionTypeMemoizer`

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `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, CLOSUREPARAMS_CLASSNODE, CURRENT_SIGNATURE_PROTOCOL, CURRENT_SIGNATURE_PROTOCOL_VERSION, currentField, currentProperty, DELEGATES_TO, DELEGATES_TO_TARGET, DGM_CLASSNODE, EMPTY_METHODNODE_LIST, ENUMERATION_TYPE, ERROR_COLLECTOR, extension, GENERATED_EMPTY_STATEMENT, GET_DELEGATE, GET_OWNER, GET_THISOBJECT, ITERABLE_TYPE, LINKEDHASHMAP_CLASSNODE, MAP_ENTRY_TYPE, NAMED_PARAMS_CLASSNODE, returnAdder, returnListener, TYPECHECKING_ANNOTATIONS, TYPECHECKING_INFO_NODE, typeCheckingContext`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `StaticCompilationVisitor​(SourceUnit unit, ClassNode node)` |

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `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, String name, ClassNode... args)` |
    `protected ClassNode[]` | `getTypeCheckingAnnotations()` | Returns array of type checking annotations.
    `static boolean` | `isStaticallyCompiled​(AnnotatedNode node)` |
    `void` | `visitClass​(ClassNode node)` | Visit a ClassNode.
    `void` | `visitConstructor​(ConstructorNode node)` | Visit a ConstructorNode.
    `void` | `visitConstructorCallExpression​(ConstructorCallExpression call)` |
    `void` | `visitForLoop​(ForStatement forLoop)` |
    `void` | `visitMethod​(MethodNode node)` | Visit a MethodNode.
    `void` | `visitMethodCallExpression​(MethodCallExpression call)` |
    `void` | `visitPropertyExpression​(PropertyExpression pexp)` |
    `void` | `visitSpreadExpression​(SpreadExpression expression)` |

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

      `addAmbiguousErrorMessage, addAssignmentError, addCategoryMethodCallError, addClosureReturnType, addError, addNoMatchingMethodError, addReceivers, addStaticTypeError, addTypeCheckingExtension, addTypeCheckingInfoAnnotation, addUnsupportedPreOrPostfixExpressionError, areCategoryMethodCalls, checkCast, checkClosureParameters, checkForbiddenSpreadArgument, checkGroovyConstructorMap, checkGroovyStyleConstructor, checkGroovyStyleConstructor, checkReturnType, collectAllInterfaceMethodsByName, existsProperty, extractPropertyNameFromMethodName, extractTemporaryTypeInfoKey, extractTypesFromParameters, findCurrentInstanceOfClass, findInstanceOfNotReturnExpression, findMethod, findMethodsWithGenerated, formatArgumentList, getArgumentTypes, getDelegationMetadata, getGroupOperationResultType, getInferredReturnType, getInferredReturnTypeFromWithClosureArgument, getOriginalDeclarationType, getResultType, getSourceUnit, getTemporaryTypesForExpression, getType, getTypeCheckingContext, hasRHSIncompleteGenericTypeInfo, hasSetter, inferClosureParameterTypes, inferComponentType, inferDiamondType, inferListExpressionType, inferLoopElementType, inferMapExpressionType, inferReturnTypeGenerics, inferReturnTypeGenerics, initialize, isClassInnerClassOrEqualTo, isClosureCall, isNullConstant, isSecondPassNeededForControlStructure, isSkipMode, isSkippedInnerClass, makeOwnerList, performSecondPass, popAssignmentTracking, prettyPrintMethodList, pushAssignmentTracking, pushInstanceOfTypeInfo, restoreVariableExpressionMetadata, saveVariableExpressionMetadata, setCompilationUnit, setMethodsToBeVisited, shouldSkipClassNode, shouldSkipMethodNode, silentlyVisitMethodNode, startMethodInference, storeInferredReturnType, storeInferredTypeForPropertyExpression, storeTargetMethod, storeType, typeCheckAssignment, typeCheckClosureCall, typeCheckMapConstructor, typeCheckMethodsWithGenericsOrFail, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBlockStatement, visitCaseStatement, visitCastExpression, visitClassExpression, visitClosingBlock, visitClosureExpression, visitConstructorOrMethod, visitField, visitIfElse, visitInstanceofNot, visitMethodCallArguments, visitMethodPointerExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitProperty, visitRangeExpression, visitReturnStatement, visitStaticMethodCallExpression, visitSwitch, visitTernaryExpression, visitTryCatchFinally, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression, visitWhileLoop, wrapTypeIfNecessary`

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

      `visitAnnotations, visitAssertStatement, visitBreakStatement, visitCatchStatement, visitClassCodeContainer, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitExpressionStatement, visitImports, visitObjectInitializerStatements, visitPackage, visitStatement, visitSynchronizedStatement, visitThrowStatement`

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

      `visitArgumentlistExpression, visitArrayExpression, visitBooleanExpression, visitBytecodeExpression, visitClosureListExpression, visitConstantExpression, visitEmptyStatement, visitFieldExpression, visitGStringExpression, visitListExpression, visitListOfExpressions, visitMapEntryExpression, visitMapExpression, 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)

  - ### Method Detail

    - #### getTypeCheckingAnnotations

          protected ClassNode[] getTypeCheckingAnnotations()

      Description copied from class: `StaticTypeCheckingVisitor`
      Returns array of type checking annotations. Subclasses may override this method in order to provide additional types 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`

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

    - #### visitConstructor

          public void visitConstructor​(ConstructorNode node)

      Description copied from interface: `GroovyClassVisitor`
      Visit a ConstructorNode.
      Specified by:
        `visitConstructor` in interface `GroovyClassVisitor`
      Overrides:
        `visitConstructor` 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,
                                                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` - if true, look for property read, else for property set
        `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

    - #### visitPropertyExpression

          public void visitPropertyExpression​(PropertyExpression pexp)

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