Package org.codehaus.groovy.control
Class ResolveVisitor
java.lang.Object
org.codehaus.groovy.ast.CodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeVisitorSupport
org.codehaus.groovy.ast.ClassCodeExpressionTransformer
org.codehaus.groovy.control.ResolveVisitor
- All Implemented Interfaces:
ExpressionTransformer,GroovyClassVisitor,GroovyCodeVisitor,ErrorCollecting
- Direct Known Subclasses:
JavaAwareResolveVisitor
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).
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionResolveVisitor(CompilationUnit compilationUnit) Creates a resolve visitor for the supplied compilation unit. -
Method Summary
Modifier and TypeMethodDescriptionprotected SourceUnitReturns the source unit currently being resolved.protected booleanResolves a type using the standard Groovy lookup rules.protected booleanresolve(ClassNode type, boolean testModuleImports, boolean testDefaultImports, boolean testStaticInnerClasses) Resolves a type while selectively enabling parts of the standard lookup sequence.protected booleanResolves a type from classes already known to the current compile unit.protected booleanResolves a type through Groovy's default imports.protected booleanresolveFromDefaultImports(ClassNode type, String[] packagePrefixes) Resolves a type against the supplied import prefixes.protected booleanresolveFromModule(ClassNode type, boolean testModuleImports) Resolves a type using module package, regular imports, star imports, and module-expanded imports.protected booleanResolves a qualified type name by treating suffix segments as static inner classes.protected booleanresolveNestedClass(ClassNode type) Resolves a type name against nested classes visible from the current class hierarchy.protected booleanresolveToInner(ClassNode type) Attempts to resolve an unqualified type against visible inner classes.protected booleanresolveToOuter(ClassNode type) Resolves a type via the configuredClassNodeResolver.voidsetClassNodeResolver(ClassNodeResolver classNodeResolver) Replaces the class-node resolver used for classpath lookups.voidstartResolving(ClassNode node, SourceUnit source) Starts resolving class references from the supplied class node.transform(Expression exp) Resolves and rewrites expressions while traversing the current class.protected ExpressionResolves annotation constants encountered in expression form.protected ExpressionResolves type references appearing in binary expressions.protected ExpressionResolves declared types and defaults inside a closure expression.protected ExpressionResolves constructor call target types.protected ExpressionResolves declared variable types in a declaration expression.protected ExpressionResolves receiver, method, and argument types for a method call.protected ExpressionResolves type references embedded in a property expression.protected ExpressionResolves variable expressions that may actually reference types.protected voidResolves an annotation type and its member values.voidUpdates the current variable scope while visiting a block statement.voidResolves the declared exception type for a catch parameter.voidvisitClass(ClassNode node) Resolves imports, headers, and member types for the supplied class.protected voidvisitConstructorOrMethod(MethodNode node, boolean isConstructor) Resolves types referenced by a constructor or method signature.voidvisitField(FieldNode node) Resolves the declared type of a field before visiting its contents.voidvisitForLoop(ForStatement forLoop) Resolves the declared loop variable type for aforstatement.voidvisitProperty(PropertyNode node) Resolves the declared type of a property before visiting its contents.protected voidvisitStatementAnnotations(Statement statement) Resolves the class nodes of any annotations attached to a loop statement (stored in statement metadata rather than inAnnotatedNode).Methods inherited from class org.codehaus.groovy.ast.ClassCodeExpressionTransformer
setSourcePosition, visitAssertStatement, visitCaseStatement, visitClosureExpression, visitDoWhileLoop, visitExpressionStatement, visitIfElse, visitReturnStatement, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitWhileLoopMethods inherited from class org.codehaus.groovy.ast.ClassCodeVisitorSupport
addError, visitAnnotations, visitAnnotations, visitBreakStatement, visitClassCodeContainer, visitConstructor, visitContinueStatement, visitDeclarationExpression, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitStatement, visitTryCatchFinallyMethods inherited from class org.codehaus.groovy.ast.CodeVisitorSupport
afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBooleanExpression, visitBytecodeExpression, visitCastExpression, visitClassExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitEmptyStatement, visitFieldExpression, visitGStringExpression, visitLambdaExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitTernaryExpression, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpressionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.codehaus.groovy.ast.GroovyCodeVisitor
visit, visit, visitEmptyExpression, visitListOfExpressions
-
Field Details
-
DEFAULT_IMPORTS
Default package imports available to Groovy source. -
EMPTY_STRING_ARRAY
Shared empty array constant for import-prefix lookups. -
QUESTION_MARK
Placeholder name used for wildcard generic arguments.- See Also:
-
-
Constructor Details
-
ResolveVisitor
Creates a resolve visitor for the supplied compilation unit.- Parameters:
compilationUnit- the compilation unit being resolved
-
-
Method Details
-
setClassNodeResolver
Replaces the class-node resolver used for classpath lookups.- Parameters:
classNodeResolver- the resolver to use
-
startResolving
Starts resolving class references from the supplied class node.- Parameters:
node- the class to resolvesource- the source unit containing the class
-
getSourceUnit
Returns the source unit currently being resolved.- Specified by:
getSourceUnitin classClassCodeVisitorSupport- Returns:
- the active source unit
-
visitField
Resolves the declared type of a field before visiting its contents.- Specified by:
visitFieldin interfaceGroovyClassVisitor- Overrides:
visitFieldin classClassCodeExpressionTransformer- Parameters:
node- the field to visit
-
visitProperty
Resolves the declared type of a property before visiting its contents.- Specified by:
visitPropertyin interfaceGroovyClassVisitor- Overrides:
visitPropertyin classClassCodeExpressionTransformer- Parameters:
node- the property to visit
-
visitConstructorOrMethod
Resolves types referenced by a constructor or method signature.- Overrides:
visitConstructorOrMethodin classClassCodeExpressionTransformer- Parameters:
node- the executable member to inspectisConstructor- whethernodeis a constructor
-
resolveToInner
Attempts to resolve an unqualified type against visible inner classes.- Parameters:
type- the type to resolve- Returns:
trueif the type was resolved
-
resolve
Resolves a type using the standard Groovy lookup rules.- Parameters:
type- the type to resolve- Returns:
trueif the type was resolved
-
resolve
protected boolean resolve(ClassNode type, boolean testModuleImports, boolean testDefaultImports, boolean testStaticInnerClasses) Resolves a type while selectively enabling parts of the standard lookup sequence.- Parameters:
type- the type to resolvetestModuleImports- whether module imports should be consultedtestDefaultImports- whether default imports should be consultedtestStaticInnerClasses- whether static inner-class resolution should be attempted- Returns:
trueif the type was resolved
-
resolveNestedClass
Resolves a type name against nested classes visible from the current class hierarchy.- Parameters:
type- the type to resolve- Returns:
trueif the type was resolved
-
resolveFromStaticInnerClasses
Resolves a qualified type name by treating suffix segments as static inner classes.- Parameters:
type- the type to resolve- Returns:
trueif the type was resolved
-
resolveFromDefaultImports
Resolves a type through Groovy's default imports.- Parameters:
type- the type to resolve- Returns:
trueif the type was resolved
-
resolveFromDefaultImports
Resolves a type against the supplied import prefixes.- Parameters:
type- the type to resolvepackagePrefixes- the package prefixes to test- Returns:
trueif the type was resolved
-
resolveFromCompileUnit
Resolves a type from classes already known to the current compile unit.- Parameters:
type- the type to resolve- Returns:
trueif the type was resolved
-
resolveFromModule
Resolves a type using module package, regular imports, star imports, and module-expanded imports.- Parameters:
type- the type to resolvetestModuleImports- whether module-level imports should be consulted- Returns:
trueif the type was resolved
-
resolveToOuter
Resolves a type via the configuredClassNodeResolver.- Parameters:
type- the type to resolve- Returns:
trueif the type was resolved
-
transform
Resolves and rewrites expressions while traversing the current class.- Specified by:
transformin interfaceExpressionTransformer- Overrides:
transformin classClassCodeExpressionTransformer- Parameters:
exp- the expression to transform- Returns:
- the transformed expression
-
transformPropertyExpression
Resolves type references embedded in a property expression.- Parameters:
pe- the property expression to transform- Returns:
- the transformed expression
-
transformVariableExpression
Resolves variable expressions that may actually reference types.- Parameters:
ve- the variable expression to transform- Returns:
- the transformed expression
-
transformBinaryExpression
Resolves type references appearing in binary expressions.- Parameters:
be- the binary expression to transform- Returns:
- the transformed expression
-
transformClosureExpression
Resolves declared types and defaults inside a closure expression.- Parameters:
ce- the closure expression to transform- Returns:
- the transformed expression
-
transformConstructorCallExpression
Resolves constructor call target types.- Parameters:
cce- the constructor call to transform- Returns:
- the transformed expression
-
transformMethodCallExpression
Resolves receiver, method, and argument types for a method call.- Parameters:
mce- the method call to transform- Returns:
- the transformed expression
-
transformDeclarationExpression
Resolves declared variable types in a declaration expression.- Parameters:
de- the declaration expression to transform- Returns:
- the transformed expression
-
transformAnnotationConstantExpression
Resolves annotation constants encountered in expression form.- Parameters:
ace- the annotation constant expression to transform- Returns:
- the original expression
-
visitAnnotation
Resolves an annotation type and its member values.- Overrides:
visitAnnotationin classClassCodeExpressionTransformer- Parameters:
node- the annotation to visit
-
visitClass
Resolves imports, headers, and member types for the supplied class.- Specified by:
visitClassin interfaceGroovyClassVisitor- Overrides:
visitClassin classClassCodeVisitorSupport- Parameters:
node- the class to visit
-
visitCatchStatement
Resolves the declared exception type for a catch parameter.- Specified by:
visitCatchStatementin interfaceGroovyCodeVisitor- Overrides:
visitCatchStatementin classClassCodeVisitorSupport- Parameters:
cs- the catch statement to visit
-
visitStatementAnnotations
Resolves the class nodes of any annotations attached to a loop statement (stored in statement metadata rather than inAnnotatedNode).- Overrides:
visitStatementAnnotationsin classClassCodeVisitorSupport- Parameters:
statement- the loop statement that may have statement-level annotations
-
visitForLoop
Resolves the declared loop variable type for aforstatement.- Specified by:
visitForLoopin interfaceGroovyCodeVisitor- Overrides:
visitForLoopin classClassCodeExpressionTransformer- Parameters:
forLoop- the loop to visit
-
visitBlockStatement
Updates the current variable scope while visiting a block statement.- Specified by:
visitBlockStatementin interfaceGroovyCodeVisitor- Overrides:
visitBlockStatementin classClassCodeVisitorSupport- Parameters:
block- the block to visit- See Also:
-