Interface ISimpleCompiler
-
- All Superinterfaces:
ICookable
- All Known Implementing Classes:
SimpleCompiler
,SimpleCompiler
public interface ISimpleCompiler extends ICookable
A simplified Java compiler that can compile only a single compilation unit. (A "compilation unit" is the document stored in a ".java" file.)Opposed to a normal ".java" file, you can declare multiple public classes here.
To set up an
ISimpleCompiler
object, proceed as follows:- Create an
ISimpleCompiler
-implementing object - Optionally set an alternate parent class loader through
setParentClassLoader(ClassLoader)
. -
Call any of the
ICookable.cook(String, Reader)
methods to scan, parse, compile and load the compilation unit into the JVM. -
Call
getClassLoader()
to obtain aClassLoader
that you can use to access the compiled classes.
Comptibility notice:
The methods
setPermissions(Permissions permissions)
andvoid setNoPermissions()
were removed in version 3.1.1 (2020-03-09) and replaced by theSandbox
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.ClassLoader
getClassLoader()
Returns aClassLoader
object through which the previously compiled classes can be accessed.void
setCompileErrorHandler(ErrorHandler compileErrorHandler)
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 parentClassLoader)
The "parent class loader" is used to load referenced classes.void
setWarningHandler(WarningHandler warningHandler)
By default, warnings are discarded, but an application my install a customWarningHandler
.
-
-
-
Method Detail
-
setParentClassLoader
void setParentClassLoader(@Nullable java.lang.ClassLoader parentClassLoader)
The "parent class loader" is used to load referenced classes. Useful values are:System.getSystemClassLoader()
The running JVM's class path Thread.currentThread().getContextClassLoader()
ornull
The class loader effective for the invoking thread ClassLoaders.BOOTCLASSPATH_CLASS_LOADER
The running JVM's boot class path The parent class loader defaults to the current thread's context class loader.
-
setDebuggingInformation
void setDebuggingInformation(boolean debugSource, boolean debugLines, boolean debugVars)
Determines what kind of debugging information is included in the generates classes. The default is typically "-g:none
".
-
setCompileErrorHandler
void setCompileErrorHandler(@Nullable ErrorHandler compileErrorHandler)
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.- Parameters:
compileErrorHandler
-null
to restore the default behavior (throwing aCompileException
-
setWarningHandler
void setWarningHandler(@Nullable WarningHandler warningHandler)
By default, warnings are discarded, but an application my install a customWarningHandler
.- Parameters:
warningHandler
-null
to indicate that no warnings be issued
-
getClassLoader
java.lang.ClassLoader getClassLoader()
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 one of the
ICookable.cook(String, java.io.Reader)
methods was called.
-
-