public class SimpleCompiler extends Cookable implements ISimpleCompiler
SimpleCompiler object, proceed as described for ISimpleCompiler.
Alternatively, a number of "convenience constructors" exist that execute the described steps
instantly.| Modifier and Type | Field and Description |
|---|---|
private ClassLoaderIClassLoader |
classLoaderIClassLoader |
private static boolean |
DEBUG |
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 |
BOOT_CLASS_LOADER, SYSTEM_PROPERTY_SOURCE_DEBUGGING_DIR, SYSTEM_PROPERTY_SOURCE_DEBUGGING_ENABLE| Constructor and Description |
|---|
SimpleCompiler() |
SimpleCompiler(Scanner scanner,
java.lang.ClassLoader optionalParentClassLoader)
Equivalent to
|
SimpleCompiler(java.lang.String fileName)
Equivalent to
|
SimpleCompiler(java.lang.String optionalFileName,
java.io.InputStream is)
Equivalent to
|
SimpleCompiler(java.lang.String optionalFileName,
java.io.Reader in)
Equivalent to
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
assertNotCooked() |
protected Java.Type[] |
classesToTypes(Location location,
java.lang.Class[] classes)
Converts an array of
Classes into an array ofJava.Types. |
protected Java.Type |
classToType(Location location,
java.lang.Class clazz)
Wraps a reflection
Class in a Java.Type object. |
protected java.lang.ClassLoader |
compileToClassLoader(Java.CompilationUnit compilationUnit)
Compile the given compilation unit.
|
void |
cook(Java.CompilationUnit compilationUnit)
Cooks this compilation unit directly.
|
void |
cook(Scanner scanner)
Scans, parses and ompiles a given compilation unit from the given scanner.
|
void |
cook(java.lang.String optionalFileName,
java.io.Reader r)
Scans, parses and compiles a given compilation unit from the given
Reader. |
boolean |
equals(java.lang.Object o)
Two
SimpleCompilers are regarded equal iff
Both are objects of the same class (e.g. |
java.lang.ClassLoader |
getClassLoader()
Returns a
ClassLoader object through which the previously compiled classes can be accessed. |
int |
hashCode() |
static void |
main(java.lang.String[] args) |
void |
setCompileErrorHandler(ErrorHandler optionalCompileErrorHandler)
By default,
CompileExceptions are thrown on compile errors, but an application my install its own
ErrorHandler. |
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 |
setWarningHandler(WarningHandler optionalWarningHandler)
By default, warnings are discarded, but an application my install a custom
WarningHandler. |
cook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile, readStringprivate static final boolean DEBUG
private java.lang.ClassLoader parentClassLoader
private ClassLoaderIClassLoader classLoaderIClassLoader
private java.lang.ClassLoader result
private ErrorHandler optionalCompileErrorHandler
private WarningHandler optionalWarningHandler
private boolean debugSource
private boolean debugLines
private boolean debugVars
public SimpleCompiler(java.lang.String optionalFileName,
java.io.Reader in)
throws java.io.IOException,
CompileException
SimpleCompiler sc = new SimpleCompiler(); sc.cook(optionalFileName, in);
java.io.IOExceptionCompileExceptionSimpleCompiler(),
Cookable.cook(String, Reader)public SimpleCompiler(java.lang.String optionalFileName,
java.io.InputStream is)
throws java.io.IOException,
CompileException
SimpleCompiler sc = new SimpleCompiler(); sc.cook(optionalFileName, is);
java.io.IOExceptionCompileExceptionSimpleCompiler(),
Cookable.cook(String, InputStream)public SimpleCompiler(java.lang.String fileName)
throws java.io.IOException,
CompileException
SimpleCompiler sc = new SimpleCompiler(); sc.cook(fileName);
java.io.IOExceptionCompileExceptionSimpleCompiler(),
Cookable.cookFile(String)public SimpleCompiler(Scanner scanner, java.lang.ClassLoader optionalParentClassLoader) throws java.io.IOException, CompileException
SimpleCompiler sc = new SimpleCompiler(); sc.setParentClassLoader(optionalParentClassLoader); sc.cook(scanner);
java.io.IOExceptionCompileExceptionSimpleCompiler(),
setParentClassLoader(ClassLoader),
Cookable.cook(Reader)public SimpleCompiler()
public static void main(java.lang.String[] args)
throws java.lang.Exception
java.lang.Exceptionpublic void setParentClassLoader(java.lang.ClassLoader optionalParentClassLoader)
ICookableSystem.getSystemClassLoader() |
The running JVM's class path |
Thread.currentThread().getContextClassLoader() or null |
The class loader effective for the invoking thread |
ICookable.BOOT_CLASS_LOADER |
The running JVM's boot class path |
setParentClassLoader in interface ICookablepublic void setDebuggingInformation(boolean debugSource,
boolean debugLines,
boolean debugVars)
ICookablesetDebuggingInformation in interface ICookablepublic final void cook(java.lang.String optionalFileName,
java.io.Reader r)
throws CompileException,
java.io.IOException
Reader. After completion, getClassLoader() returns a ClassLoader that allows for access to the compiled classes.cook in interface ICookablecook in class CookableoptionalFileName - Used when reporting errors and warnings.CompileExceptionjava.io.IOExceptionICookable.cook(String, Reader)public void cook(Scanner scanner) throws CompileException, java.io.IOException
getClassLoader() returns a ClassLoader that allows for access to the compiled classes.CompileExceptionjava.io.IOExceptionpublic void cook(Java.CompilationUnit compilationUnit) throws CompileException
CompileExceptionCookable.cook(Reader)public java.lang.ClassLoader getClassLoader()
ISimpleCompilerClassLoader object through which the previously compiled classes can be accessed. This ClassLoader can be used for subsequent ISimpleCompilers 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.
getClassLoader in interface ISimpleCompilerpublic boolean equals(java.lang.Object o)
SimpleCompilers are regarded equal iff
ScriptEvaluators)
Object.equals(Object)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic void setCompileErrorHandler(ErrorHandler optionalCompileErrorHandler)
ICookableCompileExceptions are thrown on compile errors, but an application my install its own
ErrorHandler.
Be aware that a single problem during compilation often causes a bunch of compile errors, so a good ErrorHandler counts errors and throws a CompileException when a limit is reached.
If the given ErrorHandler throws CompileExceptions, then the compilation is terminated and
the exception is propagated.
If the given ErrorHandler does not throw CompileExceptions, then the compiler may or may not
continue compilation, but must eventually throw a CompileException.
In other words: The ErrorHandler may throw a CompileException or not, but the compiler must
definitely throw a CompileException if one or more compile errors have occurred.
setCompileErrorHandler in interface ICookableoptionalCompileErrorHandler - null to restore the default behavior (throwing a CompileExceptionpublic void setWarningHandler(WarningHandler optionalWarningHandler)
ICookableWarningHandler.setWarningHandler in interface ICookableoptionalWarningHandler - null to indicate that no warnings be issuedprotected Java.Type classToType(Location location, java.lang.Class clazz)
Class in a Java.Type object.protected Java.Type[] classesToTypes(Location location, java.lang.Class[] classes)
Classes into an array ofJava.Types.protected final java.lang.ClassLoader compileToClassLoader(Java.CompilationUnit compilationUnit) throws CompileException
compilationUnit - The parsed compilation unitClassLoader into which the compiled classes were definedCompileExceptionprotected void assertNotCooked()
java.lang.IllegalStateException - This Cookable is already cooked