Package org.codehaus.janino
Class SimpleCompiler
java.lang.Object
org.codehaus.commons.compiler.Cookable
org.codehaus.janino.SimpleCompiler
- All Implemented Interfaces:
ICookable
,ISimpleCompiler
- Direct Known Subclasses:
ClassBodyEvaluator
To set up a
SimpleCompiler
object, proceed as described for ISimpleCompiler
.
Alternatively, a number of "convenience constructors" exist that execute the described steps
instantly.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected boolean
protected boolean
Fields inherited from interface org.codehaus.commons.compiler.ICookable
BOOT_CLASS_LOADER, SYSTEM_PROPERTY_SOURCE_DEBUGGING_DIR, SYSTEM_PROPERTY_SOURCE_DEBUGGING_ENABLE
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleCompiler
(String fileName) Equivalent toSimpleCompiler
(String optionalFileName, InputStream is) Equivalent toSimpleCompiler
(String optionalFileName, Reader in) Equivalent toSimpleCompiler
(Scanner scanner, ClassLoader optionalParentClassLoader) Equivalent to -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Throw anIllegalStateException
if thisCookable
is already cooked.protected Java.Type[]
classesToTypes
(Location location, Class[] classes) protected Java.Type
classToType
(Location location, Class clazz) protected final ClassLoader
compileToClassLoader
(Java.CompilationUnit compilationUnit) Compile the given compilation unit.final void
Scans, parses and compiles a given compilation unit from the givenReader
.void
cook
(Java.CompilationUnit compilationUnit) Cook this compilation unit directly.void
Scans, parses and ompiles a given compilation unit from the given scanner.boolean
TwoSimpleCompiler
s are regarded equal iff Both are objects of the same class (e.g.Returns aClassLoader
object through which the previously compiled classes can be accessed.int
hashCode()
static void
void
setDebuggingInformation
(boolean debugSource, boolean debugLines, boolean debugVars) Determines what kind of debugging information is included in the generates classes.void
setParentClassLoader
(ClassLoader optionalParentClassLoader) The "parent class loader" is used to load referenced classes.Methods inherited from class org.codehaus.commons.compiler.Cookable
cook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile, readString
-
Field Details
-
debugSource
protected boolean debugSource -
debugLines
protected boolean debugLines -
debugVars
protected boolean debugVars
-
-
Constructor Details
-
SimpleCompiler
Equivalent toSimpleCompiler sc = new SimpleCompiler(); sc.cook(optionalFileName, in);
- Throws:
IOException
CompileException
- See Also:
-
SimpleCompiler
Equivalent toSimpleCompiler sc = new SimpleCompiler(); sc.cook(optionalFileName, is);
- Throws:
IOException
CompileException
- See Also:
-
SimpleCompiler
Equivalent toSimpleCompiler sc = new SimpleCompiler(); sc.cook(fileName);
- Throws:
IOException
CompileException
- See Also:
-
SimpleCompiler
public SimpleCompiler(Scanner scanner, ClassLoader optionalParentClassLoader) throws IOException, CompileException Equivalent toSimpleCompiler sc = new SimpleCompiler(); sc.setParentClassLoader(optionalParentClassLoader); sc.cook(scanner);
-
SimpleCompiler
public SimpleCompiler()
-
-
Method Details
-
main
- Throws:
Exception
-
setParentClassLoader
Description copied from interface:ICookable
The "parent class loader" is used to load referenced classes. Useful values are:
The parent class loader defaults to the current thread's context class loader.System.getSystemClassLoader()
The running JVM's class path Thread.currentThread().getContextClassLoader()
ornull
The class loader effective for the invoking thread ICookable.BOOT_CLASS_LOADER
The running JVM's boot class path - Specified by:
setParentClassLoader
in interfaceICookable
-
setDebuggingInformation
public void setDebuggingInformation(boolean debugSource, boolean debugLines, boolean debugVars) Description copied from interface:ICookable
Determines what kind of debugging information is included in the generates classes. The default is typically '-g:none', and '-g:all' if the system property 'org.codehaus.janino.source_debugging.enable' is set to 'true'.- Specified by:
setDebuggingInformation
in interfaceICookable
-
cook
Scans, parses and compiles a given compilation unit from the givenReader
. After completion,getClassLoader()
returns aClassLoader
that allows for access to the compiled classes.- Specified by:
cook
in interfaceICookable
- Specified by:
cook
in classCookable
- Parameters:
optionalFileName
- Used when reporting errors and warnings.- Throws:
CompileException
IOException
- See Also:
-
cook
Scans, parses and ompiles a given compilation unit from the given scanner. After completion,getClassLoader()
returns aClassLoader
that allows for access to the compiled classes.- Throws:
CompileException
IOException
-
cook
Cook this compilation unit directly. SeeCookable.cook(java.lang.String, java.io.Reader)
- Throws:
CompileException
-
getClassLoader
Description copied from interface:ISimpleCompiler
Returns aClassLoader
object through which the previously compiled classes can be accessed. ThisClassLoader
can be used for subsequentISimpleCompiler
s in order to compile compilation units that use types (e.g. declare derived types) declared in the previous one.This method must only be called after exactly on of the
ICookable.cook(String, java.io.Reader)
methods was called.- Specified by:
getClassLoader
in interfaceISimpleCompiler
-
equals
TwoSimpleCompiler
s are regarded equal iff- Both are objects of the same class (e.g. both are
ScriptEvaluator
s) - Both generated functionally equal classes as seen by
ByteArrayClassLoader.equals(Object)
- Both are objects of the same class (e.g. both are
-
hashCode
public int hashCode() -
classToType
-
classesToTypes
-
compileToClassLoader
protected final ClassLoader compileToClassLoader(Java.CompilationUnit compilationUnit) throws CompileException Compile the given compilation unit. (A "compilation unit" is typically the contents of a Java™ source file.)- Parameters:
compilationUnit
- The parsed compilation unit- Returns:
- The
ClassLoader
into which the compiled classes were defined - Throws:
CompileException
-
assertNotCooked
protected void assertNotCooked()Throw anIllegalStateException
if thisCookable
is already cooked.
-