groovy.lang
Class ClassCollector

Field Summary
 GroovyClassLoader cl
           
 Class generatedClass
           
 Collection loadedClasses
           
 SourceUnit su
           
 CompilationUnit unit
           
 
Constructor Summary
ClassCollector(InnerLoader cl, CompilationUnit unit, SourceUnit su)
           
 
Method Summary
void addClasspath(String path)
           adds a classpath to this classloader.
void addURL(URL url)
           adds a URL to the classloader.
void call(ClassVisitor classWriter, ClassNode classNode)
          
void clearCache()
           removes all classes from the class cache.
Class createClass(def code, ClassNode classNode)
          
String decodeFileName(String fileName)
          
Class defineClass(String name, def b)
           open up the super class define that takes raw bytes
Class getClassCacheEntry(String name)
           gets a class from the class cache.
GroovyClassLoader getDefiningClassLoader()
          
Collection getLoadedClasses()
          
def getLoadedClasses()
          

Returns all Groovy classes loaded by this class loader.

URL getSourceFile(String name)
          
long getTimeStamp(Class cls)
           gets the time stamp of a given class.
boolean isRecompilable(Class cls)
           Indicates if a class is recompilable.
Boolean isShouldRecompile()
           gets the currently set recompilation mode. null means, the compiler configuration is used.
boolean isSourceNewer(URL source, Class cls)
           Decides if the given source is newer than a class.
Class loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript)
           loads a class from a file or a parent classloader.
Class loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve)
           loads a class from a file or a parent classloader.
Class loadClass(String name, boolean resolve)
           Implemented here to check package access prior to returning an already loaded class.
Class onClassNode(ClassWriter classWriter, ClassNode classNode)
          
Class recompile(URL source, String className, Class oldClass)
           (Re)Compiles the given source.
void removeClassCacheEntry(String name)
           removes a class from the class cache.
void setClassCacheEntry(Class cls)
           sets an entry in the class cache.
void setShouldRecompile(Boolean mode)
           sets if the recompilation should be enable.
 

Constructor Detail

ClassCollector

ClassCollector(InnerLoader cl, CompilationUnit unit, SourceUnit su)


Method Detail

addClasspath

public void addClasspath(String path)
adds a classpath to this classloader.
param:
path is a jar file or a directory.
see:
#addURL(URL)


addURL

public void addURL(URL url)
adds a URL to the classloader.
param:
url the new classpath element


call

public void call(ClassVisitor classWriter, ClassNode classNode)


clearCache

public void clearCache()
removes all classes from the class cache.
see:
#getClassCacheEntry(String)
see:
#setClassCacheEntry(Class)
see:
#removeClassCacheEntry(String)


createClass

Class createClass(def code, ClassNode classNode)


decodeFileName

String decodeFileName(String fileName)


defineClass

public Class defineClass(String name, def b)
open up the super class define that takes raw bytes


getClassCacheEntry

Class getClassCacheEntry(String name)
gets a class from the class cache. This cache contains only classes loaded through this class loader or an InnerLoader instance. If no class is stored for a specific name, then the method should return null.
param:
name of the class
return:
the class stored for the given name
see:
#removeClassCacheEntry(String)
see:
#setClassCacheEntry(Class)
see:
#clearCache()


getDefiningClassLoader

GroovyClassLoader getDefiningClassLoader()


getLoadedClasses

public Collection getLoadedClasses()


getLoadedClasses

public def getLoadedClasses()

Returns all Groovy classes loaded by this class loader.

return:
all classes loaded by this class loader


getSourceFile

URL getSourceFile(String name)


getTimeStamp

long getTimeStamp(Class cls)
gets the time stamp of a given class. For groovy generated classes this usually means to return the value of the static field __timeStamp. If the parameter doesn't have such a field, then Long.MAX_VALUE is returned
param:
cls the class
return:
the time stamp


isRecompilable

boolean isRecompilable(Class cls)
Indicates if a class is recompilable. Recompileable means, that the classloader will try to locate a groovy source file for this class and then compile it again, adding the resulting class as entry to the cache. Giving null as class is like a recompilation, so the method should always return true here. Only classes that are implementing GroovyObject are compileable and only if the timestamp in the class is lower than Long.MAX_VALUE.

NOTE: First the parent loaders will be asked and only if they don't return a class the recompilation will happen. Recompilation also only happen if the source file is newer.

param:
cls the class to be tested. If null the method should return true
return:
true if the class should be compiled again
see:
#isSourceNewer(URL, Class)


isShouldRecompile

public Boolean isShouldRecompile()
gets the currently set recompilation mode. null means, the compiler configuration is used. False means no recompilation and true means that recompilation will be done if needed.
return:
the recompilation mode


isSourceNewer

boolean isSourceNewer(URL source, Class cls)
Decides if the given source is newer than a class.
param:
source the source we may want to compile
param:
cls the former class
return:
true if the source is newer, false else
throws:
IOException if it is not possible to open an
connection for the given source
see:
#getTimeStamp(Class)


loadClass

public Class loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript)
loads a class from a file or a parent classloader. This method does call loadClass(String, boolean, boolean, boolean) with the last parameter set to false.
throws:
CompilationFailedException if compilation was not successful


loadClass

public Class loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve)
loads a class from a file or a parent classloader.
param:
name of the class to be loaded
param:
lookupScriptFiles if false no lookup at files is done at all
param:
preferClassOverScript if true the file lookup is only done if there is no class
param:
resolve @see ClassLoader#loadClass(java.lang.String, boolean)
return:
the class found or the class created from a file lookup
throws:
ClassNotFoundException if the class could not be found
throws:
CompilationFailedException if the source file could not be compiled


loadClass

Class loadClass(String name, boolean resolve)
Implemented here to check package access prior to returning an already loaded class.
throws:
CompilationFailedException if the compilation failed
throws:
ClassNotFoundException if the class was not found
see:
ClassLoader#loadClass


onClassNode

Class onClassNode(ClassWriter classWriter, ClassNode classNode)


recompile

Class recompile(URL source, String className, Class oldClass)
(Re)Compiles the given source. This method starts the compilation of a given source, if the source has changed since the class was created. For this isSourceNewer is called.
param:
source the source pointer for the compilation
param:
className the name of the class to be generated
param:
oldClass a possible former class
return:
the old class if the source wasn't new enough, the new class else
throws:
CompilationFailedException if the compilation failed
throws:
IOException if the source is not readable
see:
#isSourceNewer(URL, Class)


removeClassCacheEntry

void removeClassCacheEntry(String name)
removes a class from the class cache.
param:
name of the class
see:
#getClassCacheEntry(String)
see:
#setClassCacheEntry(Class)
see:
#clearCache()


setClassCacheEntry

void setClassCacheEntry(Class cls)
sets an entry in the class cache.
param:
cls the class
see:
#removeClassCacheEntry(String)
see:
#getClassCacheEntry(String)
see:
#clearCache()


setShouldRecompile

public void setShouldRecompile(Boolean mode)
sets if the recompilation should be enable. There are 3 possible values for this. Any value different than null overrides the value from the compiler configuration. true means to recompile if needed false means to never recompile.
param:
mode the recompilation mode
see:
CompilerConfiguration