public class StaticTypeCheckingVisitor
extends ClassCodeVisitorSupport
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.
| Modifiers | Name | Description |
|---|---|---|
static class |
StaticTypeCheckingVisitor.SignatureCodecFactory |
Creates signature codecs for serialized type checking metadata. |
protected class |
StaticTypeCheckingVisitor.VariableExpressionTypeMemoizer |
Memoizes inferred variable types so they can be restored after temporary rewrites. |
| Modifiers | Name | Description |
|---|---|---|
protected static ClassNode |
CHAR_SEQUENCE_TYPE |
Cached CharSequence type (GROOVY-9848: membership operator dispatch). |
protected static ClassNode |
CLOSUREPARAMS_CLASSNODE |
Cached ClosureParams annotation type. |
static MethodNode |
CLOSURE_CALL_NO_ARG |
Cached zero-argument Closure#call() method. |
static MethodNode |
CLOSURE_CALL_ONE_ARG |
Cached single-argument Closure#call(Object) method. |
static MethodNode |
CLOSURE_CALL_VARGS |
Cached varargs Closure#call(Object[]) method. |
protected static Expression |
CURRENT_SIGNATURE_PROTOCOL |
Constant expression for the current signature protocol version. |
protected static int |
CURRENT_SIGNATURE_PROTOCOL_VERSION |
Current encoding protocol for stored type-checking signatures. |
protected static ClassNode |
DELEGATES_TO |
Cached DelegatesTo annotation type. |
protected static ClassNode |
DELEGATES_TO_TARGET |
Cached DelegatesTo.Target annotation type. |
protected static ClassNode |
DGM_CLASSNODE |
Cached DefaultGroovyMethods type. |
protected static List<MethodNode> |
EMPTY_METHODNODE_LIST |
Shared empty method list. |
protected static ClassNode |
ENUMERATION_TYPE |
Cached Enumeration type. |
protected static Object |
ERROR_COLLECTOR |
Metadata key used to store per-method error collectors. |
static Statement |
GENERATED_EMPTY_STATEMENT |
Empty statement reused for synthetic AST nodes. |
protected static MethodNode |
GET_DELEGATE |
Cached Closure#getDelegate() method. |
protected static MethodNode |
GET_OWNER |
Cached Closure#getOwner() method. |
protected static MethodNode |
GET_THISOBJECT |
Cached Closure#getThisObject() method. |
protected static ClassNode |
ITERABLE_TYPE |
Cached Iterable type. |
protected static ClassNode |
LINKEDHASHMAP_CLASSNODE |
|
protected static ClassNode |
MAP_ENTRY_TYPE |
Cached Entry type. |
protected static ClassNode |
NAMED_PARAMS_CLASSNODE |
Cached NamedParams annotation type. |
protected static ClassNode |
NAMED_PARAM_CLASSNODE |
Cached NamedParam annotation type. |
protected static ClassNode |
TYPECHECKED_CLASSNODE |
Cached TypeChecked annotation type. |
protected static ClassNode[] |
TYPECHECKING_ANNOTATIONS |
Type-checking annotations recognized by this visitor. |
protected static ClassNode |
TYPECHECKING_INFO_NODE |
Cached TypeChecked.TypeCheckingInfo annotation type. |
protected FieldNode |
currentField |
Field currently being visited. |
protected PropertyNode |
currentProperty |
Property currently being visited. |
protected DefaultTypeCheckingExtension |
extension |
Composite extension chain consulted during type checking. |
protected ReturnAdder |
returnAdder |
Return adder used to normalize implicit and explicit returns. |
protected ReturnStatementListener |
returnListener |
|
protected TypeCheckingContext |
typeCheckingContext |
Mutable state for the current type-checking run. |
| Constructor and description |
|---|
StaticTypeCheckingVisitor(SourceUnit source, ClassNode classNode)Creates a static type-checking visitor for the supplied source and class. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected void |
addAmbiguousErrorMessage(List<MethodNode> foundMethods, String name, ClassNode[] args, Expression expr)Reports that method resolution remained ambiguous after filtering. |
|
protected void |
addAssignmentError(ClassNode leftType, ClassNode rightType, Expression expression)Reports an incompatible assignment between the supplied types. |
|
protected void |
addCategoryMethodCallError(Expression call)Reports that categories cannot be used under static type checking. |
|
protected void |
addClosureReturnType(ClassNode returnType)Records a non-void return type for the current enclosing closure. |
|
public void |
addError(String msg, ASTNode node)* Adds an error message associated with an AST node to the source unit. * Errors are accumulated and reported after visitation completes. * *
|
|
protected void |
addNoMatchingMethodError(ClassNode receiver, String name, ClassNode[] args, Expression exp)Reports that no matching method or constructor could be found for the call. |
|
protected void |
addNoMatchingMethodError(ClassNode receiver, String name, ClassNode[] args, ASTNode origin)Reports that no matching method or constructor could be found for the call. |
|
protected void |
addReceivers(List<Receiver<String>> receivers, Collection<Receiver<String>> owners, boolean implicitThis)Adds candidate receivers derived from owner chains. |
|
protected void |
addStaticTypeError(String msg, ASTNode node)Reports a static type checking error for the supplied node. |
|
public void |
addTypeCheckingExtension(TypeCheckingExtension extension)Adds a type-checking extension to the active extension chain. |
|
protected void |
addTypeCheckingInfoAnnotation(MethodNode node)Adds TypeChecked.TypeCheckingInfo metadata for an inferred method return type. |
|
protected void |
addUnsupportedPreOrPostfixExpressionError(Expression expression)Reports an unsupported prefix or postfix operation. |
|
protected void |
afterSwitchCaseStatementsVisited(SwitchStatement statement)* Hook method called after all case statements are visited, but before the default statement. * Subclasses may override to perform processing between cases and default. * *
|
|
protected void |
afterSwitchConditionExpressionVisited(SwitchStatement statement)* Hook method called after the switch condition expression is visited, but before case statements. * Subclasses may override to perform processing between condition and cases. * *
|
|
protected boolean |
areCategoryMethodCalls(List<MethodNode> foundMethods, String name, ClassNode[] args)Indicates whether all candidates are category-style extension methods. |
|
protected boolean |
checkCast(ClassNode targetType, Expression source)Checks whether the source expression can be cast to the supplied target type. |
|
protected void |
checkClosureParameters(Expression callArguments, ClassNode receiver)
|
|
protected void |
checkForbiddenSpreadArgument(ArgumentListExpression arguments)Rejects spread arguments where no target signature is available. |
|
protected void |
checkGroovyConstructorMap(Expression receiver, ClassNode receiverType, MapExpression mapExpression)Validates map-style constructor arguments against writable properties. |
|
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)Validates the current return statement against the enclosing closure or method. |
|
protected boolean |
existsProperty(PropertyExpression pexp, boolean checkForReadOnly)Checks whether the property exists for the current access mode. |
|
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) |
|
public 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 for TypeCheckingContext.temporaryIfBranchTypeInformation. |
|
protected static ClassNode[] |
extractTypesFromParameters(Parameter[] parameters)Extracts the declared types of the supplied 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 List<MethodNode> |
findMethod(ClassNode receiver, String name, ClassNode args)Finds candidate methods matching the supplied receiver, name, and argument types. |
|
protected MethodNode |
findMethodOrFail(Expression expr, ClassNode receiver, String name, ClassNode args)Finds a matching method or reports a static type error when none is available. |
|
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 static String |
formatArgumentList(ClassNode[] nodes)Formats an argument-type list for diagnostics. |
|
protected ClassNode[] |
getArgumentTypes(ArgumentListExpression argumentList)Returns the inferred argument types for the supplied argument list. |
|
protected DelegationMetadata |
getDelegationMetadata(ClosureExpression expression)Returns delegation metadata attached to the supplied closure expression. |
|
protected static ClassNode |
getGroupOperationResultType(ClassNode a, ClassNode b)Returns the result type for grouped numeric operations such as addition. |
|
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 { ... } call, this method is supposed to retrieve the inferred closure return type. |
|
protected ClassNode |
getOriginalDeclarationType(Expression lhs)Returns the declared type of the left-hand side before any flow-based refinement. |
|
protected ClassNode |
getResultType(ClassNode left, int op, ClassNode right, BinaryExpression expr)Computes the result type of a binary operation. |
|
protected SourceUnit |
getSourceUnit()* Provides access to the SourceUnit for error reporting during visitation. * Implementations must override this method. * *
|
|
protected List<ClassNode> |
getTemporaryTypesForExpression(Expression expression)Returns temporary narrowed types recorded for the supplied expression. |
|
protected ClassNode |
getType(ASTNode node)Returns the inferred type for the supplied AST node. |
|
protected ClassNode[] |
getTypeCheckingAnnotations()Returns array of type checking annotations. |
|
public TypeCheckingContext |
getTypeCheckingContext()Returns the current type checking context. |
|
protected static boolean |
hasRHSIncompleteGenericTypeInfo(ClassNode inferredRightExpressionType)Indicates whether the inferred type still contains unresolved placeholder generics. |
|
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)Infers the component type addressed by subscript or iterator access. |
|
protected void |
inferDiamondType(ConstructorCallExpression cce, ClassNode lType)Infers generic arguments for constructor calls that use the diamond operator. |
|
protected ClassNode |
inferListExpressionType(ListExpression list)Infers the static type of a list literal. |
|
public static ClassNode |
inferLoopElementType(ClassNode collectionType)Returns the inferred loop element type given a loop collection type. |
|
protected ClassNode |
inferMapExpressionType(MapExpression map)Infers the static type of a map literal. |
|
protected ClassNode |
inferRangeSliceType(ClassNode receiverType)GEP-20: probe the static return type of rhs.getAt(IntRange) on
receiverType, so the rest binder can be typed against the actual
slice type rather than a hard-coded List<T>. |
|
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. |
|
public void |
initialize()Initializes the registered type-checking extensions. |
|
protected static boolean |
isClassInnerClassOrEqualTo(ClassNode toBeChecked, ClassNode start)Indicates whether start is toBeChecked or nested within it. |
|
protected static boolean |
isNullConstant(Expression expression)Indicates whether the expression is the null constant. |
|
protected boolean |
isSecondPassNeededForControlStructure(Map<VariableExpression, ClassNode> startTypes, Map<VariableExpression, List<ClassNode>> oldTracker)Indicates whether a second pass is needed after visiting a control structure. |
|
public boolean |
isSkipMode(AnnotatedNode node)Indicates whether the annotated node is configured for TypeCheckingMode.SKIP. |
|
protected boolean |
isSkippedInnerClass(AnnotatedNode node)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)Indicates whether the expression represents super. |
|
protected static boolean |
isThisExpression(Expression expression)Indicates whether the expression represents this. |
|
protected List<Receiver<String>> |
makeOwnerList(Expression objectExpression)Given an object expression (a message receiver expression), generate list of possible types. |
|
public void |
performSecondPass()Replays deferred checks that require information collected during the first pass. |
|
protected Map<VariableExpression, ClassNode> |
popAssignmentTracking(Map<VariableExpression, List<ClassNode>> oldTracker)Pops the current assignment tracker and applies any merged types. |
|
protected static String |
prettyPrintMethodList(List<MethodNode> nodes)Formats a method list for diagnostics. |
|
protected Map<VariableExpression, List<ClassNode>> |
pushAssignmentTracking()Pushes a fresh assignment tracker and returns the previous tracker. |
|
protected void |
pushInstanceOfTypeInfo(Expression objectExpression, Expression typeExpression)Stores information about types when [objectExpression instanceof typeExpression] is visited. |
|
protected void |
restoreVariableExpressionMetadata(Map<VariableExpression, Map<StaticTypesMarker, Object>> typesBeforeVisit)Restores variable-expression metadata saved before a closure visit. |
|
protected void |
saveVariableExpressionMetadata(Set<VariableExpression> closureSharedExpressions, Map<VariableExpression, Map<StaticTypesMarker, Object>> typesBeforeVisit)Saves variable-expression metadata that must survive closure re-visits. |
|
public void |
setCompilationUnit(CompilationUnit compilationUnit)Associates the visitor with a compilation unit. |
|
public void |
setMethodsToBeVisited(Set<MethodNode> methodsToBeVisited)Restricts type checking to the supplied method set. |
|
protected boolean |
shouldSkipClassNode(ClassNode node)Indicates whether the class should be skipped by this visitor. |
|
protected boolean |
shouldSkipMethodNode(MethodNode node)Indicates whether the method should be skipped by this visitor. |
|
protected void |
silentlyVisitMethodNode(MethodNode directMethodCallCandidate)Visits a method call target, to infer the type. |
|
protected void |
startMethodInference(MethodNode node, ErrorCollector collector)Starts type inference for the supplied method using the supplied error 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)Stores the selected target method on the call expression. |
|
protected void |
storeType(Expression exp, ClassNode cn)Stores the inferred type for the supplied expression. |
|
protected void |
typeCheckAssignment(BinaryExpression assignmentExpression, Expression leftExpression, ClassNode leftExpressionType, Expression rightExpression, ClassNode rightExpressionType)Checks assignment compatibility and reports any associated type errors. |
|
protected void |
typeCheckClosureCall(Expression arguments, ClassNode[] argumentTypes, Parameter[] parameters)Validates closure calls against the signatures implied by the closure parameters. |
|
protected MethodNode |
typeCheckMapConstructor(ConstructorCallExpression call, ClassNode receiver, Expression arguments)Selects and validates a synthetic map-style constructor target. |
|
protected boolean |
typeCheckMethodsWithGenericsOrFail(ClassNode receiver, ClassNode[] arguments, MethodNode candidateMethod, Expression location)Validates a chosen method against its generic constraints and reports failures. |
|
public void |
visitArrayExpression(ArrayExpression expression)* Visits an ArrayExpression, traversing element expressions and size expressions. * *
|
|
public void |
visitAttributeExpression(AttributeExpression expression)* Visits an AttributeExpression, traversing the object and attribute name expressions. * *
|
|
public void |
visitBinaryExpression(BinaryExpression expression)* Visits a BinaryExpression, traversing left and right operand expressions. * *
|
|
public void |
visitBitwiseNegationExpression(BitwiseNegationExpression expression)* Visits a BitwiseNegationExpression, traversing the operand expression. * *
|
|
public void |
visitCaseStatement(CaseStatement statement)* Visits a CaseStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitCastExpression(CastExpression expression)* Visits a CastExpression, traversing the operand expression. * *
|
|
public void |
visitClass(ClassNode node)* Visits a ClassNode, processing its annotations, package, imports, contents, and object initializers. * *
|
|
public void |
visitClassExpression(ClassExpression expression)* Visits a ClassExpression. No traversal is performed as class expressions contain no child expressions. * *
|
|
public void |
visitClosureExpression(ClosureExpression expression)* Visits a ClosureExpression with annotation processing, traversing parameter annotations * before delegating to parent traversal. * *
|
|
public void |
visitConstructor(ConstructorNode node)* Visits a ConstructorNode, processing its annotations, parameter annotations, and code block. * *
|
|
public void |
visitConstructorCallExpression(ConstructorCallExpression call)* Visits a ConstructorCallExpression, traversing its argument list. * *
|
|
protected void |
visitConstructorOrMethod(MethodNode node, boolean isConstructor)* Visits a constructor or method node (implementation detail for both visit methods). * Processes the node's annotations, all parameter annotations, and code block. * *
|
|
public void |
visitExpressionStatement(ExpressionStatement statement)* Visits an ExpressionStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitField(FieldNode node)* Visits a FieldNode, processing its annotations and initial value expression if present. * *
|
|
public void |
visitForLoop(ForStatement forLoop)* Visits a ForStatement, invoking statement hooks and processing loop variable annotations. * *
|
|
public void |
visitIfElse(IfStatement ifElse)* Visits an IfStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitMethod(MethodNode node)* Visits a MethodNode, processing its annotations, parameter annotations, and code block. * *
|
|
protected void |
visitMethodCallArguments(ClassNode receiver, ArgumentListExpression arguments, boolean visitFunctors, MethodNode selectedMethod)Visits method-call arguments and defers functional arguments until a target is known. |
|
public void |
visitMethodCallExpression(MethodCallExpression call)* Visits a MethodCallExpression, traversing the object expression, * method expression, and argument list. * *
|
|
public void |
visitMethodPointerExpression(MethodPointerExpression expression)* Visits a MethodPointerExpression, traversing the object and method name expressions. * *
|
|
public void |
visitNotExpression(NotExpression expression)* Visits a NotExpression, traversing the operand expression. * *
|
|
protected void |
visitObjectInitializerStatements(ClassNode node)* Visits all object initializer statements in a class, typically static or instance initialization blocks. * *
|
|
public void |
visitPostfixExpression(PostfixExpression expression)* Visits a PostfixExpression, traversing the operand expression. * *
|
|
public void |
visitPrefixExpression(PrefixExpression expression)* Visits a PrefixExpression, traversing the operand expression. * *
|
|
public void |
visitProperty(PropertyNode node)* Visits a PropertyNode, processing its annotations, initial value expression, * and getter/setter blocks if present. * *
|
|
public void |
visitPropertyExpression(PropertyExpression expression)* Visits a PropertyExpression, traversing the object and property name expressions. * *
|
|
public void |
visitRangeExpression(RangeExpression expression)* Visits a RangeExpression, traversing from and to boundary expressions. * *
|
|
public void |
visitReturnStatement(ReturnStatement statement)* Visits a ReturnStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitStaticMethodCallExpression(StaticMethodCallExpression call)* Visits a StaticMethodCallExpression, traversing its argument list. * *
|
|
public void |
visitSwitch(SwitchStatement statement)* Visits a SwitchStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitTernaryExpression(TernaryExpression expression)* Visits a TernaryExpression, traversing the condition, true-branch, and false-branch expressions. * *
|
|
public void |
visitTryCatchFinally(TryCatchStatement statement)* Visits a TryCatchStatement, invoking the statement hook before parent traversal. * *
|
|
public void |
visitUnaryMinusExpression(UnaryMinusExpression expression)* Visits a UnaryMinusExpression, traversing the operand expression. * *
|
|
public void |
visitUnaryPlusExpression(UnaryPlusExpression expression)* Visits a UnaryPlusExpression, traversing the operand expression. * *
|
|
public void |
visitVariableExpression(VariableExpression vexp)* Visits a VariableExpression. No traversal is performed as variable expressions contain no child expressions. * *
|
|
public void |
visitWhileLoop(WhileStatement loop)* Visits a WhileStatement, invoking statement hooks before parent traversal. * *
|
|
protected static ClassNode |
wrapTypeIfNecessary(ClassNode type)Returns a wrapped type if, and only if, the provided class node is a primitive type. |
Cached CharSequence type (GROOVY-9848: membership operator dispatch).
Cached ClosureParams annotation type.
Cached zero-argument Closure#call() method.
Cached single-argument Closure#call(Object) method.
Cached varargs Closure#call(Object[]) method.
Constant expression for the current signature protocol version.
Current encoding protocol for stored type-checking signatures.
Cached DelegatesTo annotation type.
Cached DelegatesTo.Target annotation type.
Cached DefaultGroovyMethods type.
Shared empty method list.
Cached Enumeration type.
Metadata key used to store per-method error collectors.
Empty statement reused for synthetic AST nodes.
Cached Closure#getDelegate() method.
Cached Closure#getOwner() method.
Cached Closure#getThisObject() method.
Cached NamedParams annotation type.
Cached NamedParam annotation type.
Cached TypeChecked annotation type.
Type-checking annotations recognized by this visitor.
Cached TypeChecked.TypeCheckingInfo annotation type.
Field currently being visited.
Property currently being visited.
Composite extension chain consulted during type checking.
Return adder used to normalize implicit and explicit returns.
Mutable state for the current type-checking run.
Creates a static type-checking visitor for the supplied source and class.
Reports that method resolution remained ambiguous after filtering.
Reports an incompatible assignment between the supplied types.
Reports that categories cannot be used under static type checking.
Records a non-void return type for the current enclosing closure.
* Adds an error message associated with an AST node to the source unit. * Errors are accumulated and reported after visitation completes. * *
error - the error message to report
*node - the AST node associated with the error location
*Reports that no matching method or constructor could be found for the call.
Reports that no matching method or constructor could be found for the call.
Adds candidate receivers derived from owner chains.
Reports a static type checking error for the supplied node.
Adds a type-checking extension to the active extension chain.
Adds TypeChecked.TypeCheckingInfo metadata for an inferred method return type.
Reports an unsupported prefix or postfix operation.
* Hook method called after all case statements are visited, but before the default statement. * Subclasses may override to perform processing between cases and default. * *
statement - the switch statement being visited
** Hook method called after the switch condition expression is visited, but before case statements. * Subclasses may override to perform processing between condition and cases. * *
statement - the switch statement being visited
*Indicates whether all candidates are category-style extension methods.
Checks whether the source expression can be cast to the supplied target type.
Rejects spread arguments where no target signature is available.
Validates map-style constructor arguments against writable properties.
Checks that a constructor style expression is valid regarding the number of arguments and the argument types.
node - the class node for which we will try to find a matching constructorarguments - the constructor argumentsValidates the current return statement against the enclosing closure or method.
Checks whether the property exists for the current access mode.
Checks whether a property exists on the receiver, or on any of the possible receiver classes (found in the temporary type information table)
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 visitorGiven 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.
prefix - the method name prefix ("get", "is", "set", ...)methodName - the method nameComputes the key to use for TypeCheckingContext.temporaryIfBranchTypeInformation.
Extracts the declared types of the supplied parameters.
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.
expression - the expression for which an unknown field has been foundtype - the type of the expression (used as fallback type)Finds candidate methods matching the supplied receiver, name, and argument types.
Finds a matching method or reports a static type error when none is available.
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.
receiver - the type to search for methodsname - the name of the methods to returnFormats an argument-type list for diagnostics.
Returns the inferred argument types for the supplied argument list.
Returns delegation metadata attached to the supplied closure expression.
Returns the result type for grouped numeric operations such as addition.
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.
node - a ClosureExpression or MethodNodeIn the case of a Object.with { ... } call, this method is supposed to retrieve the inferred closure return type.
callArguments - the argument list from the Object#with(Closure) call, i.e. a single closure expressionReturns the declared type of the left-hand side before any flow-based refinement.
Computes the result type of a binary operation.
* Provides access to the SourceUnit for error reporting during visitation. * Implementations must override this method. * *
Returns temporary narrowed types recorded for the supplied expression.
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.
Returns the current type checking context. The context is used internally by the type checker during type checking to store various state data.
Indicates whether the inferred type still contains unresolved placeholder generics.
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 its Closure argument annotated with ClosureParams. If
so, then additional type inference can be performed and the type of
it may be inferred.
expression - closure or lambda expression for which the argument types should be inferredtarget - parameter which may provide ClosureParams annotation or SAM typemethod - method that declares targetInfers the component type addressed by subscript or iterator access.
Infers generic arguments for constructor calls that use the diamond operator.
Infers the static type of a list literal.
Returns the inferred loop element type given a loop collection type. Used,
for example, to infer the element type of a for (e in list) loop.
collectionType - the type of the collectionInfers the static type of a map literal.
GEP-20: probe the static return type of rhs.getAt(IntRange) on
receiverType, so the rest binder can be typed against the actual
slice type rather than a hard-coded List<T>. Returns the resolved
slice type (e.g. String for a String receiver, BitSet for
a BitSet receiver, the user-declared return type for custom classes), or
null if the receiver has no resolvable getAt(IntRange).
Mirrors inferComponentType but for the IntRange overload. Method resolution runs under a swallowed error collector so a missing overload doesn't surface as a static-type error.
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 method Arrays.asList(T...) is parameterized with
T, which can be deduced type arguments or call arguments.
method - the method nodearguments - the method call argumentsreceiver - the object expression type 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 method Arrays.asList(T...) is parameterized with
T, which can be deduced type arguments or call arguments.
method - the method nodearguments - the method call argumentsreceiver - the object expression typeexplicitTypeHints - type arguments (optional), for example Collections.<String>emptyList()Initializes the registered type-checking extensions.
Indicates whether start is toBeChecked or nested within it.
Indicates whether the expression is the null constant.
Indicates whether a second pass is needed after visiting a control structure.
Indicates whether the annotated node is configured for TypeCheckingMode.SKIP.
Tests if a node is an inner class node, and if it is, then checks if the enclosing method is skipped.
Indicates whether the expression represents super.
Indicates whether the expression represents this.
Given an object expression (a message receiver expression), generate list of possible types.
objectExpression - the message receiverReplays deferred checks that require information collected during the first pass.
Pops the current assignment tracker and applies any merged types.
Formats a method list for diagnostics.
Pushes a fresh assignment tracker and returns the previous tracker.
Stores information about types when [objectExpression instanceof typeExpression] is visited.
objectExpression - the expression to be checked against instanceoftypeExpression - the expression which represents the target typeRestores variable-expression metadata saved before a closure visit.
Saves variable-expression metadata that must survive closure re-visits.
Associates the visitor with a compilation unit.
Restricts type checking to the supplied method set.
Indicates whether the class should be skipped by this visitor.
Indicates whether the method should be skipped by this visitor.
Visits a method call target, to infer the type. Don't report errors right away, that will be done by a later visitMethod call.
Starts type inference for the supplied method using the supplied error collector.
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 is Closure, which is different from the inferred type of the code of the closure.
node - a ClosureExpression or MethodNodetype - the inferred return type of the codeStores the selected target method on the call expression.
Stores the inferred type for the supplied expression.
Checks assignment compatibility and reports any associated type errors.
Validates closure calls against the signatures implied by the closure parameters.
Selects and validates a synthetic map-style constructor target.
Validates a chosen method against its generic constraints and reports failures.
* Visits an ArrayExpression, traversing element expressions and size expressions. * *
expression - the array expression* Visits an AttributeExpression, traversing the object and attribute name expressions. * *
expression - the attribute expression* Visits a BinaryExpression, traversing left and right operand expressions. * *
expression - the binary expression* Visits a BitwiseNegationExpression, traversing the operand expression. * *
expression - the bitwise negation expression* Visits a CaseStatement, invoking the statement hook before parent traversal. * *
statement - the case statement to visit* Visits a CastExpression, traversing the operand expression. * *
expression - the cast expression* Visits a ClassNode, processing its annotations, package, imports, contents, and object initializers. * *
node - the class node to visit* Visits a ClassExpression. No traversal is performed as class expressions contain no child expressions. * *
expression - the class expression* Visits a ClosureExpression with annotation processing, traversing parameter annotations * before delegating to parent traversal. * *
expression - the closure expression to visit* Visits a ConstructorNode, processing its annotations, parameter annotations, and code block. * *
node - the constructor node to visit* Visits a ConstructorCallExpression, traversing its argument list. * *
call - the constructor call expression* Visits a constructor or method node (implementation detail for both visit methods). * Processes the node's annotations, all parameter annotations, and code block. * *
node - the method or constructor node
*isConstructor - true if node is a constructor, false if it is a method* Visits an ExpressionStatement, invoking the statement hook before parent traversal. * *
statement - the expression statement to visit* Visits a FieldNode, processing its annotations and initial value expression if present. * *
node - the field node to visit* Visits a ForStatement, invoking statement hooks and processing loop variable annotations. * *
statement - the for statement to visit* Visits an IfStatement, invoking the statement hook before parent traversal. * *
statement - the if statement to visit* Visits a MethodNode, processing its annotations, parameter annotations, and code block. * *
node - the method node to visitVisits method-call arguments and defers functional arguments until a target is known.
* Visits a MethodCallExpression, traversing the object expression, * method expression, and argument list. * *
call - the method call expression* Visits a MethodPointerExpression, traversing the object and method name expressions. * *
expression - the method pointer expression* Visits a NotExpression, traversing the operand expression. * *
expression - the not expression* Visits all object initializer statements in a class, typically static or instance initialization blocks. * *
node - the class node containing initializer statements* Visits a PostfixExpression, traversing the operand expression. * *
expression - the postfix expression* Visits a PrefixExpression, traversing the operand expression. * *
expression - the prefix expression* Visits a PropertyNode, processing its annotations, initial value expression, * and getter/setter blocks if present. * *
node - the property node to visit* Visits a PropertyExpression, traversing the object and property name expressions. * *
expression - the property expression* Visits a RangeExpression, traversing from and to boundary expressions. * *
expression - the range expression* Visits a ReturnStatement, invoking the statement hook before parent traversal. * *
statement - the return statement to visit* Visits a StaticMethodCallExpression, traversing its argument list. * *
call - the static method call expression* Visits a SwitchStatement, invoking the statement hook before parent traversal. * *
statement - the switch statement to visit* Visits a TernaryExpression, traversing the condition, true-branch, and false-branch expressions. * *
expression - the ternary expression* Visits a TryCatchStatement, invoking the statement hook before parent traversal. * *
statement - the try-catch statement to visit* Visits a UnaryMinusExpression, traversing the operand expression. * *
expression - the unary minus expression* Visits a UnaryPlusExpression, traversing the operand expression. * *
expression - the unary plus expression* Visits a VariableExpression. No traversal is performed as variable expressions contain no child expressions. * *
expression - the variable expression* Visits a WhileStatement, invoking statement hooks before parent traversal. * *
statement - the while statement to visitReturns a wrapped type if, and only if, the provided class node is a primitive type. This method differs from ClassHelper#getWrapper(org.codehaus.groovy.ast.ClassNode) as it will return the same instance if the provided type is not a generic type.
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.