|
Web Site | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.codehaus.janino.Cookable
org.codehaus.janino.SimpleCompiler
public class SimpleCompiler
A simplified version of Compiler
that can compile only a single
compilation unit. (A "compilation unit" is the characters stored in a
".java" file.)
Opposed to a normal ".java" file, you can declare multiple public classes here.
To set up a SimpleCompiler
object, proceed as follows:
SimpleCompiler
using SimpleCompiler()
setParentClassLoader(ClassLoader)
.
Cookable.cook(Scanner)
methods to scan,
parse, compile and load the compilation unit into the JVM.
Field Summary | |
---|---|
static ClassLoader |
BOOT_CLASS_LOADER
A ClassLoader that finds the classes on the JVM's boot class path (e.g. |
Constructor Summary | |
---|---|
SimpleCompiler()
|
|
SimpleCompiler(Scanner scanner,
ClassLoader optionalParentClassLoader)
Equivalent to SimpleCompiler sc = new SimpleCompiler(); sc.setParentClassLoader(optionalParentClassLoader); sc.cook(scanner); |
|
SimpleCompiler(String fileName)
Equivalent to SimpleCompiler sc = new SimpleCompiler(); sc.cook(fileName); |
|
SimpleCompiler(String optionalFileName,
InputStream is)
Equivalent to SimpleCompiler sc = new SimpleCompiler(); sc.cook(optionalFileName, is); |
|
SimpleCompiler(String optionalFileName,
Reader in)
Equivalent to SimpleCompiler sc = new SimpleCompiler(); sc.cook(optionalFileName, in); |
Method Summary | |
---|---|
protected void |
assertNotCooked()
Throw an IllegalStateException if this Cookable is already cooked. |
protected Java.Type[] |
classesToTypes(Location location,
Class[] classes)
Convert an array of Class es into an array ofJava.Type s. |
protected Java.Type |
classToType(Location location,
Class optionalClass)
Wrap a reflection Class in a Java.Type object. |
protected ClassLoader |
compileToClassLoader(Java.CompilationUnit compilationUnit,
EnumeratorSet debuggingInformation)
Compile the given compilation unit. |
void |
cook(Scanner scanner)
To be implemented by the derived classes. |
boolean |
equals(Object o)
Two SimpleCompiler 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)
|
ClassLoader |
getClassLoader()
Returns a ClassLoader object through which the previously compiled classes can
be accessed. |
int |
hashCode()
|
static void |
main(String[] args)
|
void |
setParentClassLoader(ClassLoader optionalParentClassLoader)
The "parent class loader" is used to load referenced classes. |
void |
setParentClassLoader(ClassLoader optionalParentClassLoader,
Class[] auxiliaryClasses)
Allowe references to the classes loaded through this parent class loader (@see setParentClassLoader(ClassLoader) ), plus the extra
auxiliaryClasses . |
protected void |
setUpClassLoaders()
Initializes classLoader and iClassLoader from the configured
parentClassLoader and optionalAuxiliaryClasses . |
Methods inherited from class org.codehaus.janino.Cookable |
---|
cook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final ClassLoader BOOT_CLASS_LOADER
ClassLoader
that finds the classes on the JVM's boot class path (e.g.
java.io.*
), but not the classes on the JVM's class path.
Constructor Detail |
---|
public SimpleCompiler(String optionalFileName, Reader in) throws IOException, Scanner.ScanException, Parser.ParseException, CompileException
SimpleCompiler sc = new SimpleCompiler(); sc.cook(optionalFileName, in);
IOException
Scanner.ScanException
Parser.ParseException
CompileException
SimpleCompiler()
,
Cookable.cook(String, Reader)
public SimpleCompiler(String optionalFileName, InputStream is) throws IOException, Scanner.ScanException, Parser.ParseException, CompileException
SimpleCompiler sc = new SimpleCompiler(); sc.cook(optionalFileName, is);
IOException
Scanner.ScanException
Parser.ParseException
CompileException
SimpleCompiler()
,
Cookable.cook(String, InputStream)
public SimpleCompiler(String fileName) throws IOException, Scanner.ScanException, Parser.ParseException, CompileException
SimpleCompiler sc = new SimpleCompiler(); sc.cook(fileName);
IOException
Scanner.ScanException
Parser.ParseException
CompileException
SimpleCompiler()
,
Cookable.cookFile(String)
public SimpleCompiler(Scanner scanner, ClassLoader optionalParentClassLoader) throws IOException, Scanner.ScanException, Parser.ParseException, CompileException
SimpleCompiler sc = new SimpleCompiler(); sc.setParentClassLoader(optionalParentClassLoader); sc.cook(scanner);
IOException
Scanner.ScanException
Parser.ParseException
CompileException
SimpleCompiler()
,
setParentClassLoader(ClassLoader)
,
Cookable.cook(Scanner)
public SimpleCompiler()
Method Detail |
---|
public static void main(String[] args) throws Exception
Exception
public void setParentClassLoader(ClassLoader optionalParentClassLoader)
System.getSystemClassLoader() |
The running JVM's class path |
Thread.currentThread().getContextClassLoader() or null |
The class loader effective for the invoking thread |
BOOT_CLASS_LOADER |
The running JVM's boot class path |
public void setParentClassLoader(ClassLoader optionalParentClassLoader, Class[] auxiliaryClasses)
setParentClassLoader(ClassLoader)
), plus the extra
auxiliaryClasses
.
Notice that the auxiliaryClasses
must either be loadable through the
optionalParentClassLoader
(in which case they have no effect), or
no class with the same name must be loadable through the
optionalParentClassLoader
.
public void cook(Scanner scanner) throws CompileException, Parser.ParseException, Scanner.ScanException, IOException
Cookable
cook
in class Cookable
CompileException
Parser.ParseException
Scanner.ScanException
IOException
protected final void setUpClassLoaders()
classLoader
and iClassLoader
from the configured
parentClassLoader
and optionalAuxiliaryClasses
. These are needed by
classToType(Location, Class)
and friends which are used when creating the AST.
public ClassLoader getClassLoader()
ClassLoader
object through which the previously compiled classes can
be accessed. This ClassLoader
can be used for subsequent calls to
SimpleCompiler(Scanner, ClassLoader)
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 cook(Scanner)
.
This method must not be called for instances of derived classes.
public boolean equals(Object o)
SimpleCompiler
s are regarded equal iff
ScriptEvaluator
s)
ByteArrayClassLoader.equals(Object)
equals
in class Object
public int hashCode()
hashCode
in class Object
protected Java.Type classToType(Location location, Class optionalClass)
Class
in a Java.Type
object.
protected Java.Type[] classesToTypes(Location location, Class[] classes)
Class
es into an array ofJava.Type
s.
protected final ClassLoader compileToClassLoader(Java.CompilationUnit compilationUnit, EnumeratorSet debuggingInformation) throws CompileException
compilationUnit
- The parsed compilation unitdebuggingInformation
- What kind of debugging information to generate in the class file
ClassLoader
into which the compiled classes were defined
CompileException
protected void assertNotCooked()
IllegalStateException
if this Cookable
is already cooked.
|
Web Site | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |