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 final MethodNode`
  `ARRAYLIST_ADD_METHOD`
  `static final ClassNode`
  `ARRAYLIST_CLASSNODE`
  `static final MethodNode`
  `ARRAYLIST_CONSTRUCTOR`
  `static final ClassNode`
  `COMPILESTATIC_CLASSNODE`
  `static final ClassNode`
  `TYPECHECKED_CLASSNODE`

  ### 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_PARAM_CLASSNODE, NAMED_PARAMS_CLASSNODE, returnAdder, returnListener, TYPECHECKING_ANNOTATIONS, TYPECHECKING_INFO_NODE, typeCheckingContext`

- ## Constructor Summary

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

- ## Method Summary

  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)`
  Visits a `ClassNode`, processing its annotations, package, imports, contents, and object initializers.
  `void`
  `visitConstructor(ConstructorNode node)`
  Visits a `ConstructorNode`, processing its annotations, parameter annotations, and code block.
  `void`
  `visitConstructorCallExpression(ConstructorCallExpression call)`
  Visits a `ConstructorCallExpression`, traversing its argument list.
  `void`
  `visitForLoop(ForStatement statement)`
  Visits a `ForStatement`, invoking statement hooks and processing loop variable annotations.
  `void`
  `visitLambdaExpression(LambdaExpression expression)`
  Visits a `LambdaExpression`, treating it as a closure expression.
  `void`
  `visitMethod(MethodNode node)`
  Visits a `MethodNode`, processing its annotations, parameter annotations, and code block.
  `void`
  `visitMethodCallExpression(MethodCallExpression call)`
  Visits a `MethodCallExpression`, traversing the object expression, method expression, and argument list.
  `void`
  `visitPropertyExpression(PropertyExpression expression)`
  Visits a `PropertyExpression`, traversing the object and property name expressions.

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

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

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

  `visitAnnotation, visitAnnotations, visitAnnotations, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCatchStatement, visitClassCodeContainer, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitImports, visitPackage, visitStatement, visitStatementAnnotations, visitSynchronizedStatement, visitThrowStatement`

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

  `visitArgumentlistExpression, visitBooleanExpression, visitBytecodeExpression, visitClosureListExpression, visitConstantExpression, visitEmptyStatement, visitFieldExpression, visitGStringExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodReferenceExpression, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitTupleExpression`

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

  - ### TYPECHECKED_CLASSNODE

    public static final ClassNode TYPECHECKED_CLASSNODE

  - ### COMPILESTATIC_CLASSNODE

    public static final ClassNode COMPILESTATIC_CLASSNODE

  - ### ARRAYLIST_CLASSNODE

    public static final ClassNode ARRAYLIST_CLASSNODE

  - ### ARRAYLIST_ADD_METHOD

    public static final MethodNode ARRAYLIST_ADD_METHOD

  - ### ARRAYLIST_CONSTRUCTOR

    public static final MethodNode ARRAYLIST_CONSTRUCTOR

- ## Constructor Details

  - ### StaticCompilationVisitor

    public StaticCompilationVisitor(SourceUnit unit, ClassNode node)

- ## Method Details

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

  - ### 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 `StaticTypeCheckingVisitor`
    Parameters:
      `node` - the class node to visit

  - ### visitConstructor

    public void visitConstructor(ConstructorNode node)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a `ConstructorNode`, processing its annotations, parameter annotations, and code block.
    Specified by:
      `visitConstructor` in interface `GroovyClassVisitor`
    Overrides:
      `visitConstructor` in class `StaticTypeCheckingVisitor`
    Parameters:
      `node` - the constructor node to visit

  - ### visitMethod

    public void visitMethod(MethodNode node)
    Description copied from class: `ClassCodeVisitorSupport`
    Visits a `MethodNode`, processing its annotations, parameter annotations, and code block.
    Specified by:
      `visitMethod` in interface `GroovyClassVisitor`
    Overrides:
      `visitMethod` in class `StaticTypeCheckingVisitor`
    Parameters:
      `node` - the method node to visit

  - ### visitMethodCallExpression

    public void visitMethodCallExpression(MethodCallExpression call)
    Description copied from class: `CodeVisitorSupport`
    Visits a `MethodCallExpression`, traversing the object expression, method expression, and argument list.
    Specified by:
      `visitMethodCallExpression` in interface `GroovyCodeVisitor`
    Overrides:
      `visitMethodCallExpression` in class `StaticTypeCheckingVisitor`
    Parameters:
      `call` - the method call expression

  - ### visitConstructorCallExpression

    public void visitConstructorCallExpression(ConstructorCallExpression call)
    Description copied from class: `CodeVisitorSupport`
    Visits a `ConstructorCallExpression`, traversing its argument list.
    Specified by:
      `visitConstructorCallExpression` in interface `GroovyCodeVisitor`
    Overrides:
      `visitConstructorCallExpression` in class `StaticTypeCheckingVisitor`
    Parameters:
      `call` - the constructor call expression

  - ### visitForLoop

    public void visitForLoop(ForStatement statement)
    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 `StaticTypeCheckingVisitor`
    Parameters:
      `statement` - the for statement to visit

  - ### visitLambdaExpression

    public void visitLambdaExpression(LambdaExpression expression)
    Description copied from class: `CodeVisitorSupport`
    Visits a `LambdaExpression`, treating it as a closure expression.
    Specified by:
      `visitLambdaExpression` in interface `GroovyCodeVisitor`
    Overrides:
      `visitLambdaExpression` in class `CodeVisitorSupport`
    Parameters:
      `expression` - the lambda expression

  - ### visitPropertyExpression

    public void visitPropertyExpression(PropertyExpression expression)
    Description copied from class: `CodeVisitorSupport`
    Visits a `PropertyExpression`, traversing the object and property name expressions.
    Specified by:
      `visitPropertyExpression` in interface `GroovyCodeVisitor`
    Overrides:
      `visitPropertyExpression` in class `StaticTypeCheckingVisitor`
    Parameters:
      `expression` - the property expression

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

  - ### findMethodOrFail

    protected MethodNode findMethodOrFail(Expression expr, ClassNode receiver, String name, ClassNode... args)
    Overrides:
      `findMethodOrFail` in class `StaticTypeCheckingVisitor`

  - ### isStaticallyCompiled

    public static boolean isStaticallyCompiled(AnnotatedNode node)