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 LookupResult. This class provides a
class cache to cache lookups. If you don't want this, you have to override
the methods ClassNodeResolver#cacheClass(String, ClassNode) and
ClassNodeResolver#getFromClassCache(String). Custom lookup logic is
supposed to go into the method
ClassNodeResolver#findClassNode(String, CompilationUnit) while the
entry method is ClassNodeResolver#resolveName(String, CompilationUnit)
| Modifier and Type | Class and Description |
|---|---|
| public static class | ClassNodeResolver.LookupResult
Helper class to return either a SourceUnit or ClassNode. |
| Modifier and Type | Field and Description |
|---|---|
| private final Map | |
| protected static final ClassNode | NO_CLASS
Internal helper used to indicate a cache hit for a class that does not exist. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | cacheClass(String
- the name of the class name, ClassNode - the ClassNode for that name res)caches a ClassNode |
| private static ClassNodeResolver. | findByClassLoading(String name, CompilationUnit compilationUnit, GroovyClassLoader loader)
Search for classes using class loading |
| public ClassNodeResolver. | Returns: the lookup result- the name of the class name, CompilationUnit - the current compilation unit compilationUnit)Extension point for custom lookup logic of finding ClassNodes. |
| private ClassNodeResolver. | findDecompiled(String name, CompilationUnit compilationUnit, GroovyClassLoader loader)
Search for classes using ASM decompiler |
| public ClassNode | Returns: the result of the lookup, which may be null- the name of the class name)returns whatever is stored in the class cache for the given name |
| private static long | |
| private static boolean | |
| private static boolean | isSourceNewer(URL source, ClassNode cls)
returns true if the source in URL is newer than the class NOTE: copied from GroovyClassLoader |
| public ClassNodeResolver. | Returns: the LookupResult- the name of the class name, CompilationUnit - the current CompilationUnit compilationUnit)Resolves the name of a class to a SourceUnit or ClassNode. |
| private ClassNodeResolver. | tryAsLoaderClassOrScript(String name, CompilationUnit compilationUnit)
This method is used to realize the lookup of a class using the compilation unit class loader. |
| private static ClassNodeResolver. | tryAsScript(String name, CompilationUnit compilationUnit, ClassNode oldClass)
try to find a script using the compilation unit class loader. |
| cachedClasses | back to summary |
|---|---|
| private final Map<String, ClassNode> cachedClasses | |
| NO_CLASS | back to summary |
|---|---|
| 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 Warning This class is not to be used outside of ClassNodeResolver. | |
| ClassNodeResolver | back to summary |
|---|---|
| public ClassNodeResolver() | |
| cacheClass | back to summary |
|---|---|
| public void cacheClass(String name, ClassNode res) caches a ClassNode | |
| findByClassLoading | back to summary |
|---|---|
| private static ClassNodeResolver. Search for classes using class loading | |
| findClassNode | back to summary |
|---|---|
| public ClassNodeResolver. 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.
| |
| findDecompiled | back to summary |
|---|---|
| private ClassNodeResolver. Search for classes using ASM decompiler | |
| getFromClassCache | back to summary |
|---|---|
| public ClassNode getFromClassCache(String name) returns whatever is stored in the class cache for the given name | |
| getTimeStamp | back to summary |
|---|---|
| private static long getTimeStamp(ClassNode cls) get the time stamp of a class NOTE: copied from GroovyClassLoader | |
| isFromAnotherClassLoader | back to summary |
|---|---|
| private static boolean isFromAnotherClassLoader(GroovyClassLoader loader, String fileName) | |
| isSourceNewer | back to summary |
|---|---|
| private static boolean isSourceNewer(URL source, ClassNode cls) returns true if the source in URL is newer than the class NOTE: copied from GroovyClassLoader | |
| resolveName | back to summary |
|---|---|
| public ClassNodeResolver. 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
| |
| tryAsLoaderClassOrScript | back to summary |
|---|---|
| private ClassNodeResolver. This method is used to realize the lookup of a class using the compilation unit class loader. Should no class be found we fall back to a script lookup. If a class is found we check if there is also a script and maybe use that one in case it is newer. Two class search strategies are possible: by ASM decompilation or by usual Java classloading. The latter is slower but is unavoidable for scripts executed in dynamic environments where the referenced classes might only be available in the classloader, not on disk. | |
| tryAsScript | back to summary |
|---|---|
| private static ClassNodeResolver. try to find a script using the compilation unit class loader. | |
| Modifier and Type | Field and Description |
|---|---|
| private final ClassNode | |
| private final SourceUnit |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public ClassNode | |
| public SourceUnit | |
| public boolean | |
| public boolean |
| cn | back to summary |
|---|---|
| private final ClassNode cn | |
| su | back to summary |
|---|---|
| private final SourceUnit su | |
| LookupResult | back to summary |
|---|---|
| public LookupResult(SourceUnit su, ClassNode cn) creates a new LookupResult. You are not supposed to supply a SourceUnit and a ClassNode at the same time | |
| getClassNode | back to summary |
|---|---|
| public ClassNode getClassNode() returns the ClassNode | |
| getSourceUnit | back to summary |
|---|---|
| public SourceUnit getSourceUnit() returns the SourceUnit | |
| isClassNode | back to summary |
|---|---|
| public boolean isClassNode() returns true if a ClassNode is stored | |
| isSourceUnit | back to summary |
|---|---|
| public boolean isSourceUnit() returns true if a SourecUnit is stored | |