public class ClassNodeResolver extends Object
CompilationUnit
using
CompilationUnit.setClassNodeResolver(ClassNodeResolver)
. 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 ClassNodeResolver.LookupResult
. This class provides a
class cache to cache lookups. If you don't want this, you have to override
the methods cacheClass(String, ClassNode)
and
getFromClassCache(String)
. Custom lookup logic is
supposed to go into the method
findClassNode(String, CompilationUnit)
while the
entry method is resolveName(String, CompilationUnit)
Modifier and Type | Class and Description |
---|---|
static class |
ClassNodeResolver.LookupResult
Helper class to return either a SourceUnit or ClassNode.
|
Modifier and Type | Field and Description |
---|---|
protected static ClassNode |
NO_CLASS
Internal helper used to indicate a cache hit for a class that does not exist.
|
Constructor and Description |
---|
ClassNodeResolver() |
Modifier and Type | Method and Description |
---|---|
void |
cacheClass(String name,
ClassNode res)
caches a ClassNode
|
ClassNodeResolver.LookupResult |
findClassNode(String name,
CompilationUnit compilationUnit)
Extension point for custom lookup logic of finding ClassNodes.
|
ClassNode |
getFromClassCache(String name)
returns whatever is stored in the class cache for the given name
|
ClassNodeResolver.LookupResult |
resolveName(String name,
CompilationUnit compilationUnit)
Resolves the name of a class to a SourceUnit or ClassNode.
|
protected static final ClassNode NO_CLASS
findClassNode(String, CompilationUnit)
path can be avoided.
WARNING: This class is not to be used outside of ClassNodeResolver.public ClassNodeResolver.LookupResult resolveName(String name, CompilationUnit compilationUnit)
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 resname
- - the name of the classcompilationUnit
- - the current CompilationUnitpublic void cacheClass(String name, ClassNode res)
name
- - the name of the classres
- - the ClassNode for that namepublic ClassNode getFromClassCache(String name)
name
- - the name of the classpublic ClassNodeResolver.LookupResult findClassNode(String name, CompilationUnit compilationUnit)
name
- - the name of the classcompilationUnit
- - the current compilation unit