Package: org.codehaus.groovy.control

## [Java] Class ResolveVisitor

- org.codehaus.groovy.control.ResolveVisitor

-     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).

- - ### Field Summary

    Fields
    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 Summary

    Constructors
    Constructor and description
    `ResolveVisitor(CompilationUnit compilationUnit)` Creates a resolve visitor for the supplied compilation unit.

  - ### Methods Summary

    Methods
    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).

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class ClassCodeExpressionTransformer` | `setSourcePosition, transform, visitAnnotation, visitAssertStatement, visitCaseStatement, visitClosureExpression, visitConstructorOrMethod, visitDoWhileLoop, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitProperty, visitReturnStatement, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitWhileLoop`
    `class ClassCodeVisitorSupport` | `addError, getSourceUnit, visitAnnotation, visitAnnotations, visitAnnotations, visitAssertStatement, visitBlockStatement, visitBreakStatement, visitCaseStatement, visitCatchStatement, visitClass, visitClassCodeContainer, visitClosureExpression, visitConstructor, visitConstructorOrMethod, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitExpressionStatement, visitField, visitForLoop, visitIfElse, visitImports, visitMethod, visitObjectInitializerStatements, visitPackage, visitProperty, visitReturnStatement, visitStatement, visitStatementAnnotations, visitSwitch, visitSynchronizedStatement, visitThrowStatement, visitTryCatchFinally, visitWhileLoop`
    `class CodeVisitorSupport` | `afterSwitchCaseStatementsVisited, afterSwitchConditionExpressionVisited, visitArgumentlistExpression, visitArrayExpression, visitAssertStatement, visitAttributeExpression, visitBinaryExpression, visitBitwiseNegationExpression, visitBlockStatement, visitBooleanExpression, visitBreakStatement, visitBytecodeExpression, visitCaseStatement, visitCastExpression, visitCatchStatement, visitClassExpression, visitClosureExpression, visitClosureListExpression, visitConstantExpression, visitConstructorCallExpression, visitContinueStatement, visitDeclarationExpression, visitDoWhileLoop, visitEmptyStatement, visitExpressionStatement, visitFieldExpression, visitForLoop, visitGStringExpression, visitIfElse, visitLambdaExpression, visitListExpression, visitMapEntryExpression, visitMapExpression, visitMethodCallExpression, visitMethodPointerExpression, visitMethodReferenceExpression, visitNotExpression, visitPostfixExpression, visitPrefixExpression, visitPropertyExpression, visitRangeExpression, visitReturnStatement, visitShortTernaryExpression, visitSpreadExpression, visitSpreadMapExpression, visitStaticMethodCallExpression, visitSwitch, visitSynchronizedStatement, visitTernaryExpression, visitThrowStatement, visitTryCatchFinally, visitTupleExpression, visitUnaryMinusExpression, visitUnaryPlusExpression, visitVariableExpression, visitWhileLoop`

- - ### Field Detail

    - #### public static final String[] DEFAULT_IMPORTS

      Default package imports available to Groovy source.

    - #### public static final String[] EMPTY_STRING_ARRAY

      Shared empty array constant for import-prefix lookups.

    - #### public static final String QUESTION_MARK

      Placeholder name used for wildcard generic arguments.

  - ### Constructor Detail

    - #### public ResolveVisitor(CompilationUnit compilationUnit)

      Creates a resolve visitor for the supplied compilation unit.

      Parameters:
        `compilationUnit` - the compilation unit being resolved

  - ### Method Detail

    - #### protected SourceUnit getSourceUnit()

      Returns the source unit currently being resolved.

      Returns:
        the active source unit

    - #### protected boolean resolve(ClassNode type)

      Resolves a type using the standard Groovy lookup rules.

      Parameters:
        `type` - the type to resolve
      Returns:
        `true` if the type was resolved

    - #### 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 resolve
        `testModuleImports` - whether module imports should be consulted
        `testDefaultImports` - whether default imports should be consulted
        `testStaticInnerClasses` - whether static inner-class resolution should be attempted
      Returns:
        `true` if the type was resolved

    - #### protected boolean resolveFromCompileUnit(ClassNode type)

      Resolves a type from classes already known to the current compile unit.

      Parameters:
        `type` - the type to resolve
      Returns:
        `true` if the type was resolved

    - #### protected boolean resolveFromDefaultImports(ClassNode type)

      Resolves a type through Groovy's default imports.

      Parameters:
        `type` - the type to resolve
      Returns:
        `true` if the type was resolved

    - #### protected boolean resolveFromDefaultImports(ClassNode type, String[] packagePrefixes)

      Resolves a type against the supplied import prefixes.

      Parameters:
        `type` - the type to resolve
        `packagePrefixes` - the package prefixes to test
      Returns:
        `true` if the type was resolved

    - #### protected boolean resolveFromModule(ClassNode type, boolean testModuleImports)

      Resolves a type using module package, regular imports, star imports, and module-expanded imports.

      Parameters:
        `type` - the type to resolve
        `testModuleImports` - whether module-level imports should be consulted
      Returns:
        `true` if the type was resolved

    - #### protected boolean resolveFromStaticInnerClasses(ClassNode type)

      Resolves a qualified type name by treating suffix segments as static inner classes.

      Parameters:
        `type` - the type to resolve
      Returns:
        `true` if the type was resolved

    - #### protected boolean resolveNestedClass(ClassNode type)

      Resolves a type name against nested classes visible from the current class hierarchy.

      Parameters:
        `type` - the type to resolve
      Returns:
        `true` if the type was resolved

    - #### protected boolean resolveToInner(ClassNode type)

      Attempts to resolve an unqualified type against visible inner classes.

      Parameters:
        `type` - the type to resolve
      Returns:
        `true` if the type was resolved

    - #### protected boolean resolveToOuter(ClassNode type)

      Resolves a type via the configured ClassNodeResolver.

      Parameters:
        `type` - the type to resolve
      Returns:
        `true` if the type was resolved

    - #### public void setClassNodeResolver(ClassNodeResolver classNodeResolver)

      Replaces the class-node resolver used for classpath lookups.

      Parameters:
        `classNodeResolver` - the resolver to use

    - #### public void startResolving(ClassNode node, SourceUnit source)

      Starts resolving class references from the supplied class node.

      Parameters:
        `node` - the class to resolve
        `source` - the source unit containing the class

    - #### public Expression transform(Expression exp)

      Resolves and rewrites expressions while traversing the current class.

      Parameters:
        `exp` - the expression to transform
      Returns:
        the transformed expression

    - #### protected Expression transformAnnotationConstantExpression(AnnotationConstantExpression ace)

      Resolves annotation constants encountered in expression form.

      Parameters:
        `ace` - the annotation constant expression to transform
      Returns:
        the original expression

    - #### protected Expression transformBinaryExpression(BinaryExpression be)

      Resolves type references appearing in binary expressions.

      Parameters:
        `be` - the binary expression to transform
      Returns:
        the transformed expression

    - #### protected Expression transformClosureExpression(ClosureExpression ce)

      Resolves declared types and defaults inside a closure expression.

      Parameters:
        `ce` - the closure expression to transform
      Returns:
        the transformed expression

    - #### protected Expression transformConstructorCallExpression(ConstructorCallExpression cce)

      Resolves constructor call target types.

      Parameters:
        `cce` - the constructor call to transform
      Returns:
        the transformed expression

    - #### protected Expression transformDeclarationExpression(DeclarationExpression de)

      Resolves declared variable types in a declaration expression.

      Parameters:
        `de` - the declaration expression to transform
      Returns:
        the transformed expression

    - #### protected Expression transformMethodCallExpression(MethodCallExpression mce)

      Resolves receiver, method, and argument types for a method call.

      Parameters:
        `mce` - the method call to transform
      Returns:
        the transformed expression

    - #### protected Expression transformPropertyExpression(PropertyExpression pe)

      Resolves type references embedded in a property expression.

      Parameters:
        `pe` - the property expression to transform
      Returns:
        the transformed expression

    - #### protected Expression transformVariableExpression(VariableExpression ve)

      Resolves variable expressions that may actually reference types.

      Parameters:
        `ve` - the variable expression to transform
      Returns:
        the transformed expression

    - #### protected void visitAnnotation(AnnotationNode node)

      Resolves an annotation type and its member values.

      Parameters:
        `node` - the annotation to visit

    - #### public void visitBlockStatement(BlockStatement block)

      Updates the current variable scope while visiting a block statement.

      Parameters:
        `block` - the block to visit

    - #### public void visitCatchStatement(CatchStatement cs)

      Resolves the declared exception type for a catch parameter.

      Parameters:
        `cs` - the catch statement to visit

    - #### public void visitClass(ClassNode node)

      Resolves imports, headers, and member types for the supplied class.

      Parameters:
        `node` - the class to visit

    - #### protected void visitConstructorOrMethod(MethodNode node, boolean isConstructor)

      Resolves types referenced by a constructor or method signature.

      Parameters:
        `node` - the executable member to inspect
        `isConstructor` - whether `node` is a constructor

    - #### public void visitField(FieldNode node)

      Resolves the declared type of a field before visiting its contents.

      Parameters:
        `node` - the field to visit

    - #### public void visitForLoop(ForStatement forLoop)

      Resolves the declared loop variable type for a `for` statement.

      Parameters:
        `forLoop` - the loop to visit

    - #### public void visitProperty(PropertyNode node)

      Resolves the declared type of a property before visiting its contents.

      Parameters:
        `node` - the property to visit

    - #### 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).