Package: org.codehaus.groovy.control

## [Java] Class ClassNodeResolver

- org.codehaus.groovy.control.ClassNodeResolver

-     public class ClassNodeResolver
      extends Object

  This class is used as a pluggable way to resolve class names. An instance of this class has to be added to CompilationUnit using CompilationUnit.setClassNodeResolver. The CompilationUnit will then set the resolver on the ResolveVisitor each time new. The ResolveVisitor will prepare name lookup and then finally ask the resolver if the class exists. This resolver then can return either a SourceUnit or a ClassNode. In case of a SourceUnit the compiler is notified that a new source is to be added to the compilation queue. In case of a ClassNode no further action than the resolving is done. The lookup result is stored in the helper class LookupResult. This class provides a class cache to cache lookups. If you don't want this, you have to override the methods ClassNodeResolver.cacheClass and ClassNodeResolver.getFromClassCache. Custom lookup logic is supposed to go into the method ClassNodeResolver.findClassNode while the entry method is ClassNodeResolver.resolveName

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `static class` | `ClassNodeResolver.LookupResult` | Helper class to return either a SourceUnit or ClassNode.

  - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `protected static ClassNode` | `NO_CLASS` | Internal helper used to indicate a cache hit for a class that does not exist.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `cacheClass(String name, ClassNode res)` caches a ClassNode
    `` | `public LookupResult` | `findClassNode(String name, CompilationUnit compilationUnit)` Extension point for custom lookup logic of finding ClassNodes.
    `` | `public ClassNode` | `getFromClassCache(String name)` returns whatever is stored in the class cache for the given name
    `` | `public LookupResult` | `resolveName(String name, CompilationUnit compilationUnit)` Resolves the name of a class to a SourceUnit or ClassNode.
    `` | `public void` | `setRedirect(ClassNode cn)`

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll`

- - ### Field Detail

    - #### protected static final ClassNode NO_CLASS

      Internal helper used to indicate a cache hit for a class that does not exist. This way further lookups through a slow findClassNode(String, CompilationUnit) path can be avoided. WARNING: This class is not to be used outside of ClassNodeResolver.

  - ### Method Detail

    - #### public void cacheClass(String name, ClassNode res)

      caches a ClassNode

      Parameters:
        `name` - - the name of the class
        `res` - - the ClassNode for that name

    - #### public LookupResult findClassNode(String name, CompilationUnit compilationUnit)

      Extension point for custom lookup logic of finding ClassNodes. Per default this will use the CompilationUnit class loader to do a lookup on the class path and load the needed class using that loader. Or if a script is found and that script is seen as "newer", the script will be used instead of the class.

      Parameters:
        `name` - - the name of the class
        `compilationUnit` - - the current compilation unit
      Returns:
        the lookup result

    - #### public ClassNode getFromClassCache(String name)

      returns whatever is stored in the class cache for the given name

      Parameters:
        `name` - - the name of the class
      Returns:
        the result of the lookup, which may be null

    - #### public LookupResult resolveName(String name, CompilationUnit compilationUnit)

      Resolves the name of a class to a SourceUnit or ClassNode. If no class or source is found this method returns null. A lookup is done by first asking the cache if there is an entry for the class already available to then call findClassNode(String, CompilationUnit). The result of that method call will be cached if a ClassNode is found. If a SourceUnit is found, this method will not be asked later on again for that class, because ResolveVisitor will first ask the CompilationUnit for classes in the compilation queue and it will find the class for that SourceUnit there then. method return a ClassNode instead of a SourceUnit, the res

      Parameters:
        `name` - - the name of the class
        `compilationUnit` - - the current CompilationUnit
      Returns:
        the LookupResult

    - #### @Override public void setRedirect(ClassNode cn)