public class UnitCompiler extends Object
| Modifier and Type | Class and Description |
|---|---|
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 |
|---|---|
static boolean |
JUMP_IF_FALSE
Special value for the orientation parameter of the
compileBoolean(Java.Rvalue,
CodeContext.Offset, boolean) methods, indicating that the code should be generated such that execution branches
if the value on top of the operand stack is FALSE. |
static boolean |
JUMP_IF_TRUE
Special value for the orientation parameter of the
compileBoolean(Java.Rvalue,
CodeContext.Offset, boolean) methods, indicating that the code should be generated such that execution branches
if the value on top of the operand stack is TRUE. |
static 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 catchClause,
Map<String,Java.LocalVariable> localVars)
Adds the given localVars to the 'local variable map' of the given catchClause.
|
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(String className)
Finds one class or interface declared in this compilation unit by name.
|
IClass.IMethod |
findIMethod(Java.MethodInvocation mi)
Finds methods of the mi
. |
IClass.IMethod |
findIMethod(Java.SuperclassMethodInvocation superclassMethodInvocation) |
IClass.IInvocable |
findMostSpecificIInvocable(Java.Locatable locatable,
IClass.IInvocable[] iInvocables,
IClass[] argumentTypes,
boolean boxingPermitted,
Java.Scope contextScope)
Determines the applicable invocables and choose the most specific invocable.
|
Java.CompilationUnit |
getCompilationUnit() |
Object |
getConstantValue(Java.Rvalue rv)
Attempts to evaluate as a constant expression.
|
void |
getIMethods(IClass type,
String methodName,
List<IClass.IMethod> v)
Adds 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.CatchParameter parameter) |
Java.LocalVariable |
getLocalVariable(Java.FunctionDeclarator.FormalParameter parameter) |
Java.LocalVariable |
getLocalVariable(Java.FunctionDeclarator.FormalParameter parameter,
boolean isVariableArityParameter) |
Java.LocalVariable |
getLocalVariable(Java.LocalVariableDeclarationStatement lvds,
Java.VariableDeclarator vd) |
String[] |
getSingleTypeImport(String name,
Location location)
Checks if the given simple name was imported through a single type import.
|
IClass |
importTypeOnDemand(String simpleTypeName,
Location location)
6.5.2.BL1.B1.B5, 6.5.2.BL1.B1.B6 Type-import-on-demand.
|
EnumSet<JaninoOption> |
options() |
UnitCompiler |
options(EnumSet<JaninoOption> options)
Sets the options for all future compilations.
|
void |
setCompileErrorHandler(ErrorHandler optionalCompileErrorHandler)
By default,
CompileExceptions are thrown on compile errors, but an application my install its own
(thread-local) ErrorHandler. |
void |
setWarningHandler(WarningHandler optionalWarningHandler)
By default, warnings are discarded, but an application my install a custom
WarningHandler. |
IClass.IMethod |
toIMethod(Java.MethodDeclarator methodDeclarator) |
public static final boolean JUMP_IF_TRUE
compileBoolean(Java.Rvalue,
CodeContext.Offset, boolean) methods, indicating that the code should be generated such that execution branches
if the value on top of the operand stack is TRUE.public static final boolean JUMP_IF_FALSE
compileBoolean(Java.Rvalue,
CodeContext.Offset, boolean) methods, indicating that the code should be generated such that execution branches
if the value on top of the operand stack is FALSE.public static final Object NOT_CONSTANT
getConstantValue(Java.Rvalue) method family indicating that the given
Java.Rvalue does not evaluate to a constant value.public UnitCompiler(Java.CompilationUnit compilationUnit, IClassLoader iClassLoader)
public EnumSet<JaninoOption> options()
public UnitCompiler options(EnumSet<JaninoOption> options)
public Java.CompilationUnit getCompilationUnit()
Java.CompilationUnit that this UnitCompiler compilespublic ClassFile[] compileUnit(boolean debugSource, boolean debugLines, boolean debugVars) throws CompileException
ClassFile objects which represent the classes and interfaces declared in the
compilation unit.CompileExceptionpublic Java.LocalVariable getLocalVariable(Java.LocalVariableDeclarationStatement lvds, Java.VariableDeclarator vd) throws CompileException
Java.LocalVariable corresponding with the local variable declaration/declaratorCompileExceptionprotected void buildLocalVariableMap(Java.CatchClause catchClause, Map<String,Java.LocalVariable> localVars) throws CompileException
CompileExceptionpublic Java.LocalVariable getLocalVariable(Java.FunctionDeclarator.FormalParameter parameter) throws CompileException
Java.LocalVariable corresponding with the parameterCompileExceptionpublic Java.LocalVariable getLocalVariable(Java.FunctionDeclarator.FormalParameter parameter, boolean isVariableArityParameter) throws CompileException
isVariableArityParameter - Whether the parameter is the last parameter of a 'variable arity'
(a.k.a. 'varargs') method declarationJava.LocalVariable corresponding with the parameterCompileExceptionpublic Java.LocalVariable getLocalVariable(Java.CatchParameter parameter) throws CompileException
Java.LocalVariable corresponding with the parameterCompileException@Nullable public final Object getConstantValue(Java.Rvalue rv) throws CompileException
Boolean, Byte, Short, Integer, Long, Float, Double, Character, String, null (representing the null literal.
This method cannot be STATIC, because the constant value may refer to a constant declaration in this compilation unit.
NOT_CONSTANT iff the rvalue is not a constant valueCompileExceptionpublic IClass.IMethod findIMethod(Java.MethodInvocation mi) throws CompileException
.optionalTarget named mi.methodName,
examines the argument types and chooses the most specific method. Checks that only the
allowed exceptions are thrown.
Notice that the returned IClass.IMethod may be declared in an enclosing type.
IClass.IMethodCompileExceptionpublic void getIMethods(IClass type, String methodName, List<IClass.IMethod> v) throws CompileException
CompileExceptionpublic IClass.IMethod findIMethod(Java.SuperclassMethodInvocation superclassMethodInvocation) throws CompileException
IClass.IMethod that implements the superclassMethodInvocationCompileException@Nullable public 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 methodDeclarator)
IClass.IMethod that implements the methodDeclarator@Nullable public String[] getSingleTypeImport(String name, Location location) throws CompileException
name - The simple type name, e.g. "Inner"{ "pkg", "Outer", "Inner" }, or nullCompileException@Nullable public IClass importTypeOnDemand(String simpleTypeName, Location location) throws CompileException
null if the given simpleTypeName cannot be resolved through any of the
import-on-demand directivesCompileException@Nullable public IClass findClass(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(@Nullable ErrorHandler optionalCompileErrorHandler)
CompileExceptions are thrown on compile errors, but an application my install its own
(thread-local) ErrorHandler.
Be aware that a single problem during compilation often causes a bunch of compile errors, so a good ErrorHandler counts errors and throws a CompileException when a limit is reached.
If the given 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 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(@Nullable WarningHandler optionalWarningHandler)
WarningHandler.optionalWarningHandler - null to indicate that no warnings be issuedCopyright © 2019. All rights reserved.