public class ResolveVisitor
extends ClassCodeExpressionTransformer
Visitor to resolve types and convert VariableExpression to ClassExpressions if needed. The ResolveVisitor will try to find the Class for a ClassExpression and prints an error if it fails to do so. Constructions like C[], foo as C, (C) foo will force creation of a ClassExpression for C
Note: the method to start the resolving is startResolving(ClassNode,SourceUnit).
| Modifiers | Name | Description |
|---|---|---|
static String[] |
DEFAULT_IMPORTS |
Default package imports available to Groovy source. |
static String[] |
EMPTY_STRING_ARRAY |
Shared empty array constant for import-prefix lookups. |
static String |
QUESTION_MARK |
Placeholder name used for wildcard generic arguments. |
| Constructor and description |
|---|
ResolveVisitor(CompilationUnit compilationUnit)Creates a resolve visitor for the supplied compilation unit. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected SourceUnit |
getSourceUnit()Returns the source unit currently being resolved. |
|
protected boolean |
resolve(ClassNode type)Resolves a type using the standard Groovy lookup rules. |
|
protected boolean |
resolve(ClassNode type, boolean testModuleImports, boolean testDefaultImports, boolean testStaticInnerClasses)Resolves a type while selectively enabling parts of the standard lookup sequence. |
|
protected boolean |
resolveFromCompileUnit(ClassNode type)Resolves a type from classes already known to the current compile unit. |
|
protected boolean |
resolveFromDefaultImports(ClassNode type)Resolves a type through Groovy's default imports. |
|
protected boolean |
resolveFromDefaultImports(ClassNode type, String[] packagePrefixes)Resolves a type against the supplied import prefixes. |
|
protected boolean |
resolveFromModule(ClassNode type, boolean testModuleImports)Resolves a type using module package, regular imports, star imports, and module-expanded imports. |
|
protected boolean |
resolveFromStaticInnerClasses(ClassNode type)Resolves a qualified type name by treating suffix segments as static inner classes. |
|
protected boolean |
resolveNestedClass(ClassNode type)Resolves a type name against nested classes visible from the current class hierarchy. |
|
protected boolean |
resolveToInner(ClassNode type)Attempts to resolve an unqualified type against visible inner classes. |
|
protected boolean |
resolveToOuter(ClassNode type)Resolves a type via the configured ClassNodeResolver. |
|
public void |
setClassNodeResolver(ClassNodeResolver classNodeResolver)Replaces the class-node resolver used for classpath lookups. |
|
public void |
startResolving(ClassNode node, SourceUnit source)Starts resolving class references from the supplied class node. |
|
public Expression |
transform(Expression exp)Resolves and rewrites expressions while traversing the current class. |
|
protected Expression |
transformAnnotationConstantExpression(AnnotationConstantExpression ace)Resolves annotation constants encountered in expression form. |
|
protected Expression |
transformBinaryExpression(BinaryExpression be)Resolves type references appearing in binary expressions. |
|
protected Expression |
transformClosureExpression(ClosureExpression ce)Resolves declared types and defaults inside a closure expression. |
|
protected Expression |
transformConstructorCallExpression(ConstructorCallExpression cce)Resolves constructor call target types. |
|
protected Expression |
transformDeclarationExpression(DeclarationExpression de)Resolves declared variable types in a declaration expression. |
|
protected Expression |
transformMethodCallExpression(MethodCallExpression mce)Resolves receiver, method, and argument types for a method call. |
|
protected Expression |
transformPropertyExpression(PropertyExpression pe)Resolves type references embedded in a property expression. |
|
protected Expression |
transformVariableExpression(VariableExpression ve)Resolves variable expressions that may actually reference types. |
|
protected void |
visitAnnotation(AnnotationNode node)Resolves an annotation type and its member values. |
|
public void |
visitBlockStatement(BlockStatement block)Updates the current variable scope while visiting a block statement. |
|
public void |
visitCatchStatement(CatchStatement cs)Resolves the declared exception type for a catch parameter. |
|
public void |
visitClass(ClassNode node)Resolves imports, headers, and member types for the supplied class. |
|
protected void |
visitConstructorOrMethod(MethodNode node, boolean isConstructor)Resolves types referenced by a constructor or method signature. |
|
public void |
visitField(FieldNode node)Resolves the declared type of a field before visiting its contents. |
|
public void |
visitForLoop(ForStatement forLoop)Resolves the declared loop variable type for a for statement. |
|
public void |
visitProperty(PropertyNode node)Resolves the declared type of a property before visiting its contents. |
|
protected void |
visitStatementAnnotations(Statement statement)Resolves the class nodes of any annotations attached to a loop statement (stored in statement metadata rather than in AnnotatedNode). |
Default package imports available to Groovy source.
Shared empty array constant for import-prefix lookups.
Placeholder name used for wildcard generic arguments.
Creates a resolve visitor for the supplied compilation unit.
compilationUnit - the compilation unit being resolvedReturns the source unit currently being resolved.
Resolves a type using the standard Groovy lookup rules.
type - the type to resolvetrue if the type was resolvedResolves a type while selectively enabling parts of the standard lookup sequence.
type - the type to resolvetestModuleImports - whether module imports should be consultedtestDefaultImports - whether default imports should be consultedtestStaticInnerClasses - whether static inner-class resolution should be attemptedtrue if the type was resolvedResolves a type from classes already known to the current compile unit.
type - the type to resolvetrue if the type was resolvedResolves a type through Groovy's default imports.
type - the type to resolvetrue if the type was resolvedResolves a type against the supplied import prefixes.
type - the type to resolvepackagePrefixes - the package prefixes to testtrue if the type was resolvedResolves a type using module package, regular imports, star imports, and module-expanded imports.
type - the type to resolvetestModuleImports - whether module-level imports should be consultedtrue if the type was resolvedResolves a qualified type name by treating suffix segments as static inner classes.
type - the type to resolvetrue if the type was resolvedResolves a type name against nested classes visible from the current class hierarchy.
type - the type to resolvetrue if the type was resolvedAttempts to resolve an unqualified type against visible inner classes.
type - the type to resolvetrue if the type was resolvedResolves a type via the configured ClassNodeResolver.
type - the type to resolvetrue if the type was resolvedReplaces the class-node resolver used for classpath lookups.
classNodeResolver - the resolver to useStarts resolving class references from the supplied class node.
node - the class to resolvesource - the source unit containing the classResolves and rewrites expressions while traversing the current class.
exp - the expression to transformResolves annotation constants encountered in expression form.
ace - the annotation constant expression to transformResolves type references appearing in binary expressions.
be - the binary expression to transformResolves declared types and defaults inside a closure expression.
ce - the closure expression to transformResolves constructor call target types.
cce - the constructor call to transformResolves declared variable types in a declaration expression.
de - the declaration expression to transformResolves receiver, method, and argument types for a method call.
mce - the method call to transformResolves type references embedded in a property expression.
pe - the property expression to transformResolves variable expressions that may actually reference types.
ve - the variable expression to transformResolves an annotation type and its member values.
node - the annotation to visitUpdates the current variable scope while visiting a block statement.
block - the block to visitResolves the declared exception type for a catch parameter.
cs - the catch statement to visitResolves imports, headers, and member types for the supplied class.
node - the class to visitResolves types referenced by a constructor or method signature.
node - the executable member to inspectisConstructor - whether node is a constructorResolves the declared type of a field before visiting its contents.
node - the field to visit Resolves the declared loop variable type for a for statement.
forLoop - the loop to visitResolves the declared type of a property before visiting its contents.
node - the property to visitResolves the class nodes of any annotations attached to a loop statement (stored in statement metadata rather than in AnnotatedNode).
Copyright © 2003-2026 The Apache Software Foundation. All rights reserved.