Package org.codehaus.janino
Class Compiler.CompilerIClassLoader
- java.lang.Object
-
- org.codehaus.janino.IClassLoader
-
- org.codehaus.janino.Compiler.CompilerIClassLoader
-
- Enclosing class:
- Compiler
private class Compiler.CompilerIClassLoader extends IClassLoader
A specializedIClassLoader
that loadsIClass
es from the following sources:- An already-parsed compilation unit
- A class file in the output directory (if existant and younger than source file)
- A source file in any of the source path directories
- The parent class loader
Compiler.CompilerIClassLoader
is an inner class ofCompiler
and heavily usesCompiler
's members.
-
-
Field Summary
Fields Modifier and Type Field Description private ResourceFinder
sourceFinder
-
Fields inherited from class org.codehaus.janino.IClassLoader
ANNO_java_lang_Override, CTOR_java_lang_StringBuilder__java_lang_String, METH_java_lang_Iterable__iterator, METH_java_lang_String__concat__java_lang_String, METH_java_lang_String__valueOf__boolean, METH_java_lang_String__valueOf__char, METH_java_lang_String__valueOf__double, METH_java_lang_String__valueOf__float, METH_java_lang_String__valueOf__int, METH_java_lang_String__valueOf__java_lang_Object, METH_java_lang_String__valueOf__long, METH_java_lang_StringBuilder__append__java_lang_String, METH_java_lang_StringBuilder__toString, METH_java_util_Iterator__hasNext, METH_java_util_Iterator__next, TYPE_java_io_Serializable, TYPE_java_lang_AssertionError, TYPE_java_lang_Boolean, TYPE_java_lang_Byte, TYPE_java_lang_Character, TYPE_java_lang_Class, TYPE_java_lang_Cloneable, TYPE_java_lang_Double, TYPE_java_lang_Error, TYPE_java_lang_Exception, TYPE_java_lang_Float, TYPE_java_lang_Integer, TYPE_java_lang_Iterable, TYPE_java_lang_Long, TYPE_java_lang_Object, TYPE_java_lang_RuntimeException, TYPE_java_lang_Short, TYPE_java_lang_String, TYPE_java_lang_StringBuilder, TYPE_java_lang_Throwable, TYPE_java_util_Iterator
-
-
Constructor Summary
Constructors Constructor Description CompilerIClassLoader(ResourceFinder sourceFinder, IClassLoader optionalParentIClassLoader)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private IClass
defineIClassFromClassFileResource(Resource classFileResource)
Open the givenclassFileResource
, read its contents, define it in theIClassLoader
, and resolve it (this step may involve loading more classes).private IClass
defineIClassFromSourceResource(Resource sourceResource, java.lang.String className)
Parse the compilation unit stored in the givensourceResource
, remember it inCompiler.this.parsedCompilationUnits
(it may declare other classes that are needed later), find the declaration of the type with the givenclassName
, and define it in theIClassLoader
.protected IClass
findIClass(java.lang.String type)
-
Methods inherited from class org.codehaus.janino.IClassLoader
createJavacLikePathIClassLoader, defineIClass, loadIClass, postConstruct
-
-
-
-
Field Detail
-
sourceFinder
private final ResourceFinder sourceFinder
-
-
Constructor Detail
-
CompilerIClassLoader
public CompilerIClassLoader(ResourceFinder sourceFinder, IClassLoader optionalParentIClassLoader)
- Parameters:
sourceFinder
- Where to look for source filesoptionalParentIClassLoader
-IClassLoader
through whichIClass
es are to be loaded
-
-
Method Detail
-
findIClass
protected IClass findIClass(java.lang.String type) throws java.lang.ClassNotFoundException
Description copied from class:IClassLoader
Find a newIClass
by descriptor; returnnull
if a class for thatdescriptor
could not be found.Similar
ClassLoader.findClass(java.lang.String)
, this method must- Get an
IClass
object from somewhere for the given type - Call
IClassLoader.defineIClass(IClass)
with thatIClass
object as the argument - Return the
IClass
object
The format of a
descriptor
is defined in JVMS 4.3.2. Typical descriptors are:I
(Integer)Lpkg1/pkg2/Cls;
(Class declared in package)Lpkg1/pkg2/Outer$Inner;
Member class
Notice that this method is never called from more than one thread at a time. In other words, implementations of this method need not be synchronized.
- Specified by:
findIClass
in classIClassLoader
- Parameters:
type
- field descriptor of the to load, e.g. "Lpkg1/pkg2/Outer$Inner;"- Returns:
null
if a the type could not be found- Throws:
java.lang.ClassNotFoundException
- if an exception was raised while loading theIClass
- Get an
-
defineIClassFromSourceResource
private IClass defineIClassFromSourceResource(Resource sourceResource, java.lang.String className) throws java.lang.ClassNotFoundException
Parse the compilation unit stored in the givensourceResource
, remember it inCompiler.this.parsedCompilationUnits
(it may declare other classes that are needed later), find the declaration of the type with the givenclassName
, and define it in theIClassLoader
.Notice that the CU is not compiled here!
- Throws:
java.lang.ClassNotFoundException
-
defineIClassFromClassFileResource
private IClass defineIClassFromClassFileResource(Resource classFileResource) throws java.lang.ClassNotFoundException
Open the givenclassFileResource
, read its contents, define it in theIClassLoader
, and resolve it (this step may involve loading more classes).- Throws:
java.lang.ClassNotFoundException
-
-