public class UnitCompiler
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
UnitCompiler.ErrorHandler
Interface type for
setCompileErrorHandler(org.codehaus.janino.UnitCompiler.ErrorHandler). |
static class |
UnitCompiler.SimpleIField
Short-hand implementation of
IClass.IField that implements a non-constant, non-static,
package-accessible field. |
| Modifier and Type | Field and Description |
|---|---|
Java.CompilationUnit |
compilationUnit |
static java.lang.Object |
NOT_CONSTANT
Special return value for the
getConstantValue(Java.Rvalue) method family indicating that the given
Java.Rvalue does not evaluate to a constant value. |
| Constructor and Description |
|---|
UnitCompiler(Java.CompilationUnit compilationUnit,
IClassLoader iClassLoader) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
buildLocalVariableMap(Java.CatchClause cc,
java.util.Map localVars) |
void |
compile2(Java.AnonymousClassDeclaration acd) |
void |
compile2(Java.ClassDeclaration cd) |
void |
compile2(org.codehaus.janino.Java.InnerClassDeclaration icd) |
void |
compile2(Java.InterfaceDeclaration id) |
void |
compile2(Java.LocalClassDeclaration lcd) |
void |
compile2(Java.MemberClassDeclaration mcd) |
void |
compile2(Java.PackageMemberTypeDeclaration pmtd) |
ClassFile[] |
compileUnit(boolean debugSource,
boolean debugLines,
boolean debugVars)
Generates an array of
ClassFile objects which represent the classes and interfaces declared in the
compilation unit. |
IClass |
findClass(java.lang.String className)
Find one class or interface declared in this compilation unit by name.
|
IClass.IMethod |
findIMethod(Java.MethodInvocation mi)
Find named methods of "targetType", examine the argument types and choose the most specific method.
|
IClass.IMethod |
findIMethod(Java.SuperclassMethodInvocation scmi) |
IClass.IInvocable |
findMostSpecificIInvocable(Java.Locatable locatable,
IClass.IInvocable[] iInvocables,
IClass[] argumentTypes,
boolean boxingPermitted,
Java.Scope contextScope)
Determine the applicable invocables and choose the most specific invocable.
|
boolean |
generatesCode2(Java.AssertStatement as) |
boolean |
generatesCode2(Java.Block b) |
boolean |
generatesCode2(Java.BlockStatement bs) |
boolean |
generatesCode2(Java.EmptyStatement es) |
boolean |
generatesCode2(Java.FieldDeclaration fd) |
boolean |
generatesCode2(Java.Initializer i) |
boolean |
generatesCode2(Java.LocalClassDeclarationStatement lcds) |
boolean |
generatesCode2ListStatements(java.util.List l) |
java.lang.Object |
getConstantValue(Java.Rvalue rv)
Attempts to evaluate as a constant expression.
|
void |
getIMethods(IClass type,
java.lang.String methodName,
java.util.List v)
Add all methods with the given
methodName that are declared by the type, its superclasses and
all their superinterfaces to the result list v. |
Java.LocalVariable |
getLocalVariable(Java.FunctionDeclarator.FormalParameter fp) |
Java.LocalVariable |
getLocalVariable(Java.LocalVariableDeclarationStatement lvds,
Java.VariableDeclarator vd) |
java.lang.String[] |
getSingleTypeImport(java.lang.String name,
Location location)
Check if the given simple name was imported through a single type import.
|
CodeContext.Offset |
getWhereToBreak(Java.BreakableStatement bs) |
IClass |
importTypeOnDemand(java.lang.String simpleTypeName,
Location location)
6.5.2.BL1.B1.B5, 6.5.2.BL1.B1.B6 Type-import-on-demand.
6.5.5.1.6 Type-import-on-demand declaration. |
void |
leave2(Java.BlockStatement bs,
IClass optionalStackValueType) |
void |
leave2(Java.SynchronizedStatement ss,
IClass optionalStackValueType) |
void |
leave2(Java.TryStatement ts,
IClass optionalStackValueType) |
void |
setCompileErrorHandler(UnitCompiler.ErrorHandler optionalCompileErrorHandler)
By default,
CompileExceptions are thrown on compile errors, but an application my install its own
(thread-local) UnitCompiler.ErrorHandler. |
void |
setWarningHandler(WarningHandler optionalWarningHandler)
By default, warnings are discarded, but an application my install a custom
WarningHandler. |
IClass.IMethod |
toIMethod(Java.MethodDeclarator md) |
Java.Lvalue |
toLvalueOrCompileException(Java.Atom a) |
public static final java.lang.Object NOT_CONSTANT
getConstantValue(Java.Rvalue) method family indicating that the given
Java.Rvalue does not evaluate to a constant value.public final Java.CompilationUnit compilationUnit
public UnitCompiler(Java.CompilationUnit compilationUnit, IClassLoader iClassLoader)
public ClassFile[] compileUnit(boolean debugSource, boolean debugLines, boolean debugVars) throws CompileException
ClassFile objects which represent the classes and interfaces declared in the
compilation unit.CompileExceptionpublic void compile2(Java.PackageMemberTypeDeclaration pmtd) throws CompileException
CompileExceptionpublic void compile2(Java.ClassDeclaration cd) throws CompileException
CompileExceptionpublic void compile2(Java.AnonymousClassDeclaration acd) throws CompileException
CompileExceptionpublic void compile2(Java.LocalClassDeclaration lcd) throws CompileException
CompileExceptionpublic void compile2(org.codehaus.janino.Java.InnerClassDeclaration icd)
throws CompileException
CompileExceptionpublic void compile2(Java.MemberClassDeclaration mcd) throws CompileException
CompileExceptionpublic void compile2(Java.InterfaceDeclaration id) throws CompileException
CompileExceptionpublic Java.LocalVariable getLocalVariable(Java.LocalVariableDeclarationStatement lvds, Java.VariableDeclarator vd) throws CompileException
CompileExceptionprotected void buildLocalVariableMap(Java.CatchClause cc, java.util.Map localVars) throws CompileException
CompileExceptionpublic Java.LocalVariable getLocalVariable(Java.FunctionDeclarator.FormalParameter fp) throws CompileException
CompileExceptionpublic final java.lang.Object getConstantValue(Java.Rvalue rv) throws CompileException
NOT_CONSTANT iff the rvalue is not a constant valueCompileExceptionpublic boolean generatesCode2(Java.BlockStatement bs)
public boolean generatesCode2(Java.AssertStatement as)
public boolean generatesCode2(Java.EmptyStatement es)
public boolean generatesCode2(Java.LocalClassDeclarationStatement lcds)
public boolean generatesCode2(Java.Initializer i) throws CompileException
CompileExceptionpublic boolean generatesCode2ListStatements(java.util.List l)
throws CompileException
CompileExceptionpublic boolean generatesCode2(Java.Block b) throws CompileException
CompileExceptionpublic boolean generatesCode2(Java.FieldDeclaration fd) throws CompileException
CompileExceptionpublic void leave2(Java.BlockStatement bs, IClass optionalStackValueType)
public void leave2(Java.SynchronizedStatement ss, IClass optionalStackValueType)
public void leave2(Java.TryStatement ts, IClass optionalStackValueType)
public final Java.Lvalue toLvalueOrCompileException(Java.Atom a) throws CompileException
CompileExceptionpublic IClass.IMethod findIMethod(Java.MethodInvocation mi) throws CompileException
Notice that the returned IClass.IMethod may be declared in an enclosing type.
IClass.IMethod or nullCompileExceptionpublic void getIMethods(IClass type, java.lang.String methodName, java.util.List v) throws CompileException
methodName that are declared by the type, its superclasses and
all their superinterfaces to the result list v.CompileExceptionpublic IClass.IMethod findIMethod(Java.SuperclassMethodInvocation scmi) throws CompileException
CompileExceptionpublic IClass.IInvocable findMostSpecificIInvocable(Java.Locatable locatable, IClass.IInvocable[] iInvocables, IClass[] argumentTypes, boolean boxingPermitted, Java.Scope contextScope) throws CompileException
IClass.IInvocable or null if no IClass.IInvocable is applicableCompileExceptionpublic IClass.IMethod toIMethod(Java.MethodDeclarator md)
public java.lang.String[] getSingleTypeImport(java.lang.String name,
Location location)
throws CompileException
name - The simple type name, e.g. Inner{ "pkg", "Outer", "Inner" }, or nullCompileExceptionpublic IClass importTypeOnDemand(java.lang.String simpleTypeName, Location location) throws CompileException
null if the given simpleTypeName cannot be resolved through any of the
import-on-demand directivesCompileExceptionpublic IClass findClass(java.lang.String className)
className - Fully qualified class name, e.g. "pkg1.pkg2.Outer$Inner".null if a class or an interface with that name is not declared in this compilation unitpublic void setCompileErrorHandler(UnitCompiler.ErrorHandler optionalCompileErrorHandler)
CompileExceptions are thrown on compile errors, but an application my install its own
(thread-local) UnitCompiler.ErrorHandler.
Be aware that a single problem during compilation often causes a bunch of compile errors, so a good UnitCompiler.ErrorHandler counts errors and throws a CompileException when a limit is reached.
If the given UnitCompiler.ErrorHandler does not throw CompileExceptions, then compileUnit(boolean, boolean, boolean) will throw one when the compilation of the unit is finished, and errors
had occurred. In other words: The UnitCompiler.ErrorHandler may throw a CompileException or not, but compileUnit(boolean, boolean, boolean) will definitely throw a CompileException if one or more compile
errors have occurred.
optionalCompileErrorHandler - null to restore the default behavior (throwing a CompileExceptionpublic void setWarningHandler(WarningHandler optionalWarningHandler)
WarningHandler.optionalWarningHandler - null to indicate that no warnings be issuedpublic CodeContext.Offset getWhereToBreak(Java.BreakableStatement bs)