|
janino.net | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.codehaus.commons.compiler.Cookable
org.codehaus.janino.SimpleCompiler
org.codehaus.janino.ClassBodyEvaluator
public class ClassBodyEvaluator
The optionalClassLoader serves two purposes:
ByteArrayClassLoader, or by creation of a temporary
ByteArrayClassLoader if not.
| Field Summary |
|---|
| Fields inherited from interface org.codehaus.commons.compiler.IClassBodyEvaluator |
|---|
DEFAULT_CLASS_NAME |
| Fields inherited from interface org.codehaus.commons.compiler.ICookable |
|---|
BOOT_CLASS_LOADER, SYSTEM_PROPERTY_SOURCE_DEBUGGING_DIR, SYSTEM_PROPERTY_SOURCE_DEBUGGING_ENABLE |
| Constructor Summary | |
|---|---|
ClassBodyEvaluator()
|
|
ClassBodyEvaluator(Scanner scanner,
optionalExtendedType,
[] implementedTypes,
optionalParentClassLoader)
Equivalent to ClassBodyEvaluator cbe = new ClassBodyEvaluator(); cbe.setExtendedType(optionalExtendedType); cbe.setImplementedTypes(implementedTypes); cbe.setParentClassLoader(optionalParentClassLoader); cbe.cook(scanner); |
|
ClassBodyEvaluator(Scanner scanner,
optionalParentClassLoader)
Equivalent to ClassBodyEvaluator cbe = new ClassBodyEvaluator(); cbe.setParentClassLoader(optionalParentClassLoader); cbe.cook(scanner); |
|
ClassBodyEvaluator(Scanner scanner,
className,
optionalExtendedType,
[] implementedTypes,
optionalParentClassLoader)
Equivalent to ClassBodyEvaluator cbe = new ClassBodyEvaluator(); cbe.setClassName(className); cbe.setExtendedType(optionalExtendedType); cbe.setImplementedTypes(implementedTypes); cbe.setParentClassLoader(optionalParentClassLoader); cbe.cook(scanner); |
|
ClassBodyEvaluator( classBody)
Equivalent to ClassBodyEvaluator cbe = new ClassBodyEvaluator(); cbe.cook(classBody); |
|
ClassBodyEvaluator( optionalFileName,
is)
Equivalent to ClassBodyEvaluator cbe = new ClassBodyEvaluator(); cbe.cook(optionalFileName, is); |
|
ClassBodyEvaluator( optionalFileName,
reader)
Equivalent to ClassBodyEvaluator cbe = new ClassBodyEvaluator(); cbe.cook(optionalFileName, reader); |
|
| Method Summary | |
|---|---|
protected Java.PackageMemberClassDeclaration |
addPackageMemberClassDeclaration(Location location,
Java.CompilationUnit compilationUnit)
To the given Java.CompilationUnit, add
A class declaration with the configured name, superclass and interfaces
A method declaration with the given return type, name, parameter names and values and thrown exceptions
|
protected |
compileToClass(Java.CompilationUnit compilationUnit)
Compile the given compilation unit, load all generated classes, and return the class with the given name. |
void |
cook(Scanner scanner)
Scans, parses and ompiles a given compilation unit from the given scanner. |
static |
createFastClassBodyEvaluator(Scanner scanner,
optionalBaseType,
optionalParentClassLoader)
Use createInstance(Reader) instead:
IClassBodyEvaluator cbe = CompilerFactoryFactory. |
static |
createFastClassBodyEvaluator(Scanner scanner,
className,
optionalExtendedClass,
[] implementedInterfaces,
optionalParentClassLoader)
Deprecated. Use createInstance(Reader) instead. |
|
createInstance( reader)
Scans, parses and compiles a class body from the tokens delivered by the the given , then creates and returns an instance of that class. |
|
getClazz()
Returns the loaded . |
protected Java.CompilationUnit |
makeCompilationUnit(Parser optionalParser)
Create a Java.CompilationUnit, set the default imports, and parse the import declarations. |
void |
setClassName( className)
Set the name of the generated class. |
void |
setDefaultImports([] optionalDefaultImports)
"Default imports" add to the system import "java.lang", i.e. the evaluator may refer to classes imported by default imports without having to explicitly declare IMPORT statements. |
void |
setExtendedClass( optionalExtendedType)
Set a particular superclass that the generated class will extend. |
void |
setExtendedType( optionalExtendedClass)
Deprecated. |
void |
setImplementedInterfaces([] implementedTypes)
Set a particular set of interfaces that the generated class will implement. |
void |
setImplementedTypes([] implementedInterfaces)
Deprecated. |
| Methods inherited from class org.codehaus.janino.SimpleCompiler |
|---|
assertNotCooked, classesToTypes, classToType, compileToClassLoader, cook, cook, equals, getClassLoader, hashCode, main, setCompileErrorHandler, setDebuggingInformation, setParentClassLoader, setWarningHandler |
| Methods inherited from class org.codehaus.commons.compiler.Cookable |
|---|
cook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile, readString |
| Methods inherited from class java.lang. |
|---|
, , , , , , , , |
| Methods inherited from interface org.codehaus.commons.compiler.ICookable |
|---|
cook, cook, cook, cook, cook, cook, cook, cook, cookFile, cookFile, cookFile, cookFile, setCompileErrorHandler, setDebuggingInformation, setParentClassLoader, setWarningHandler |
| Constructor Detail |
|---|
public ClassBodyEvaluator( classBody)
throws CompileException
ClassBodyEvaluator cbe = new ClassBodyEvaluator(); cbe.cook(classBody);
CompileExceptionClassBodyEvaluator(),
Cookable.cook(String)public ClassBodyEvaluator( optionalFileName,
is)
throws CompileException,
ClassBodyEvaluator cbe = new ClassBodyEvaluator(); cbe.cook(optionalFileName, is);
CompileException
ClassBodyEvaluator(),
Cookable.cook(String, InputStream)public ClassBodyEvaluator( optionalFileName,
reader)
throws CompileException,
ClassBodyEvaluator cbe = new ClassBodyEvaluator(); cbe.cook(optionalFileName, reader);
CompileException
ClassBodyEvaluator(),
Cookable.cook(String, Reader)public ClassBodyEvaluator(Scanner scanner,
optionalParentClassLoader)
throws CompileException,
ClassBodyEvaluator cbe = new ClassBodyEvaluator(); cbe.setParentClassLoader(optionalParentClassLoader); cbe.cook(scanner);
CompileException
ClassBodyEvaluator(),
SimpleCompiler.setParentClassLoader(ClassLoader),
Cookable.cook(Reader)public ClassBodyEvaluator(Scanner scanner,
optionalExtendedType,
[] implementedTypes,
optionalParentClassLoader)
throws CompileException,
ClassBodyEvaluator cbe = new ClassBodyEvaluator(); cbe.setExtendedType(optionalExtendedType); cbe.setImplementedTypes(implementedTypes); cbe.setParentClassLoader(optionalParentClassLoader); cbe.cook(scanner);
CompileException
ClassBodyEvaluator(),
setExtendedClass(Class),
setImplementedInterfaces(Class[]),
SimpleCompiler.setParentClassLoader(ClassLoader),
Cookable.cook(Reader)public ClassBodyEvaluator(Scanner scanner,
className,
optionalExtendedType,
[] implementedTypes,
optionalParentClassLoader)
throws CompileException,
ClassBodyEvaluator cbe = new ClassBodyEvaluator(); cbe.setClassName(className); cbe.setExtendedType(optionalExtendedType); cbe.setImplementedTypes(implementedTypes); cbe.setParentClassLoader(optionalParentClassLoader); cbe.cook(scanner);
CompileException
ClassBodyEvaluator(),
setClassName(String),
setExtendedClass(Class),
setImplementedInterfaces(Class[]),
SimpleCompiler.setParentClassLoader(ClassLoader),
Cookable.cook(Reader)public ClassBodyEvaluator()
| Method Detail |
|---|
public void setDefaultImports([] optionalDefaultImports)
IClassBodyEvaluatorNotice that JDK 5 "static imports" are also supported, as shown in the following example.
Example:
sc.setDefaultImports(new String[] {
"java.util.Map", // Single type import
"java.io.*", // Type-import-on-demand
"static java.util.Collections.EMPTY_MAP", // Single static import
"static java.util.Collections.*", // Static-import-on-demand
});
setDefaultImports in interface IClassBodyEvaluatorpublic void setClassName( className)
IClassBodyEvaluatorIClassBodyEvaluator.DEFAULT_CLASS_NAME. In most cases,
there is no need to set this name, because the generated class is loaded into its own
where its name cannot collide with classes generated by
other evaluators.
One reason to use this function is to have a class name in a non-default package, which can be relevant when types and members with DEFAULT accessibility are accessed.
setClassName in interface IClassBodyEvaluatorpublic void setExtendedClass( optionalExtendedType)
IClassBodyEvaluatornull is
passed, the generated class will extend .
The common reason to set a base class for an evaluator is that the generated class can directly access the base superclass's (non-private) members.
setExtendedClass in interface IClassBodyEvaluatorpublic void setExtendedType( optionalExtendedClass)
setExtendedType in interface IClassBodyEvaluatorpublic void setImplementedInterfaces([] implementedTypes)
IClassBodyEvaluator
setImplementedInterfaces in interface IClassBodyEvaluatorpublic void setImplementedTypes([] implementedInterfaces)
setImplementedTypes in interface IClassBodyEvaluatorpublic void cook(Scanner scanner)
throws CompileException,
SimpleCompilerSimpleCompiler.getClassLoader() returns a that allows for access to the compiled classes.
cook in class SimpleCompilerCompileException
protected final Java.CompilationUnit makeCompilationUnit(Parser optionalParser)
throws CompileException,
Java.CompilationUnit, set the default imports, and parse the import declarations.
If the optionalParser is given, a sequence of IMPORT directives is parsed from it and added to the
compilation unit.
CompileException
protected Java.PackageMemberClassDeclaration addPackageMemberClassDeclaration(Location location,
Java.CompilationUnit compilationUnit)
throws CompileException
Java.CompilationUnit, add
Java.ClassDeclaration object
CompileExceptionprotected final compileToClass(Java.CompilationUnit compilationUnit)
throws CompileException
compilationUnit -
CompileExceptionpublic getClazz()
IClassBodyEvaluator
This method must only be called after exactly one of the ICookable.cook(String,
java.io.Reader) methods was called.
getClazz in interface IClassBodyEvaluatorpublic createInstance( reader)
throws CompileException,
IClassBodyEvaluator
createInstance in interface IClassBodyEvaluatorreader - Source of class body tokens
optionalExtendedType and implements the given
implementedTypes
CompileException
public static createFastClassBodyEvaluator(Scanner scanner,
optionalBaseType,
optionalParentClassLoader)
throws CompileException,
createInstance(Reader) instead:
IClassBodyEvaluator cbe =CompilerFactoryFactory.getDefaultCompilerFactory().newClassBodyEvaluator(); if (optionalBaseType != null) { if (optionalBaseType.isInterface()) { cbe.setImplementedInterfaces(new Class[] { optionalBaseType }); } else { cbe.setExtendedClass(optionalBaseType); } } cbe.setParentClassLoader(optionalParentClassLoader); cbe.createInstance(reader);
CompileException
createInstance(Reader)
public static createFastClassBodyEvaluator(Scanner scanner,
className,
optionalExtendedClass,
[] implementedInterfaces,
optionalParentClassLoader)
throws CompileException,
createInstance(Reader) instead.
createInstance(Reader) instead:
IClassBodyEvaluator cbe =CompilerFactoryFactory.getDefaultCompilerFactory().newClassBodyEvaluator(); cbe.setExtendedClass(optionalExtendedClass); cbe.setImplementedInterfaces(implementedInterfaces); cbe.setParentClassLoader(optionalParentClassLoader); cbe.createInstance(reader);
CompileException
createInstance(Reader)
|
janino.net | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||