Class StaticTypeCheckingVisitor
java.lang.Object
org.codehaus.groovy.ast.CodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeVisitorSupport
org.codehaus.groovy.transform.stc.StaticTypeCheckingVisitor
- All Implemented Interfaces:
GroovyClassVisitor
,GroovyCodeVisitor
,ErrorCollecting
- Direct Known Subclasses:
StaticCompilationVisitor
The main class code visitor responsible for static type checking. It will perform various inspections like checking
assignment types, type inference, ... Eventually, class nodes may be annotated with inferred type information.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
protected class
-
Field Summary
Modifier and TypeFieldDescriptionstatic final MethodNode
static final MethodNode
static final MethodNode
protected static final ClassNode
protected static final Expression
protected static final int
protected FieldNode
protected PropertyNode
protected static final ClassNode
protected static final ClassNode
protected static final ClassNode
protected static final List<MethodNode>
protected static final ClassNode
protected static final Object
protected DefaultTypeCheckingExtension
static final Statement
protected static final MethodNode
protected static final MethodNode
protected static final MethodNode
protected static final ClassNode
protected static final ClassNode
Deprecated.protected static final ClassNode
protected static final ClassNode
protected static final ClassNode
protected final ReturnAdder
protected final ReturnAdder.ReturnStatementListener
protected static final ClassNode
protected static final ClassNode[]
protected static final ClassNode
protected TypeCheckingContext
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
addAmbiguousErrorMessage
(List<MethodNode> foundMethods, String name, ClassNode[] args, Expression expr) protected void
addAssignmentError
(ClassNode leftType, ClassNode rightType, Expression expression) protected void
protected void
addClosureReturnType
(ClassNode returnType) void
protected void
addNoMatchingMethodError
(ClassNode receiver, String name, ClassNode[] args, ASTNode origin) protected void
addNoMatchingMethodError
(ClassNode receiver, String name, ClassNode[] args, Expression exp) protected void
addReceivers
(List<Receiver<String>> receivers, Collection<Receiver<String>> owners, boolean implicitThis) protected void
addStaticTypeError
(String msg, ASTNode node) void
addTypeCheckingExtension
(TypeCheckingExtension extension) protected void
protected void
addUnsupportedPreOrPostfixExpressionError
(Expression expression) protected void
protected boolean
areCategoryMethodCalls
(List<MethodNode> foundMethods, String name, ClassNode[] args) protected boolean
checkCast
(ClassNode targetType, Expression source) protected void
checkClosureParameters
(Expression callArguments, ClassNode receiver) Deprecated.protected void
checkForbiddenSpreadArgument
(ArgumentListExpression argumentList) protected void
checkGroovyConstructorMap
(Expression receiver, ClassNode receiverType, MapExpression mapExpression) protected void
checkGroovyStyleConstructor
(ClassNode node, ClassNode[] arguments) protected MethodNode
checkGroovyStyleConstructor
(ClassNode node, ClassNode[] arguments, ASTNode origin) Checks that a constructor style expression is valid regarding the number of arguments and the argument types.protected ClassNode
checkReturnType
(ReturnStatement statement) protected boolean
existsProperty
(PropertyExpression pexp, boolean checkForReadOnly) protected boolean
existsProperty
(PropertyExpression pexp, boolean readMode, 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)static String
extractPropertyNameFromMethodName
(String prefix, String methodName) Given a method name and a prefix, returns the name of the property that should be looked up, following the java beans rules.protected Object
extractTemporaryTypeInfoKey
(Expression expression) Computes the key to use forTypeCheckingContext.temporaryIfBranchTypeInformation
.protected static ClassNode[]
extractTypesFromParameters
(Parameter[] parameters) protected ClassNode
findCurrentInstanceOfClass
(Expression expression, ClassNode type) A helper method which determines which receiver class should be used in error messages when a field or attribute is not found.protected BinaryExpression
Deprecated.protected List<MethodNode>
findMethod
(ClassNode receiver, String name, ClassNode... args) protected MethodNode
findMethodOrFail
(Expression expr, ClassNode receiver, String name, ClassNode... args) protected List<MethodNode>
findMethodsWithGenerated
(ClassNode receiver, String name) Returns methods defined for the specified receiver and adds "non-existing" methods that will be generated afterwards by the compiler; for example if a method is using default values and the class node is not compiled yet.protected BinaryExpression
Deprecated.protected static String
formatArgumentList
(ClassNode[] nodes) protected ClassNode[]
getArgumentTypes
(ArgumentListExpression argumentList) protected org.codehaus.groovy.transform.stc.DelegationMetadata
getDelegationMetadata
(ClosureExpression expression) protected static ClassNode
protected ClassNode
getInferredReturnType
(ASTNode node) Returns the inferred return type of a closure or method, if stored on the AST node.protected ClassNode
getInferredReturnTypeFromWithClosureArgument
(Expression callArguments) In the case of a Object.with { ...protected ClassNode
protected ClassNode
getResultType
(ClassNode left, int op, ClassNode right, BinaryExpression expr) protected SourceUnit
getTemporaryTypesForExpression
(Expression expression) protected ClassNode
protected ClassNode[]
Returns array of type checking annotations.Returns the current type checking context.protected static boolean
hasRHSIncompleteGenericTypeInfo
(ClassNode inferredRightExpressionType) Deprecated.protected void
inferClosureParameterTypes
(ClassNode receiver, Expression arguments, ClosureExpression expression, Parameter target, MethodNode method) Performs type inference on closure argument types whenever code like this is found:foo.collect { it.toUpperCase() }
.protected ClassNode
inferComponentType
(ClassNode receiverType, ClassNode subscriptType) protected void
inferDiamondType
(ConstructorCallExpression cce, ClassNode lType) protected ClassNode
static ClassNode
inferLoopElementType
(ClassNode collectionType) Returns the inferred loop element type given a loop collection type.protected ClassNode
protected ClassNode
inferReturnTypeGenerics
(ClassNode receiver, MethodNode method, Expression arguments) If a method call returns a parameterized type, then perform additional inference on the return type, so that the type gets actual type arguments.protected ClassNode
inferReturnTypeGenerics
(ClassNode receiver, MethodNode method, Expression arguments, GenericsType[] explicitTypeHints) If a method call returns a parameterized type, then perform additional inference on the return type, so that the type gets actual type arguments.void
protected static boolean
isClassInnerClassOrEqualTo
(ClassNode toBeChecked, ClassNode start) protected static boolean
isNullConstant
(Expression expression) protected boolean
isSecondPassNeededForControlStructure
(Map<VariableExpression, ClassNode> startTypes, Map<VariableExpression, List<ClassNode>> oldTracker) boolean
isSkipMode
(AnnotatedNode node) protected boolean
Tests if a node is an inner class node, and if it is, then checks if the enclosing method is skipped.protected static boolean
isSuperExpression
(Expression expression) protected static boolean
isThisExpression
(Expression expression) makeOwnerList
(Expression objectExpression) Given an object expression (a message receiver expression), generate list of possible types.void
protected Map<VariableExpression,
ClassNode> popAssignmentTracking
(Map<VariableExpression, List<ClassNode>> oldTracker) protected static String
prettyPrintMethodList
(List<MethodNode> nodes) protected Map<VariableExpression,
List<ClassNode>> protected void
pushInstanceOfTypeInfo
(Expression objectOfInstanceOf, Expression typeExpression) Stores information about types when [objectOfInstanceof instanceof typeExpression] is visited.protected void
restoreVariableExpressionMetadata
(Map<VariableExpression, Map<StaticTypesMarker, Object>> typesBeforeVisit) protected void
saveVariableExpressionMetadata
(Set<VariableExpression> closureSharedExpressions, Map<VariableExpression, Map<StaticTypesMarker, Object>> typesBeforeVisit) void
setCompilationUnit
(CompilationUnit compilationUnit) void
setMethodsToBeVisited
(Set<MethodNode> methodsToBeVisited) protected boolean
shouldSkipClassNode
(ClassNode node) protected boolean
protected void
silentlyVisitMethodNode
(MethodNode directMethodCallCandidate) Visits a method call target, to infer the type.protected void
startMethodInference
(MethodNode node, ErrorCollector collector) protected ClassNode
storeInferredReturnType
(ASTNode node, ClassNode type) Stores the inferred return type of a closure or method.protected void
storeTargetMethod
(Expression call, MethodNode target) protected void
storeType
(Expression exp, ClassNode cn) protected void
typeCheckAssignment
(BinaryExpression assignmentExpression, Expression leftExpression, ClassNode leftExpressionType, Expression rightExpression, ClassNode rightExpressionType) protected void
typeCheckClosureCall
(Expression arguments, ClassNode[] argumentTypes, Parameter[] parameters) protected MethodNode
typeCheckMapConstructor
(ConstructorCallExpression call, ClassNode receiver, Expression arguments) protected boolean
typeCheckMethodsWithGenericsOrFail
(ClassNode receiver, ClassNode[] arguments, MethodNode candidateMethod, Expression location) void
visitArrayExpression
(ArrayExpression expression) void
visitAttributeExpression
(AttributeExpression expression) void
visitBinaryExpression
(BinaryExpression expression) void
void
Deprecated.void
visitCaseStatement
(CaseStatement statement) void
visitCastExpression
(CastExpression expression) void
visitClass
(ClassNode node) Visit a ClassNode.void
visitClassExpression
(ClassExpression expression) void
visitClosingBlock
(BlockStatement block) Deprecated.void
visitClosureExpression
(ClosureExpression expression) void
Visit a ConstructorNode.void
protected void
visitConstructorOrMethod
(MethodNode node, boolean isConstructor) void
visitExpressionStatement
(ExpressionStatement statement) void
visitField
(FieldNode node) Visit a FieldNode.void
visitForLoop
(ForStatement forLoop) void
visitIfElse
(IfStatement ifElse) protected void
Deprecated.void
visitMethod
(MethodNode node) Visit a MethodNode.protected void
visitMethodCallArguments
(ClassNode receiver, ArgumentListExpression arguments, boolean visitClosures, MethodNode selectedMethod) void
void
visitMethodPointerExpression
(MethodPointerExpression expression) void
visitNotExpression
(NotExpression expression) protected void
void
visitPostfixExpression
(PostfixExpression expression) void
visitPrefixExpression
(PrefixExpression expression) void
visitProperty
(PropertyNode node) Visit a PropertyNode.void
visitPropertyExpression
(PropertyExpression expression) void
visitRangeExpression
(RangeExpression expression) void
visitReturnStatement
(ReturnStatement statement) void
void
visitSwitch
(SwitchStatement statement) void
visitTernaryExpression
(TernaryExpression expression) void
visitTryCatchFinally
(TryCatchStatement statement) void
visitUnaryMinusExpression
(UnaryMinusExpression expression) void
visitUnaryPlusExpression
(UnaryPlusExpression expression) void
void
visitWhileLoop
(WhileStatement loop) protected static ClassNode
wrapTypeIfNecessary
(ClassNode type) Returns a wrapped type if, and only if, the provided class node is a primitive type.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, visitLambdaExpression, 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
-
ERROR_COLLECTOR
-
EMPTY_METHODNODE_LIST
-
TYPECHECKED_CLASSNODE
-
TYPECHECKING_ANNOTATIONS
-
TYPECHECKING_INFO_NODE
-
DGM_CLASSNODE
-
CURRENT_SIGNATURE_PROTOCOL_VERSION
protected static final int CURRENT_SIGNATURE_PROTOCOL_VERSION- See Also:
-
CURRENT_SIGNATURE_PROTOCOL
-
GET_DELEGATE
-
GET_OWNER
-
GET_THISOBJECT
-
DELEGATES_TO
-
DELEGATES_TO_TARGET
-
CLOSUREPARAMS_CLASSNODE
-
NAMED_PARAMS_CLASSNODE
-
NAMED_PARAM_CLASSNODE
-
LINKEDHASHMAP_CLASSNODE
Deprecated. -
ENUMERATION_TYPE
-
MAP_ENTRY_TYPE
-
ITERABLE_TYPE
-
CLOSURE_CALL_NO_ARG
-
CLOSURE_CALL_ONE_ARG
-
CLOSURE_CALL_VARGS
-
GENERATED_EMPTY_STATEMENT
-
returnListener
-
returnAdder
-
currentField
-
currentProperty
-
extension
-
typeCheckingContext
-
-
Constructor Details
-
StaticTypeCheckingVisitor
-
-
Method Details
-
setCompilationUnit
-
getSourceUnit
- Specified by:
getSourceUnit
in classClassCodeVisitorSupport
-
initialize
public void initialize() -
getTypeCheckingAnnotations
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
. -
getTypeCheckingContext
Returns the current type checking context. The context is used internally by the type checker during type checking to store various state data.- Returns:
- the type checking context
-
addTypeCheckingExtension
-
visitClass
Description copied from interface:GroovyClassVisitor
Visit a ClassNode.- Specified by:
visitClass
in interfaceGroovyClassVisitor
- Overrides:
visitClass
in classClassCodeVisitorSupport
-
shouldSkipClassNode
-
shouldSkipMethodNode
-
isSkipMode
-
isSkippedInnerClass
Tests if a node is an inner class node, and if it is, then checks if the enclosing method is skipped.- Returns:
- true if the inner class node should be skipped
-
visitClassExpression
- Specified by:
visitClassExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitClassExpression
in classCodeVisitorSupport
-
visitVariableExpression
- Specified by:
visitVariableExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitVariableExpression
in classCodeVisitorSupport
-
visitPropertyExpression
- Specified by:
visitPropertyExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitPropertyExpression
in classCodeVisitorSupport
-
visitAttributeExpression
- Specified by:
visitAttributeExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitAttributeExpression
in classCodeVisitorSupport
-
visitRangeExpression
- Specified by:
visitRangeExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitRangeExpression
in classCodeVisitorSupport
-
visitNotExpression
- Specified by:
visitNotExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitNotExpression
in classCodeVisitorSupport
-
visitBinaryExpression
- Specified by:
visitBinaryExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitBinaryExpression
in classCodeVisitorSupport
-
getOriginalDeclarationType
-
inferDiamondType
-
typeCheckAssignment
protected void typeCheckAssignment(BinaryExpression assignmentExpression, Expression leftExpression, ClassNode leftExpressionType, Expression rightExpression, ClassNode rightExpressionType) -
checkGroovyConstructorMap
protected void checkGroovyConstructorMap(Expression receiver, ClassNode receiverType, MapExpression mapExpression) -
hasRHSIncompleteGenericTypeInfo
@Deprecated protected static boolean hasRHSIncompleteGenericTypeInfo(ClassNode inferredRightExpressionType) Deprecated. -
checkGroovyStyleConstructor
Deprecated.Checks that a constructor style expression is valid regarding the number of arguments and the argument types.- Parameters:
node
- the class node for which we will try to find a matching constructorarguments
- the constructor arguments
-
checkGroovyStyleConstructor
protected MethodNode checkGroovyStyleConstructor(ClassNode node, ClassNode[] arguments, ASTNode origin) Checks that a constructor style expression is valid regarding the number of arguments and the argument types.- Parameters:
node
- the class node for which we will try to find a matching constructorarguments
- the constructor arguments
-
existsProperty
-
existsProperty
protected boolean existsProperty(PropertyExpression pexp, boolean readMode, 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)- Parameters:
pexp
- a property expressionreadMode
- 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
-
visitProperty
Description copied from interface:GroovyClassVisitor
Visit a PropertyNode.- Specified by:
visitProperty
in interfaceGroovyClassVisitor
- Overrides:
visitProperty
in classClassCodeVisitorSupport
-
visitField
Description copied from interface:GroovyClassVisitor
Visit a FieldNode.- Specified by:
visitField
in interfaceGroovyClassVisitor
- Overrides:
visitField
in classClassCodeVisitorSupport
-
visitForLoop
- Specified by:
visitForLoop
in interfaceGroovyCodeVisitor
- Overrides:
visitForLoop
in classClassCodeVisitorSupport
-
inferLoopElementType
Returns the inferred loop element type given a loop collection type. Used, for example, to infer the element type of afor (e in list)
loop.- Parameters:
collectionType
- the type of the collection- Returns:
- the inferred component type
- See Also:
-
isSecondPassNeededForControlStructure
protected boolean isSecondPassNeededForControlStructure(Map<VariableExpression, ClassNode> startTypes, Map<VariableExpression, List<ClassNode>> oldTracker) -
visitWhileLoop
- Specified by:
visitWhileLoop
in interfaceGroovyCodeVisitor
- Overrides:
visitWhileLoop
in classClassCodeVisitorSupport
-
visitBitwiseNegationExpression
- Specified by:
visitBitwiseNegationExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitBitwiseNegationExpression
in classCodeVisitorSupport
-
visitUnaryPlusExpression
- Specified by:
visitUnaryPlusExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitUnaryPlusExpression
in classCodeVisitorSupport
-
visitUnaryMinusExpression
- Specified by:
visitUnaryMinusExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitUnaryMinusExpression
in classCodeVisitorSupport
-
visitPostfixExpression
- Specified by:
visitPostfixExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitPostfixExpression
in classCodeVisitorSupport
-
visitPrefixExpression
- Specified by:
visitPrefixExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitPrefixExpression
in classCodeVisitorSupport
-
visitExpressionStatement
- Specified by:
visitExpressionStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitExpressionStatement
in classClassCodeVisitorSupport
-
visitReturnStatement
- Specified by:
visitReturnStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitReturnStatement
in classClassCodeVisitorSupport
-
checkReturnType
-
addClosureReturnType
-
visitConstructorCallExpression
- Specified by:
visitConstructorCallExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitConstructorCallExpression
in classCodeVisitorSupport
-
typeCheckMapConstructor
protected MethodNode typeCheckMapConstructor(ConstructorCallExpression call, ClassNode receiver, Expression arguments) -
getArgumentTypes
-
visitClosureExpression
- Specified by:
visitClosureExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitClosureExpression
in classCodeVisitorSupport
-
visitMethodPointerExpression
- Specified by:
visitMethodPointerExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitMethodPointerExpression
in classCodeVisitorSupport
-
getDelegationMetadata
protected org.codehaus.groovy.transform.stc.DelegationMetadata getDelegationMetadata(ClosureExpression expression) -
restoreVariableExpressionMetadata
protected void restoreVariableExpressionMetadata(Map<VariableExpression, Map<StaticTypesMarker, Object>> typesBeforeVisit) -
saveVariableExpressionMetadata
protected void saveVariableExpressionMetadata(Set<VariableExpression> closureSharedExpressions, Map<VariableExpression, Map<StaticTypesMarker, Object>> typesBeforeVisit) -
visitConstructor
Description copied from interface:GroovyClassVisitor
Visit a ConstructorNode.- Specified by:
visitConstructor
in interfaceGroovyClassVisitor
- Overrides:
visitConstructor
in classClassCodeVisitorSupport
-
visitMethod
Description copied from interface:GroovyClassVisitor
Visit a MethodNode.- Specified by:
visitMethod
in interfaceGroovyClassVisitor
- Overrides:
visitMethod
in classClassCodeVisitorSupport
-
startMethodInference
-
visitConstructorOrMethod
- Overrides:
visitConstructorOrMethod
in classClassCodeVisitorSupport
-
visitObjectInitializerStatements
- Overrides:
visitObjectInitializerStatements
in classClassCodeVisitorSupport
-
addTypeCheckingInfoAnnotation
-
visitStaticMethodCallExpression
- Specified by:
visitStaticMethodCallExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitStaticMethodCallExpression
in classCodeVisitorSupport
-
checkClosureParameters
Deprecated.this method is unused, replaced withDelegatesTo
inference. -
silentlyVisitMethodNode
Visits a method call target, to infer the type. Don't report errors right away, that will be done by a later visitMethod call. -
visitMethodCallArguments
protected void visitMethodCallArguments(ClassNode receiver, ArgumentListExpression arguments, boolean visitClosures, MethodNode selectedMethod) -
inferClosureParameterTypes
protected void inferClosureParameterTypes(ClassNode receiver, Expression arguments, ClosureExpression expression, Parameter target, MethodNode method) Performs type inference on closure argument types whenever code like this is found:foo.collect { it.toUpperCase() }
.In this case the type checker tries to find if the
collect
method has itsClosure
argument annotated withClosureParams
. If so, then additional type inference can be performed and the type ofit
may be inferred.- Parameters:
receiver
-arguments
-expression
- closure or lambda expression for which the argument types should be inferredtarget
- parameter which may provideClosureParams
annotation or SAM typemethod
- method that declarestarget
-
addReceivers
-
visitMethodCallExpression
- Specified by:
visitMethodCallExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitMethodCallExpression
in classCodeVisitorSupport
-
getInferredReturnTypeFromWithClosureArgument
In the case of a Object.with { ... } call, this method is supposed to retrieve the inferred closure return type.- Parameters:
callArguments
- the argument list from the Object#with(Closure) call, i.e. a single closure expression- Returns:
- the inferred closure return type or null
-
makeOwnerList
Given an object expression (a message receiver expression), generate list of possible types.- Parameters:
objectExpression
- the receiver expression- Returns:
- the list of types the receiver may be
-
checkForbiddenSpreadArgument
-
storeTargetMethod
-
typeCheckClosureCall
protected void typeCheckClosureCall(Expression arguments, ClassNode[] argumentTypes, Parameter[] parameters) -
visitIfElse
- Specified by:
visitIfElse
in interfaceGroovyCodeVisitor
- Overrides:
visitIfElse
in classClassCodeVisitorSupport
-
visitInstanceofNot
Deprecated. -
visitBlockStatement
Deprecated.- Specified by:
visitBlockStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitBlockStatement
in classClassCodeVisitorSupport
-
visitClosingBlock
Deprecated. -
findInstanceOfNotReturnExpression
Deprecated.Check IfStatement matched pattern : Object var1; if (!(var1 instanceOf Runnable)) { return } // Here var1 instance of RunnableReturn expression , which contains instanceOf (without not) Return null, if not found
-
findNotInstanceOfReturnExpression
Deprecated.Check IfStatement matched pattern : Object var1; if (var1 !instanceOf Runnable) { return } // Here var1 instance of RunnableReturn expression , which contains instanceOf (without not) Return null, if not found
-
visitSwitch
- Specified by:
visitSwitch
in interfaceGroovyCodeVisitor
- Overrides:
visitSwitch
in classClassCodeVisitorSupport
-
afterSwitchConditionExpressionVisited
- Overrides:
afterSwitchConditionExpressionVisited
in classCodeVisitorSupport
-
visitCaseStatement
- Specified by:
visitCaseStatement
in interfaceGroovyCodeVisitor
- Overrides:
visitCaseStatement
in classClassCodeVisitorSupport
-
pushAssignmentTracking
-
popAssignmentTracking
protected Map<VariableExpression,ClassNode> popAssignmentTracking(Map<VariableExpression, List<ClassNode>> oldTracker) -
visitArrayExpression
- Specified by:
visitArrayExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitArrayExpression
in classCodeVisitorSupport
-
visitCastExpression
- Specified by:
visitCastExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitCastExpression
in classCodeVisitorSupport
-
checkCast
-
visitTernaryExpression
- Specified by:
visitTernaryExpression
in interfaceGroovyCodeVisitor
- Overrides:
visitTernaryExpression
in classCodeVisitorSupport
-
visitTryCatchFinally
- Specified by:
visitTryCatchFinally
in interfaceGroovyCodeVisitor
- Overrides:
visitTryCatchFinally
in classClassCodeVisitorSupport
-
storeType
-
getResultType
-
getGroupOperationResultType
-
inferComponentType
-
findMethodOrFail
protected MethodNode findMethodOrFail(Expression expr, ClassNode receiver, String name, ClassNode... args) -
prettyPrintMethodList
-
areCategoryMethodCalls
protected boolean areCategoryMethodCalls(List<MethodNode> foundMethods, String name, ClassNode[] args) -
findMethodsWithGenerated
Returns methods defined for the specified receiver and adds "non-existing" methods that will be generated afterwards by the compiler; for example if a method is using default values and the class node is not compiled yet.- Parameters:
receiver
- the type to search for methodsname
- the name of the methods to return- Returns:
- the methods that are defined on the receiver completed with stubs for future methods
-
findMethod
-
extractPropertyNameFromMethodName
Given a method name and a prefix, returns the name of the property that should be looked up, following the java beans rules. For example, "getName" would return "name", while "getFullName" would return "fullName". If the prefix is not found, returns null.- Parameters:
prefix
- the method name prefix ("get", "is", "set", ...)methodName
- the method name- Returns:
- a property name if the prefix is found and the method matches the java beans rules, null otherwise
-
getType
-
storeInferredReturnType
Stores the inferred return type of a closure or method. We are using a separate key to store inferred return type because the inferred type of a closure isClosure
, which is different from the inferred type of the code of the closure.- Parameters:
node
- aClosureExpression
orMethodNode
type
- the inferred return type of the code- Returns:
- The old value of the inferred type.
-
getInferredReturnType
Returns the inferred return type of a closure or method, if stored on the AST node. This method doesn't perform any type inference by itself.- Parameters:
node
- aClosureExpression
orMethodNode
- Returns:
- The expected return type.
-
isNullConstant
-
isThisExpression
-
isSuperExpression
-
inferListExpressionType
-
inferMapExpressionType
-
inferReturnTypeGenerics
protected ClassNode inferReturnTypeGenerics(ClassNode receiver, MethodNode method, Expression arguments) If a method call returns a parameterized type, then perform additional inference on the return type, so that the type gets actual type arguments. For example, the methodArrays.asList(T...)
is parameterized withT
, which can be deduced type arguments or call arguments.- Parameters:
method
- the method nodearguments
- the method call argumentsreceiver
- the object expression type
-
inferReturnTypeGenerics
protected ClassNode inferReturnTypeGenerics(ClassNode receiver, MethodNode method, Expression arguments, GenericsType[] explicitTypeHints) If a method call returns a parameterized type, then perform additional inference on the return type, so that the type gets actual type arguments. For example, the methodArrays.asList(T...)
is parameterized withT
, which can be deduced type arguments or call arguments.- Parameters:
method
- the method nodearguments
- the method call argumentsreceiver
- the object expression typeexplicitTypeHints
- type arguments (optional), for exampleCollections.<String>emptyList()
-
typeCheckMethodsWithGenericsOrFail
protected boolean typeCheckMethodsWithGenericsOrFail(ClassNode receiver, ClassNode[] arguments, MethodNode candidateMethod, Expression location) -
formatArgumentList
-
addError
- Specified by:
addError
in interfaceErrorCollecting
- Overrides:
addError
in classClassCodeVisitorSupport
-
addStaticTypeError
-
addNoMatchingMethodError
protected void addNoMatchingMethodError(ClassNode receiver, String name, ClassNode[] args, Expression exp) -
addNoMatchingMethodError
-
addAmbiguousErrorMessage
protected void addAmbiguousErrorMessage(List<MethodNode> foundMethods, String name, ClassNode[] args, Expression expr) -
addCategoryMethodCallError
-
addAssignmentError
-
addUnsupportedPreOrPostfixExpressionError
-
setMethodsToBeVisited
-
performSecondPass
public void performSecondPass() -
extractTypesFromParameters
-
wrapTypeIfNecessary
Returns a wrapped type if, and only if, the provided class node is a primitive type. This method differs fromClassHelper.getWrapper(org.codehaus.groovy.ast.ClassNode)
as it will return the same instance if the provided type is not a generic type.- Returns:
- the wrapped type
-
isClassInnerClassOrEqualTo
-
pushInstanceOfTypeInfo
Stores information about types when [objectOfInstanceof instanceof typeExpression] is visited.- Parameters:
objectOfInstanceOf
- the expression to be checked against instanceoftypeExpression
- the expression which represents the target type
-
extractTemporaryTypeInfoKey
Computes the key to use forTypeCheckingContext.temporaryIfBranchTypeInformation
. -
findCurrentInstanceOfClass
A helper method which determines which receiver class should be used in error messages when a field or attribute is not found. The returned type class depends on whether we have temporary type information available (due to instanceof checks) and whether there is a single candidate in that case.- Parameters:
expression
- the expression for which an unknown field has been foundtype
- the type of the expression (used as fallback type)- Returns:
- if temporary information is available and there's only one type, returns the temporary type class otherwise falls back to the provided type class.
-
getTemporaryTypesForExpression
-
DelegatesTo
inference.