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
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
Modifier and TypeFieldDescriptionstatic final MethodNode
static final ClassNode
static final MethodNode
static final ClassNode
static final 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
-
Method Summary
Modifier and TypeMethodDescriptionprotected 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[]
Returns array of type checking annotations.static boolean
void
visitClass
(ClassNode node) Visit a ClassNode.void
Visit a ConstructorNode.void
void
visitForLoop
(ForStatement statement) void
visitLambdaExpression
(LambdaExpression expression) void
visitMethod
(MethodNode node) Visit a MethodNode.void
void
visitPropertyExpression
(PropertyExpression expression) Methods inherited from class org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor
addAmbiguousErrorMessage, addAssignmentError, addCategoryMethodCallError, addClosureReturnType, addError, addNoMatchingMethodError, addNoMatchingMethodError, addReceivers, addStaticTypeError, addTypeCheckingExtension, addTypeCheckingInfoAnnotation, addUnsupportedPreOrPostfixExpressionError, afterSwitchConditionExpressionVisited, areCategoryMethodCalls, checkCast, checkClosureParameters, checkForbiddenSpreadArgument, checkGroovyConstructorMap, checkGroovyStyleConstructor, checkGroovyStyleConstructor, checkReturnType, existsProperty, extractPropertyNameFromMethodName, extractTemporaryTypeInfoKey, extractTypesFromParameters, findCurrentInstanceOfClass, findInstanceOfNotReturnExpression, findMethod, findMethodsWithGenerated, findNotInstanceOfReturnExpression, formatArgumentList, getArgumentTypes, getDelegationMetadata, getGroupOperationResultType, getInferredReturnType, getInferredReturnTypeFromWithClosureArgument, getOriginalDeclarationType, getResultType, getSourceUnit, getTemporaryTypesForExpression, getType, getTypeCheckingContext, hasRHSIncompleteGenericTypeInfo, inferClosureParameterTypes, inferComponentType, inferDiamondType, inferListExpressionType, inferLoopElementType, inferMapExpressionType, 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, visitBlockStatement, visitCaseStatement, visitCastExpression, visitClassExpression, visitClosingBlock, visitClosureExpression, visitConstructorOrMethod, visitExpressionStatement, visitField, visitIfElse, visitInstanceofNot, 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, visitBreakStatement, visitCatchStatement, visitClassCodeContainer, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitImports, visitPackage, visitStatement, 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
-
COMPILESTATIC_CLASSNODE
-
ARRAYLIST_CLASSNODE
-
ARRAYLIST_ADD_METHOD
-
ARRAYLIST_CONSTRUCTOR
-
-
Constructor Details
-
StaticCompilationVisitor
-
-
Method Details
-
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 classStaticTypeCheckingVisitor
-
visitClass
Description copied from interface:GroovyClassVisitor
Visit a ClassNode.- Specified by:
visitClass
in interfaceGroovyClassVisitor
- Overrides:
visitClass
in classStaticTypeCheckingVisitor
-
visitConstructor
Description copied from interface:GroovyClassVisitor
Visit a ConstructorNode.- Specified by:
visitConstructor
in interfaceGroovyClassVisitor
- Overrides:
visitConstructor
in classStaticTypeCheckingVisitor
-
visitMethod
Description copied from interface:GroovyClassVisitor
Visit a MethodNode.- Specified by:
visitMethod
in interfaceGroovyClassVisitor
- Overrides:
visitMethod
in classStaticTypeCheckingVisitor
-
visitMethodCallExpression
- Specified by:
visitMethodCallExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitMethodCallExpression
in classStaticTypeCheckingVisitor
-
visitConstructorCallExpression
- Specified by:
visitConstructorCallExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitConstructorCallExpression
in classStaticTypeCheckingVisitor
-
visitForLoop
- Specified by:
visitForLoop
in interfaceGroovyCodeVisitor
- Overrides:
visitForLoop
in classStaticTypeCheckingVisitor
-
visitLambdaExpression
- Specified by:
visitLambdaExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitLambdaExpression
in classCodeVisitorSupport
-
visitPropertyExpression
- Specified by:
visitPropertyExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitPropertyExpression
in classStaticTypeCheckingVisitor
-
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 classStaticTypeCheckingVisitor
- Parameters:
pexp
- a property expressioncheckForReadOnly
- if true, look for property read, else for property setvisitor
- 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 classStaticTypeCheckingVisitor
-
isStaticallyCompiled
-