Class SimpleCompiler
- java.lang.Object
-
- org.codehaus.commons.compiler.Cookable
-
- org.codehaus.commons.compiler.jdk.SimpleCompiler
-
- All Implemented Interfaces:
ICookable
,ISimpleCompiler
- Direct Known Subclasses:
ClassBodyEvaluator
public class SimpleCompiler extends Cookable implements ISimpleCompiler
The JDK-based implementation ofISimpleCompiler
.
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
debugLines
private boolean
debugSource
private boolean
debugVars
private ErrorHandler
optionalCompileErrorHandler
private WarningHandler
optionalWarningHandler
private java.lang.ClassLoader
parentClassLoader
private java.lang.ClassLoader
result
-
Fields inherited from interface org.codehaus.commons.compiler.ICookable
BOOT_CLASS_LOADER, SYSTEM_PROPERTY_SOURCE_DEBUGGING_DIR, SYSTEM_PROPERTY_SOURCE_DEBUGGING_ENABLE
-
-
Constructor Summary
Constructors Constructor Description SimpleCompiler()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
assertCooked()
Throw anIllegalStateException
if thisCookable
is not yet cooked.protected void
assertNotCooked()
Throw anIllegalStateException
if thisCookable
is already cooked.void
cook(java.lang.String optionalFileName, java.io.Reader r)
Reads, scans, parses and compiles Java tokens from the givenReader
.java.lang.ClassLoader
getClassLoader()
Returns aClassLoader
object through which the previously compiled classes can be accessed.void
setCompileErrorHandler(ErrorHandler optionalCompileErrorHandler)
By default,CompileException
s are thrown on compile errors, but an application my install its ownErrorHandler
.void
setDebuggingInformation(boolean debugSource, boolean debugLines, boolean debugVars)
Determines what kind of debugging information is included in the generates classes.void
setParentClassLoader(java.lang.ClassLoader optionalParentClassLoader)
The "parent class loader" is used to load referenced classes.void
setParentClassLoader(java.lang.ClassLoader optionalParentClassLoader, java.lang.Class<?>[] auxiliaryClasses)
Deprecated.Auxiliary classes never really worked...void
setWarningHandler(WarningHandler optionalWarningHandler)
By default, warnings are discarded, but an application my install a customWarningHandler
.-
Methods inherited from class org.codehaus.commons.compiler.Cookable
cook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile, readString
-
-
-
-
Field Detail
-
parentClassLoader
private java.lang.ClassLoader parentClassLoader
-
result
private java.lang.ClassLoader result
-
debugSource
private boolean debugSource
-
debugLines
private boolean debugLines
-
debugVars
private boolean debugVars
-
optionalCompileErrorHandler
private ErrorHandler optionalCompileErrorHandler
-
optionalWarningHandler
private WarningHandler optionalWarningHandler
-
-
Method Detail
-
getClassLoader
public java.lang.ClassLoader 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
-
cook
public void cook(java.lang.String optionalFileName, java.io.Reader r) throws CompileException, java.io.IOException
Description copied from interface:ICookable
Reads, scans, parses and compiles Java tokens from the givenReader
.- Specified by:
cook
in interfaceICookable
- Specified by:
cook
in classCookable
- Parameters:
optionalFileName
- Used when reporting errors and warnings.- Throws:
CompileException
java.io.IOException
- See Also:
ICookable.cook(String, Reader)
-
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
-
setParentClassLoader
public void setParentClassLoader(java.lang.ClassLoader optionalParentClassLoader)
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
-
setParentClassLoader
@Deprecated public void setParentClassLoader(java.lang.ClassLoader optionalParentClassLoader, java.lang.Class<?>[] auxiliaryClasses)
Deprecated.Auxiliary classes never really worked... don't use them.
-
setCompileErrorHandler
public void setCompileErrorHandler(ErrorHandler optionalCompileErrorHandler)
Description copied from interface:ICookable
By default,CompileException
s are thrown on compile errors, but an application my install its ownErrorHandler
.Be aware that a single problem during compilation often causes a bunch of compile errors, so a good
ErrorHandler
counts errors and throws aCompileException
when a limit is reached.If the given
ErrorHandler
throwsCompileException
s, then the compilation is terminated and the exception is propagated.If the given
ErrorHandler
does not throwCompileException
s, then the compiler may or may not continue compilation, but must eventually throw aCompileException
.In other words: The
ErrorHandler
may throw aCompileException
or not, but the compiler must definitely throw aCompileException
if one or more compile errors have occurred.- Specified by:
setCompileErrorHandler
in interfaceICookable
- Parameters:
optionalCompileErrorHandler
-null
to restore the default behavior (throwing aCompileException
-
setWarningHandler
public void setWarningHandler(WarningHandler optionalWarningHandler)
Description copied from interface:ICookable
By default, warnings are discarded, but an application my install a customWarningHandler
.- Specified by:
setWarningHandler
in interfaceICookable
- Parameters:
optionalWarningHandler
-null
to indicate that no warnings be issued
-
assertCooked
protected void assertCooked()
Throw anIllegalStateException
if thisCookable
is not yet cooked.
-
assertNotCooked
protected void assertNotCooked()
Throw anIllegalStateException
if thisCookable
is already cooked.
-
-