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
public class SimpleCompiler extends Cookable implements ISimpleCompiler
To set up aSimpleCompilerobject, proceed as described forISimpleCompiler. Alternatively, a number of "convenience constructors" exist that execute the described steps instantly.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleandebugLinesprotected booleandebugSourceprotected booleandebugVars-
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()SimpleCompiler(java.lang.String fileName)Equivalent toSimpleCompiler(java.lang.String optionalFileName, java.io.InputStream is)Equivalent toSimpleCompiler(java.lang.String optionalFileName, java.io.Reader in)Equivalent toSimpleCompiler(Scanner scanner, java.lang.ClassLoader optionalParentClassLoader)Equivalent to
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidassertNotCooked()Throw anIllegalStateExceptionif thisCookableis already cooked.protected Java.Type[]classesToTypes(Location location, java.lang.Class[] classes)Convert an array ofClasses into an array ofJava.Types.protected Java.TypeclassToType(Location location, java.lang.Class clazz)Wrap a reflectionClassin aJava.Typeobject.protected java.lang.ClassLoadercompileToClassLoader(Java.CompilationUnit compilationUnit)Compile the given compilation unit.voidcook(java.lang.String optionalFileName, java.io.Reader r)Scans, parses and compiles a given compilation unit from the givenReader.voidcook(Java.CompilationUnit compilationUnit)Cook this compilation unit directly.voidcook(Scanner scanner)Scans, parses and ompiles a given compilation unit from the given scanner.booleanequals(java.lang.Object o)TwoSimpleCompilers are regarded equal iff Both are objects of the same class (e.g.java.lang.ClassLoadergetClassLoader()Returns aClassLoaderobject through which the previously compiled classes can be accessed.inthashCode()static voidmain(java.lang.String[] args)voidsetDebuggingInformation(boolean debugSource, boolean debugLines, boolean debugVars)Determines what kind of debugging information is included in the generates classes.voidsetParentClassLoader(java.lang.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
-
-
-
-
Constructor Detail
-
SimpleCompiler
public SimpleCompiler(java.lang.String optionalFileName, java.io.Reader in) throws java.io.IOException, CompileExceptionEquivalent toSimpleCompiler sc = new SimpleCompiler(); sc.cook(optionalFileName, in);
- Throws:
java.io.IOExceptionCompileException- See Also:
SimpleCompiler(),Cookable.cook(String, Reader)
-
SimpleCompiler
public SimpleCompiler(java.lang.String optionalFileName, java.io.InputStream is) throws java.io.IOException, CompileExceptionEquivalent toSimpleCompiler sc = new SimpleCompiler(); sc.cook(optionalFileName, is);
- Throws:
java.io.IOExceptionCompileException- See Also:
SimpleCompiler(),Cookable.cook(String, InputStream)
-
SimpleCompiler
public SimpleCompiler(java.lang.String fileName) throws java.io.IOException, CompileExceptionEquivalent toSimpleCompiler sc = new SimpleCompiler(); sc.cook(fileName);
- Throws:
java.io.IOExceptionCompileException- See Also:
SimpleCompiler(),Cookable.cookFile(String)
-
SimpleCompiler
public SimpleCompiler(Scanner scanner, java.lang.ClassLoader optionalParentClassLoader) throws java.io.IOException, CompileException
Equivalent toSimpleCompiler sc = new SimpleCompiler(); sc.setParentClassLoader(optionalParentClassLoader); sc.cook(scanner);
- Throws:
java.io.IOExceptionCompileException- See Also:
SimpleCompiler(),setParentClassLoader(ClassLoader),Cookable.cook(Reader)
-
SimpleCompiler
public SimpleCompiler()
-
-
Method Detail
-
main
public static void main(java.lang.String[] args) throws java.lang.Exception- Throws:
java.lang.Exception
-
setParentClassLoader
public void setParentClassLoader(java.lang.ClassLoader optionalParentClassLoader)
Description copied from interface:ICookableThe "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()ornullThe class loader effective for the invoking thread ICookable.BOOT_CLASS_LOADERThe running JVM's boot class path - Specified by:
setParentClassLoaderin interfaceICookable
-
setDebuggingInformation
public void setDebuggingInformation(boolean debugSource, boolean debugLines, boolean debugVars)Description copied from interface:ICookableDetermines 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:
setDebuggingInformationin interfaceICookable
-
cook
public final void cook(java.lang.String optionalFileName, java.io.Reader r) throws CompileException, java.io.IOExceptionScans, parses and compiles a given compilation unit from the givenReader. After completion,getClassLoader()returns aClassLoaderthat allows for access to the compiled classes.- Specified by:
cookin interfaceICookable- Specified by:
cookin classCookable- Parameters:
optionalFileName- Used when reporting errors and warnings.- Throws:
CompileExceptionjava.io.IOException- See Also:
ICookable.cook(String, Reader)
-
cook
public void cook(Scanner scanner) throws CompileException, java.io.IOException
Scans, parses and ompiles a given compilation unit from the given scanner. After completion,getClassLoader()returns aClassLoaderthat allows for access to the compiled classes.- Throws:
CompileExceptionjava.io.IOException
-
cook
public void cook(Java.CompilationUnit compilationUnit) throws CompileException
Cook this compilation unit directly. SeeCookable.cook(java.lang.String, java.io.Reader)- Throws:
CompileException
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
Description copied from interface:ISimpleCompilerReturns aClassLoaderobject through which the previously compiled classes can be accessed. ThisClassLoadercan be used for subsequentISimpleCompilers 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:
getClassLoaderin interfaceISimpleCompiler
-
equals
public boolean equals(java.lang.Object o)
TwoSimpleCompilers are regarded equal iff- Both are objects of the same class (e.g. both are
ScriptEvaluators) - Both generated functionally equal classes as seen by
ByteArrayClassLoader.equals(Object)
- Overrides:
equalsin classjava.lang.Object
- Both are objects of the same class (e.g. both are
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
classToType
protected Java.Type classToType(Location location, java.lang.Class clazz)
Wrap a reflectionClassin aJava.Typeobject.
-
classesToTypes
protected Java.Type[] classesToTypes(Location location, java.lang.Class[] classes)
Convert an array ofClasses into an array ofJava.Types.
-
compileToClassLoader
protected final java.lang.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
ClassLoaderinto which the compiled classes were defined - Throws:
CompileException
-
assertNotCooked
protected void assertNotCooked()
Throw anIllegalStateExceptionif thisCookableis already cooked.
-
-