Package org.codehaus.janino
Class UnitCompiler
java.lang.Object
org.codehaus.janino.UnitCompiler
This class actually implements the Java™ compiler. It is associated with exactly one compilation unit which it
compiles.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Interface type forsetCompileErrorHandler(org.codehaus.janino.UnitCompiler.ErrorHandler)
.static class
Short-hand implementation ofIClass.IField
that implements a non-constant, non-static, package-accessible field. -
Field Summary
FieldsModifier and TypeFieldDescriptionfinal Java.CompilationUnit
static final Object
Special return value for thegetConstantValue(Java.Rvalue)
method family indicating that the givenJava.Rvalue
does not evaluate to a constant value. -
Constructor Summary
ConstructorsConstructorDescriptionUnitCompiler
(Java.CompilationUnit compilationUnit, IClassLoader iClassLoader) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
buildLocalVariableMap
(Java.CatchClause cc, Map localVars) void
void
void
compile2
(org.codehaus.janino.Java.InnerClassDeclaration icd) void
void
void
void
compileUnit
(boolean debugSource, boolean debugLines, boolean debugVars) Generates an array ofClassFile
objects which represent the classes and interfaces declared in the compilation unit.Find one class or interface declared in this compilation unit by name.Find named methods of "targetType", examine the argument types and choose the most specific method.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
boolean
boolean
boolean
boolean
boolean
boolean
boolean
final Object
Attempts to evaluate as a constant expression.void
getIMethods
(IClass type, String methodName, List v) Add all methods with the givenmethodName
that are declared by thetype
, its superclasses and all their superinterfaces to the result listv
.String[]
getSingleTypeImport
(String name, Location location) Check if the given simple name was imported through a single type import.importTypeOnDemand
(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,CompileException
s 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 customWarningHandler
.final Java.Lvalue
-
Field Details
-
NOT_CONSTANT
Special return value for thegetConstantValue(Java.Rvalue)
method family indicating that the givenJava.Rvalue
does not evaluate to a constant value. -
compilationUnit
-
-
Constructor Details
-
UnitCompiler
-
-
Method Details
-
compileUnit
public ClassFile[] compileUnit(boolean debugSource, boolean debugLines, boolean debugVars) throws CompileException Generates an array ofClassFile
objects which represent the classes and interfaces declared in the compilation unit.- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
getLocalVariable
public Java.LocalVariable getLocalVariable(Java.LocalVariableDeclarationStatement lvds, Java.VariableDeclarator vd) throws CompileException - Throws:
CompileException
-
buildLocalVariableMap
- Throws:
CompileException
-
getLocalVariable
public Java.LocalVariable getLocalVariable(Java.FunctionDeclarator.FormalParameter fp) throws CompileException - Throws:
CompileException
-
getConstantValue
Attempts to evaluate as a constant expression.- Returns:
NOT_CONSTANT
iff the rvalue is not a constant value- Throws:
CompileException
-
generatesCode2
-
generatesCode2
-
generatesCode2
-
generatesCode2
-
generatesCode2
- Throws:
CompileException
-
generatesCode2ListStatements
- Throws:
CompileException
-
generatesCode2
- Throws:
CompileException
-
generatesCode2
- Throws:
CompileException
-
leave2
-
leave2
-
leave2
-
toLvalueOrCompileException
- Throws:
CompileException
-
findIMethod
Find named methods of "targetType", examine the argument types and choose the most specific method. Check that only the allowed exceptions are thrown.Notice that the returned
IClass.IMethod
may be declared in an enclosing type.- Returns:
- The selected
IClass.IMethod
ornull
- Throws:
CompileException
-
getIMethods
Add all methods with the givenmethodName
that are declared by thetype
, its superclasses and all their superinterfaces to the result listv
.- Throws:
CompileException
-
findIMethod
- Throws:
CompileException
-
findMostSpecificIInvocable
public IClass.IInvocable findMostSpecificIInvocable(Java.Locatable locatable, IClass.IInvocable[] iInvocables, IClass[] argumentTypes, boolean boxingPermitted, Java.Scope contextScope) throws CompileException Determine the applicable invocables and choose the most specific invocable.- Returns:
- The maximally specific
IClass.IInvocable
ornull
if noIClass.IInvocable
is applicable - Throws:
CompileException
-
toIMethod
-
getSingleTypeImport
Check if the given simple name was imported through a single type import.- Parameters:
name
- The simple type name, e.g.Inner
- Returns:
- The fully qualified name, e.g.
{ "pkg", "Outer", "Inner" }
, ornull
- Throws:
CompileException
-
importTypeOnDemand
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.- Returns:
null
if the givensimpleTypeName
cannot be resolved through any of the import-on-demand directives- Throws:
CompileException
-
findClass
Find one class or interface declared in this compilation unit by name.- Parameters:
className
- Fully qualified class name, e.g. "pkg1.pkg2.Outer$Inner".- Returns:
null
if a class or an interface with that name is not declared in this compilation unit
-
setCompileErrorHandler
By default,CompileException
s 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 aCompileException
when a limit is reached.If the given
UnitCompiler.ErrorHandler
does not throwCompileException
s, thencompileUnit(boolean, boolean, boolean)
will throw one when the compilation of the unit is finished, and errors had occurred. In other words: TheUnitCompiler.ErrorHandler
may throw aCompileException
or not, butcompileUnit(boolean, boolean, boolean)
will definitely throw aCompileException
if one or more compile errors have occurred.- Parameters:
optionalCompileErrorHandler
-null
to restore the default behavior (throwing aCompileException
-
setWarningHandler
By default, warnings are discarded, but an application my install a customWarningHandler
.- Parameters:
optionalWarningHandler
-null
to indicate that no warnings be issued
-
getWhereToBreak
-