Package: org.codehaus.groovy.transform.sc

## [Java] Class StaticCompilationVisitor

- org.codehaus.groovy.transform.sc.StaticCompilationVisitor

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

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static MethodNode` | `ARRAYLIST_ADD_METHOD` | ArrayList.add method node.
    `static ClassNode` | `ARRAYLIST_CLASSNODE` | Class node for ArrayList.
    `static MethodNode` | `ARRAYLIST_CONSTRUCTOR` | No-arg ArrayList constructor node.
    `static ClassNode` | `COMPILESTATIC_CLASSNODE` | Class node for CompileStatic.
    `static ClassNode` | `TYPECHECKED_CLASSNODE` | Class node for TypeChecked.

  - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class StaticTypeCheckingVisitor` | `CHAR_SEQUENCE_TYPE, CLOSUREPARAMS_CLASSNODE, CLOSURE_CALL_NO_ARG, CLOSURE_CALL_ONE_ARG, CLOSURE_CALL_VARGS, CURRENT_SIGNATURE_PROTOCOL, CURRENT_SIGNATURE_PROTOCOL_VERSION, DELEGATES_TO, DELEGATES_TO_TARGET, DGM_CLASSNODE, EMPTY_METHODNODE_LIST, ENUMERATION_TYPE, ERROR_COLLECTOR, GENERATED_EMPTY_STATEMENT, GET_DELEGATE, GET_OWNER, GET_THISOBJECT, ITERABLE_TYPE, LINKEDHASHMAP_CLASSNODE, MAP_ENTRY_TYPE, NAMED_PARAMS_CLASSNODE, NAMED_PARAM_CLASSNODE, TYPECHECKED_CLASSNODE, TYPECHECKING_ANNOTATIONS, TYPECHECKING_INFO_NODE, currentField, currentProperty, extension, returnAdder, returnListener, typeCheckingContext`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `StaticCompilationVisitor(SourceUnit unit, ClassNode node)` Creates a static compilation visitor for the supplied source unit and class.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected boolean` | `existsProperty(PropertyExpression pexp, boolean checkForReadOnly, ClassCodeVisitorSupport visitor)` Resolves a property reference and records the owning type for later static compilation.
    `` | `protected MethodNode` | `findMethodOrFail(Expression expr, ClassNode receiver, String name, ClassNode args)` Stores binary-expression target metadata alongside the resolved method.
    `` | `protected ClassNode[]` | `getTypeCheckingAnnotations()` Returns the annotations that trigger static type checking in this visitor.
    `` | `public static boolean` | `isStaticallyCompiled(AnnotatedNode node)` Indicates whether the supplied node is marked for static compilation.
    `` | `public void` | `visitClass(ClassNode node)` Visits a class and attaches the metadata required by the static compiler.
    `` | `public void` | `visitConstructor(ConstructorNode node)` Visits a constructor and records static-compilation metadata for it.
    `` | `public void` | `visitConstructorCallExpression(ConstructorCallExpression call)` Resolves and stores the direct target for a statically compiled constructor call.
    `` | `public void` | `visitForLoop(ForStatement statement)` Finalizes inferred loop-variable types for statically compiled `for` loops.
    `` | `public void` | `visitLambdaExpression(LambdaExpression expression)` Removes post-type-checking lambda rewrites that are incompatible with static compilation.
    `` | `public void` | `visitMethod(MethodNode node)` Visits a method and records static-compilation metadata for it.
    `` | `public void` | `visitMethodCallExpression(MethodCallExpression call)` Resolves and stores the direct target for a statically compiled method call.
    `` | `public void` | `visitPropertyExpression(PropertyExpression expression)` Marks receivers for property expressions that still require dynamic resolution.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class StaticTypeCheckingVisitor` | `addAmbiguousErrorMessage, addAssignmentError, addCategoryMethodCallError, addClosureReturnType, addError, addNoMatchingMethodError, addNoMatchingMethodError, addReceivers, addStaticTypeError, addTypeCheckingExtension, addTypeCheckingInfoAnnotation, addUnsupportedPreOrPostfixExpressionError, afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, areCategoryMethodCalls, checkCast, checkClosureParameters, checkForbiddenSpreadArgument, checkGroovyConstructorMap, checkGroovyStyleConstructor, checkReturnType, existsProperty, existsProperty, extractPropertyNameFromMethodName, extractTemporaryTypeInfoKey, extractTypesFromParameters, findCurrentInstanceOfClass, findMethod, findMethodOrFail, findMethodsWithGenerated, formatArgumentList, getArgumentTypes, getDelegationMetadata, getGroupOperationResultType, getInferredReturnType, getInferredReturnTypeFromWithClosureArgument, getOriginalDeclarationType, getResultType, getSourceUnit, getTemporaryTypesForExpression, getType, getTypeCheckingAnnotations, 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, visitClass, visitClassExpression, visitClosureExpression, visitConstructor, visitConstructorCallExpression, visitConstructorOrMethod, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitMethod, visitMethodCallArguments, visitMethodCallExpression, visitMethodPointerExpression, visitNotExpression, visitObjectInitializerStatements, visitPostfixExpression, visitPrefixExpression, visitProperty, visitPropertyExpression, visitRangeExpression, visitReturnStatement, visitStaticMethodCallExpression, visitSwitch, visitTernaryExpression, visitTryCatchFinally, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression, visitWhileLoop, wrapTypeIfNecessary`
    `class ClassCodeVisitorSupport` | `addError, getSourceUnit, visitAnnotation, visitAnnotations, visitAnnotations, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCaseStatement, visitCatchStatement, visitClass, visitClassCodeContainer, visitClosureExpression, visitConstructor, visitConstructorOrMethod, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitProperty, visitReturnStatement, visitStatement, visitStatementAnnotations, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitTryCatchFinally, visitWhileLoop`
    `class CodeVisitorSupport` | `afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAssertStatement, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBlockStatement, visitBooleanExpression, visitBreakStatement, visitBytecodeExpression, visitCaseStatement, visitCastExpression, visitCatchStatement, visitClassExpression, visitClosureExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitEmptyStatement, visitExpressionStatement, visitFieldExpression, visitForLoop, visitGStringExpression, visitIfElse, visitLambdaExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitReturnStatement, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitSwitch, visitSynchronizedStatement, visitTernaryExpression, visitThrowStatement, visitTryCatchFinally, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression, visitWhileLoop`

- - ### Field Detail

    - #### public static final MethodNode ARRAYLIST_ADD_METHOD

      ArrayList.add method node.

    - #### public static final ClassNode ARRAYLIST_CLASSNODE

      Class node for ArrayList.

    - #### public static final MethodNode ARRAYLIST_CONSTRUCTOR

      No-arg ArrayList constructor node.

    - #### public static final ClassNode COMPILESTATIC_CLASSNODE

      Class node for CompileStatic.

    - #### public static final ClassNode TYPECHECKED_CLASSNODE

      Class node for TypeChecked.

  - ### Constructor Detail

    - #### public StaticCompilationVisitor(SourceUnit unit, ClassNode node)

      Creates a static compilation visitor for the supplied source unit and class.

      Parameters:
        `unit` - the source unit being processed
        `node` - the class node to visit

  - ### Method Detail

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

      Resolves a property reference and records the owning type for later static compilation.

      Parameters:
        `pexp` - the property expression being resolved
        `checkForReadOnly` - whether read-only properties should be considered
        `visitor` - an optional callback for the matched member
      Returns:
        `true` if a matching property-like member exists

    - #### protected MethodNode findMethodOrFail(Expression expr, ClassNode receiver, String name, ClassNode args)

      Stores binary-expression target metadata alongside the resolved method.

      Parameters:
        `expr` - the expression being resolved
        `receiver` - the candidate receiver type
        `name` - the method name
        `args` - the argument types
      Returns:
        the resolved method, or `null` if resolution fails

    - #### protected ClassNode[] getTypeCheckingAnnotations()

      Returns the annotations that trigger static type checking in this visitor.

      Returns:
        the supported type-checking annotations

    - #### public static boolean isStaticallyCompiled(AnnotatedNode node)

      Indicates whether the supplied node is marked for static compilation.

      Parameters:
        `node` - the class or method node to inspect
      Returns:
        `true` if the node is statically compiled

    - #### public void visitClass(ClassNode node)

      Visits a class and attaches the metadata required by the static compiler.

      Parameters:
        `node` - the class node to process

    - #### public void visitConstructor(ConstructorNode node)

      Visits a constructor and records static-compilation metadata for it.

      Parameters:
        `node` - the constructor to process

    - #### public void visitConstructorCallExpression(ConstructorCallExpression call)

      Resolves and stores the direct target for a statically compiled constructor call.

      Parameters:
        `call` - the constructor call expression to inspect

    - #### public void visitForLoop(ForStatement statement)

      Finalizes inferred loop-variable types for statically compiled `for` loops.

      Parameters:
        `statement` - the loop statement to process

    - #### public void visitLambdaExpression(LambdaExpression expression)

      Removes post-type-checking lambda rewrites that are incompatible with static compilation.

      Parameters:
        `expression` - the lambda expression to process

    - #### public void visitMethod(MethodNode node)

      Visits a method and records static-compilation metadata for it.

      Parameters:
        `node` - the method to process

    - #### public void visitMethodCallExpression(MethodCallExpression call)

      Resolves and stores the direct target for a statically compiled method call.

      Parameters:
        `call` - the method call expression to inspect

    - #### public void visitPropertyExpression(PropertyExpression expression)

      Marks receivers for property expressions that still require dynamic resolution.

      Parameters:
        `expression` - the property expression to process