Class UnitCompiler
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static interface
Helper interface for string conversion.(package private) static interface
Interface for delayed code generation.static class
Short-hand implementation ofIClass.IField
that implements a non-constant, non-static, package-accessible field.private static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Java.AbstractCompilationUnit
private CodeContext
private int
private ErrorHandler
private boolean
private boolean
private boolean
private static final int
private static final boolean
private static final int
private static final int
Non-null
whilecompileUnit(boolean, boolean, boolean)
is executing.private static final int
private final IClassLoader
static final boolean
Special value for the orientation parameter of thecompileBoolean(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 final boolean
Special value for the orientation parameter of thecompileBoolean(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.private static final int
private static final Logger
private static final Pattern
private static final int
private static final Visitor.RvalueVisitor<Boolean,
RuntimeException> private static final int
static final Object
Special return value for thegetConstantValue(Java.Rvalue)
method family indicating that the givenJava.Rvalue
does not evaluate to a constant value.private EnumSet<JaninoOption>
To be used only bygetSingleTypeImport(String, Location)
;null
means "not yet initialized"private static final int
This constant determines the number of operands up to which theprivate int
Java version to compile for.private static final Pattern
2147483648 is the special value that can not be stored in an INT, but its negated value (-2147483648) can.private static final Pattern
9223372036854775808 is the special value that can not be stored in a LONG, but its negated value (-9223372036854775808) can.private WarningHandler
-
Constructor Summary
ConstructorsConstructorDescriptionUnitCompiler
(Java.AbstractCompilationUnit abstractCompilationUnit, IClassLoader iClassLoader) -
Method Summary
Modifier and TypeMethodDescriptionprivate short
accessFlags
(Java.Modifier[] modifiers) private static Java.Modifier[]
accessModifiers
(Location location, String... keywords) private void
aconstnull
(Java.Locatable locatable) private void
add
(Java.Locatable locatable) private void
Adds the givenClassFile
to the result set.private short
addConstantClassInfo
(IClass iClass) private short
addConstantDoubleInfo
(double value) private short
addConstantFieldrefInfo
(IClass iClass, String fieldName, IClass fieldType) private short
addConstantFloatInfo
(float value) private short
addConstantIntegerInfo
(int value) private short
addConstantInterfaceMethodrefInfo
(IClass iClass, String methodName, String methodFd) private short
addConstantLongInfo
(long value) private short
addConstantMethodrefInfo
(IClass iClass, String methodName, String methodFd) private short
addConstantStringInfo
(String value) private void
addFields
(Java.FieldDeclaration fd, ClassFile cf) Creates and addsClassFile.FieldInfo
s to the cf for all fields declared by the fd.private void
addLineNumberOffset
(Java.Locatable locatable) private static String[]
allButLast
(String[] sa) private void
andOrXor
(Java.Locatable locatable, String operator) private void
anewarray
(Java.Locatable locatable, IClass componentType) private void
arraylength
(Java.Locatable locatable) private void
arraystore
(Java.Locatable locatable, IType lhsComponentType) private static <T> T
assertNonNull
(T subject) private Object
assignmentConversion
(Java.Locatable locatable, Object value, IType targetType) Implements "assignment conversion" (JLS7 5.2) on a constant value.private void
assignmentConversion
(Java.Locatable locatable, IType sourceType, IType targetType, Object constantValue) Implements "assignment conversion" (JLS7 5.2).(package private) void
Copies the values of the synthetic parameters of this constructor ("this$..." and "val$...") to the synthetic fields of the object ("this$..." and "val$...").private void
athrow
(Java.Locatable locatable) private IClass
binaryNumericPromotionType
(Java.Locatable locatable, IType type1, IType type2) private void
boxingConversion
(Java.Locatable locatable, IType sourceType, IType targetType) private void
buildLocalVariableMap
(Java.Block block, Map<String, Java.LocalVariable> localVars) private Map<String,
Java.LocalVariable> buildLocalVariableMap
(Java.BlockStatement blockStatement, Map<String, Java.LocalVariable> localVars) Computes and fills in the 'local variable map' for the given blockStatement.protected void
buildLocalVariableMap
(Java.CatchClause catchClause, Map<String, Java.LocalVariable> localVars) Adds the given localVars to the 'local variable map' of the given catchClause.private static Map<String,
Java.LocalVariable> buildLocalVariableMap
(Java.ConstructorInvocation ci, Map<String, Java.LocalVariable> localVars) private void
buildLocalVariableMap
(Java.DoStatement ds, Map<String, Java.LocalVariable> localVars) private void
buildLocalVariableMap
(Java.ForEachStatement fes, Map<String, Java.LocalVariable> localVars) private void
buildLocalVariableMap
(Java.ForStatement fs, Map<String, Java.LocalVariable> localVars) private void
private void
buildLocalVariableMap
(Java.IfStatement is, Map<String, Java.LocalVariable> localVars) private void
buildLocalVariableMap
(Java.Initializer i, Map<String, Java.LocalVariable> localVars) private Map<String,
Java.LocalVariable> buildLocalVariableMap
(Java.LabeledStatement ls, Map<String, Java.LocalVariable> localVars) private Map<String,
Java.LocalVariable> buildLocalVariableMap
(Java.LocalVariableDeclarationStatement lvds, Map<String, Java.LocalVariable> localVars) private static Map<String,
Java.LocalVariable> buildLocalVariableMap
(Java.Statement s, Map<String, Java.LocalVariable> localVars) private void
buildLocalVariableMap
(Java.SwitchStatement ss, Map<String, Java.LocalVariable> localVars) private void
buildLocalVariableMap
(Java.SynchronizedStatement ss, Map<String, Java.LocalVariable> localVars) private void
buildLocalVariableMap
(Java.TryStatement ts, Map<String, Java.LocalVariable> localVars) private void
buildLocalVariableMap
(Java.WhileStatement ws, Map<String, Java.LocalVariable> localVars) private void
castConversion
(Java.Locatable locatable, IType sourceType, IType targetType, Object constantValue) private static short
changeAccessibility
(short accessFlags, short newAccessibility) private void
checkAccessible
(IClass.IMember member, Java.Scope contextScope, Location location) Checks whether the givenIClass.IMember
is accessible in the given context, according to JLS7 6.6.1.BL1.B4.private void
checkAccessible
(IClass type, Java.Scope contextScope, Location location) Checks whether the givenIClass
is accessible in the given context, according to JLS7 6.6.1.2 and 6.6.1.4.private void
checkcast
(Java.Locatable locatable, IType targetType) private void
checkForConflictWithSingleTypeImport
(String name, Location location) private void
private void
checkMemberAccessible
(IClass iClassDeclaringMember, IClass.IMember member, Java.Scope contextScope, Location location) Verifies that a member (class, interface, field or method) declared in a given class is accessible from a given block statement context, according to JLS7 6.6.1.4.private void
checkThrownException
(Java.Locatable locatable, IType type, Java.Scope scope) private void
checkThrownExceptions
(Java.Invocation in, IClass.IMethod iMethod) private void
cmp
(Java.Locatable locatable, int opIdx) private IType
commonSupertype
(IType t1, IType t2) private IType
commonSupertype2
(IType t1, IType t2) private boolean
private void
compile
(Java.FunctionDeclarator fd, ClassFile classFile) private void
compile
(Java.Rvalue rv) SomeJava.Rvalue
s compile more efficiently when their value is not needed, e.g.private void
private void
private boolean
private void
private boolean
private void
private boolean
private boolean
private void
Compiles an (ordinary, not modular) compilation unitprivate boolean
private void
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private void
compile2
(Java.FunctionDeclarator fd, ClassFile classFile) private boolean
private boolean
private void
private void
private boolean
private void
private boolean
private boolean
private void
private void
Compiles a top-level class or enum declaration.private void
Compiles a top-level interface or annotation type declaration.private void
private boolean
private void
compile2
(Java.Rvalue rv) private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private void
compileAnnotations
(Java.Annotation[] annotations, Annotatable target, ClassFile cf) Converts and adds the annotations to the target.private IType
compileArithmeticBinaryOperation
(Java.Locatable locatable, IType lhsType, String operator, Java.Rvalue rhs) The LHS operand of type lhsType is expected on the stack.private IType
compileArithmeticOperation
(Java.Locatable locatable, IType firstOperandType, Iterator<Java.Rvalue> operands, String operator) Executes an arithmetic operation on a sequence of operands.private void
compileBoolean
(Java.Rvalue rv, CodeContext.Offset dst, boolean orientation) Compiles anJava.Rvalue
and branches, depending on the value.private void
compileBoolean2
(Java.BinaryOperation bo, CodeContext.Offset dst, boolean orientation) private void
compileBoolean2
(Java.ParenthesizedExpression pe, CodeContext.Offset dst, boolean orientation) private void
compileBoolean2
(Java.Rvalue rv, CodeContext.Offset dst, boolean orientation) private void
compileBoolean2
(Java.UnaryOperation ue, CodeContext.Offset dst, boolean orientation) private int
Generates code that determines the context of theJava.Rvalue
and puts it on the operand stack.private int
private int
Array access expression; see JLS7 15.13 / JLS8+ 15.10.3.private int
private int
private int
private int
private int
private int
private void
Compiles all of the types for this declarationprivate void
compileDeclaredMethods
(Java.TypeDeclaration typeDeclaration, ClassFile cf) Compiles all of the methods for this declarationprivate void
compileDeclaredMethods
(Java.TypeDeclaration typeDeclaration, ClassFile cf, int startPos) Compiles methods for this declaration starting at startPos.private ClassFile.ElementValue
compileElementValue
(Java.ElementValue elementValue, ClassFile cf) private void
compileError
(String message) Equivalent withcompileError(String, Location)
with anull
location argument.private void
compileError
(String message, Location location) Issues a compile error with the given message.private static CompileException
compileException
(Java.Locatable locatable, String message) private IClass.IField
compileField
(Java.TypeDeclaration declaringType, Java.Annotation[] annotations, Access access, boolean statiC, boolean finaL, Java.Type type, int brackets, String name, Java.ArrayInitializerOrRvalue initializer) Compiles one variable declarator into anIClass.IField
.private IClass.IField[]
compileFields
(Java.FieldDeclaration fieldDeclaration) private IType
Generates code that determines the value of theJava.Rvalue
and puts it on the operand stack.private IType
private IType
private IClass
private IClass
private IType
private IType
private IClass
private IType
private IClass
private IClass
private IType
private IType
private IType
private IType
private IClass
private IClass
private IClass
private IType
private IClass
private IClass
private IClass
private IClass
private IType
private IType
private IType
private IType
private IType
private IClass
private IType
private IClass
private IClass
private IClass
private void
compileGetValue
(Java.ArrayInitializer ai, IType arrayType) private IType
Convenience function that callscompileContext(Rvalue)
andcompileGet(Rvalue)
.private void
Generates code that stores a value in theJava.Lvalue
.private void
private void
private void
private void
private void
private void
private void
private boolean
compileStatements
(List<? extends Java.BlockStatement> statements) private IClass
compileStringConcatenation
(Java.Locatable locatable, IType type, Java.Rvalue secondOperand, Iterator<Java.Rvalue> operands) private boolean
compileTryCatch
(Java.TryStatement tryStatement, UnitCompiler.Compilable2 compileBody, CodeContext.Offset beginningOfBody, CodeContext.Offset afterStatement) Generates code for a TRY statement without resources and without a FINALLY clause.private boolean
compileTryCatchFinally
(Java.TryStatement ts, UnitCompiler.Compilable2 compileBody, Java.BlockStatement finallY) Generates code for a TRY statement without resources, but with an (optional) FINALLY clause.private boolean
compileTryCatchFinallyWithResources
(Java.TryStatement ts, List<Java.TryStatement.Resource> resources, UnitCompiler.Compilable2 compileBody, Java.Block finallY) Generates code for a TRY statement with (possibly zero) resources and an (optional) FINALLY clause.private boolean
compileUnconditionalLoop
(Java.ContinuableStatement cs, Java.BlockStatement body, Java.Rvalue[] update) private boolean
compileUnconditionalLoopWithUpdate
(Java.ContinuableStatement cs, Java.BlockStatement body, Java.Rvalue[] update) compileUnit
(boolean debugSource, boolean debugLines, boolean debugVars) Generates an array ofClassFile
objects which represent the classes and interfaces declared in the compilation unit.private static String[]
private void
consT
(Java.Locatable locatable, double value) private void
consT
(Java.Locatable locatable, float value) private void
consT
(Java.Locatable locatable, int value) private void
consT
(Java.Locatable locatable, long value) private IClass
consT
(Java.Locatable locatable, Object value) Pushes one value on the operand stack and pushes the respectiveClassFile.StackMapTableAttribute.VerificationTypeInfo
operand to the stack map.private void
consT
(Java.Locatable locatable, String s) private void
consT
(Java.Locatable locatable, IClass iClass) private void
consT
(Java.Locatable locatable, IClass t, int value) private IClass
convertToPrimitiveNumericType
(Java.Locatable locatable, IType type) If the given type is a primitive type, return that type.private Java.Rvalue
private Java.Rvalue
"super.fld", "Type.super.fld"private void
dup
(Java.Locatable locatable) Duplicates the top operand: ...private void
dup2
(Java.Locatable locatable) Duplicates the top two operands: ...private void
dupn
(Java.Locatable locatable, int n) Duplicates the top n operands.private void
dupx
(Java.Locatable locatable) Copies the top operand one position down: b a => a b aprivate void
dupx2
(Java.Locatable locatable) Copies the top operand two positions down: c b a => a c b a.private void
dupxx
(Java.Locatable locatable, int positions) Copies the top operand positions down.private boolean
Called to check whether the givenJava.Rvalue
compiles or not.private void
Called to check whether the givenJava.Rvalue
compiles or not.private void
private IClass.IMethod
fakeIMethod
(IClass targetType, String name, Java.Rvalue[] arguments) private static void
fillConversionMap
(Object[] array, Map<String, int[]> map) Finds one class or interface declaration in this compilation unit and resolves it into anIClass
.private IClass.IField
findIField
(IClass iClass, String name, Location location) Finds a named field in the givenIClass
.private IClass.IMethod
findIMethod
(IType targetType, Java.Invocation invocation) Finds aIClass.IMethod
in the given targetType, its superclasses or superinterfaces which is applicable with the given invocation.Finds methods of the mi.
target
named mi.
methodName
, examines the argument types and chooses the most specific method.findIMethod
(Java.SuperclassMethodInvocation superclassMethodInvocation) private static Java.LocalClassDeclaration
findLocalClassDeclaration
(Java.Scope s, String name) Finds a local class declared in any block enclosing the given block statement.private IClass
findMemberType
(IType iType, String name, Java.TypeArgument[] typeArguments, Location location) Finds a named type in the givenIClass
orIParameterizedType
.findMostSpecificIInvocable
(Java.Locatable locatable, IClass.IInvocable[] iInvocables, IClass[] argumentTypes, boolean boxingPermitted, Java.Scope contextScope) Determines the applicable invocables and choose the most specific invocable.private IClass.IInvocable
findMostSpecificIInvocable
(Java.Locatable locatable, IClass.IInvocable[] iInvocables, Java.Rvalue[] arguments, Java.Scope contextScope) Determines the arguments' types, determine the applicable invocables and choose the most specific invocable and adjust arguments as needed (for varargs case).private IClass
findTypeByFullyQualifiedName
(Location location, String[] identifiers) Attempts to load anIClass
by fully-qualified name throughiClassLoader
.private IClass
findTypeByName
(Location location, String className) Finds the namedIClass
in this compilation unit, or through theiClassLoader
.private void
generateBridgeMethod
(ClassFile cf, IClass declaringIClass, IClass.IMethod base, IClass.IMethod override) Generates and compiles a bridge method with signature base that delegates to override.private boolean
Checks whether invocation ofcompile(BlockStatement)
would generate more than zero code bytes.private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private CodeContext
private static IType
getComponentType
(IType expressionType) final Object
Attempts to evaluate as a constant expression.private Object
private Object
private boolean
private Object
private char
private Object
private Object
private Object
private Object
private Object
private Object
private Object
private Object
private Object
private String
private Object
private Java.AbstractClassDeclaration
private Java.TypeBodyDeclaration
private void
getfield
(Java.Locatable locatable, IClass.IField iField) private void
getfield
(Java.Locatable locatable, IClass declaringIClass, String fieldName, IClass fieldType, boolean statiC) private IClass
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.private static IType[]
getInterfaces
(IType t1) getLocalVariable
(Java.CatchParameter parameter) getLocalVariable
(Java.FunctionDeclarator.FormalParameter parameter, boolean isVariableArityParameter) getLocalVariableTypeInfo
(short lvIndex) (package private) Java.ArrayInitializerOrRvalue
Determines the non-constant-final initializer of the givenJava.VariableDeclarator
.(package private) static Java.TypeDeclaration
getOuterClass
(Java.TypeDeclaration typeDeclaration) private static List<Java.TypeDeclaration>
Returns a list consisting of the given inner class and all its enclosing (outer) classes.private IClass
getRawReferenceType
(Location location, String simpleTypeName, Java.Scope scope) private IClass
private IType
getReferenceType
(Location location, String simpleTypeName, Java.TypeArgument[] typeArguments, Java.Scope scope) JLS7 6.5.5.1 Simple type name (single identifier)private IType
getReferenceType
(Location location, Java.Scope scope, String[] identifiers, int n, Java.TypeArgument[] typeArguments) private IType
String[]
getSingleTypeImport
(String name, Location location) Checks if the given simple name was imported through a single type import.private static IType
getSuperclass
(IType type) private IType
private int
private IType
private IType
getType
(Java.Lvalue lv) private IType
getType
(Java.Rvalue rv) private IType
private IType
private IType
private IClass
private IClass
private IClass
private IType
private IType
private IClass
private IType
private IClass
private IClass
private IClass
private IType
private IClass
private IType
private IType
private IType
private IClass
private IClass
private IClass
private IClass
private IType
private IClass
private IClass
private IClass
private IClass
private IType
private IType
private IClass
private IClass
private IType
private IType
private IClass
private IType
private IType
private IClass
private IClass
private IType
private IClass
private IType
private IClass
private IClass
private IClass
private IType[]
private IType
getUnboxedType
(IType type) private CodeContext.Offset
private void
gotO
(Java.Locatable locatable, CodeContext.Offset dst) private boolean
hasAnnotation
(Java.FunctionDeclarator fd, IClass annotationType) private void
if_acmpxx
(Java.Locatable locatable, int opIdx, CodeContext.Offset dst) private void
if_icmpxx
(Java.Locatable locatable, int opIdx, CodeContext.Offset dst) private void
ifnonnull
(Java.Locatable locatable, CodeContext.Offset dst) private void
ifnull
(Java.Locatable locatable, CodeContext.Offset dst) private void
ifNumeric
(Java.Locatable locatable, int opIdx, CodeContext.Offset dst, boolean orientation) private void
ifxx
(Java.Locatable locatable, int opIdx, CodeContext.Offset dst) private void
iinc
(Java.Locatable locatable, Java.LocalVariable lv, String operator) private static int
private static int
private static int
private static int
private static int
importSingleStatic
(String simpleName) Imports a member class, member interface, static field or static method via the compilation unit's single static import declarations.private IClass
importSingleType
(String simpleTypeName, Location location) If the given name was declared in a simple type import, load that class.private void
importStatic
(IClass declaringIClass, String simpleName, Collection<Object> result, Location location) Finds all members (member classes, member interfaces, static fields and/or static methods) of the declaringIClass with the given simpleName and adds them to the result.importStaticOnDemand
(String simpleName) Imports a member class or interface, static field or static method via the compilation unit's static import on-demand declarations.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.private IClass
importTypeOnDemand2
(String simpleTypeName, Location location) (package private) void
Compiles the instance variable initializers and the instance initializers in their lexical order.private void
instanceoF
(Java.Locatable locatable, IType rhsType) private String
internalCheckAccessible
(IClass iClassDeclaringMember, Access memberAccess, Java.Scope contextScope) private String
internalCheckAccessible
(IClass type, Java.Scope contextScope) private void
invoke
(Java.Locatable locatable, int opcode, IClass declaringIClass, String methodName, MethodDescriptor methodDescriptor, boolean useInterfaceMethodRef) Expects the target object and the arguments on the operand stack.private void
invokeConstructor
(Java.Locatable locatable, IClass.IConstructor iConstructor) Invokes the iConstructor; assumes thatthis
and the correct number and types of arguments are on the operand stack.private void
invokeConstructor
(Java.Locatable locatable, Java.Scope scope, Java.Rvalue enclosingInstance, IType targetType, Java.Rvalue[] arguments) Expects the object to initialize on the stack.private void
invokeMethod
(Java.Locatable locatable, IClass.IMethod iMethod) Invokes the iMethod; assumes thatthis
(unless iMethod is static) and the correct number and types of arguments are on the operand stack.private boolean
isAccessible
(IClass.IMember member, Java.Scope contextScope) Determines whether the givenIClass.IMember
is accessible in the given context, according to JLS7 6.6.1.BL1.B4.private boolean
isAccessible
(IClass iClassDeclaringMember, Access memberAccess, Java.Scope contextScope) Determines whether a member (class, interface, field or method) declared in a given class is accessible from a given block statement context, according to JLS7 6.6.1.4.private boolean
isAccessible
(IClass type, Java.Scope contextScope) Determines whether the givenIClass
is accessible in the given context, according to JLS7 6.6.1.2 and 6.6.1.4.private static boolean
private static boolean
isAssignableFrom
(IType targetType, IType sourceType) private IClass
isBoxingConvertible
(IType sourceType) private static Byte
private boolean
isCastReferenceConvertible
(IType sourceType, IType targetType) JLS7 5.5private boolean
isConvertibleToPrimitiveNumeric
(IType sourceType) private boolean
isIdentityConvertible
(IType sourceType, IType targetType) Checks whether "identity conversion" (5.1.1) is possible.private static boolean
isInterface
(IType type) (package private) Java.LocalVariable
Checks whether the operand is anint
local variable.private boolean
isMethodInvocationConvertible
(IClass sourceType, IClass targetType, boolean boxingPermitted) Checks if "method invocation conversion" (5.3) is possible.private boolean
isNarrowingPrimitiveConvertible
(IType sourceType, IType targetType) Checks whether "narrowing primitive conversion" (JLS7 5.1.3) is possible.private boolean
isNarrowingReferenceConvertible
(IType sourceType, IType targetType) Checks whether "narrowing reference conversion" (JLS7 5.1.5) is possible.private static boolean
isPrimitive
(IType type) private static boolean
private boolean
private boolean
private boolean
private IClass
isUnboxingConvertible
(IType sourceType) private boolean
isWideningPrimitiveConvertible
(IClass sourceType, IType targetType) private boolean
isWideningReferenceConvertible
(IType sourceType, IType targetType) Checks if "widening reference conversion" (5.1.4) is possible.private void
l2i
(Java.Locatable locatable) private static String
private void
Cleans up the statement context.private void
private void
private void
private void
leaveStatements
(Java.Scope from, Java.Scope to) Statements that jump out of blocks (return
,break
,continue
) must call this method to make sure that thefinally
clauses of alltry ... catch
andsynchronized
statements are executed.private void
load
(Java.Locatable locatable, IType localVariableType, int localVariableIndex) private IType
load
(Java.Locatable locatable, Java.LocalVariable localVariable) private void
lookupswitch
(Java.Locatable locatable, SortedMap<Integer, CodeContext.Offset> caseLabelMap, CodeContext.Offset switchOffset, CodeContext.Offset defaultLabelOffset) private static void
Makes the variable name and class name Constant Pool names used by local variables.private static String[]
Only strings that can be UTF8-encoded into 65535 bytes can be stored as a constant string info.private void
maybeCreateInitMethod
(Java.TypeDeclaration td, ClassFile cf, List<Java.BlockStatement> statements) Creates class/interface initialization method iff there is any initialization code.private static boolean
mayHaveSideEffects
(Java.Rvalue... rvalues) private void
monitorenter
(Java.Locatable locatable) private void
monitorexit
(Java.Locatable locatable) private void
mulDivRemAddSub
(Java.Locatable locatable, String operator) private void
multianewarray
(Java.Locatable locatable, int dimExprCount, int dims, IType componentType) private void
neg
(Java.Locatable locatable, IClass operandType) private void
neW
(Java.Locatable locatable, IType iType) private void
newarray
(Java.Locatable locatable, IType componentType) private IClass
newArray
(Java.Locatable locatable, int dimExprCount, int dims, IType componentType) Expects dimExprCount values of typeint
on the operand stack.private ClassFile
newClassFile
(short accessFlags, IClass iClass, IClass superclass, IClass[] interfaces) private void
numericPromotion
(Java.Locatable locatable, IType sourceType, IClass targetType) options()
options
(EnumSet<JaninoOption> options) Sets the options for all future compilations.private boolean
overridesMethod
(IClass.IMethod method, IClass type) private boolean
private void
pop
(Java.Locatable locatable, IType type) private void
putfield
(Java.Locatable locatable, IClass.IField iField) private static IClass
private static IClass[]
rawTypesOf
(IType[] iTypes) private Java.Atom
private Java.Atom
reclassifyName
(Location location, Java.Scope scope, String identifier) JLS7 6.5.2.1private Java.Atom
reclassifyName
(Location location, Java.Scope scope, String[] identifiers, int n) Reclassifies the ambiguous name consisting of the first n of the identifiers (JLS7 6.5.2.2).private void
referenceThis
(Java.Locatable locatable, IClass currentIClass) private void
referenceThis
(Java.Locatable locatable, Java.AbstractTypeDeclaration declaringType, Java.TypeBodyDeclaration declaringTypeBodyDeclaration, IType targetIType) private CodeContext
replaceCodeContext
(CodeContext newCodeContext) private IClass
private void
returN
(Java.Locatable locatable) private void
reverseUnaryNumericPromotion
(Java.Locatable locatable, IClass sourceType, IType targetType) void
setCompileErrorHandler
(ErrorHandler compileErrorHandler) By default,CompileException
s are thrown on compile errors, but an application my install its own (thread-local)ErrorHandler
.void
setTargetVersion
(int version) Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's-target
command line option.void
setWarningHandler
(WarningHandler warningHandler) By default, warnings are discarded, but an application my install a customWarningHandler
.private void
shift
(Java.Locatable locatable, String operator) private void
store
(Java.Locatable locatable, IType lvType, short lvIndex) private void
store
(Java.Locatable locatable, Java.LocalVariable localVariable) Assigns the top operand to the given local variable.private void
stringConversion
(Java.Locatable locatable, IType sourceType) Converts object of type "sourceType" to type "String" (JLS7 15.18.1.1).private void
sub
(Java.Locatable locatable) private void
swap
(Java.Locatable locatable) private void
tableswitch
(Java.Locatable locatable, SortedMap<Integer, CodeContext.Offset> caseLabelMap, CodeContext.Offset switchOffset, CodeContext.Offset defaultLabelOffset) private IClass.IAnnotation
toIAnnotation
(Java.Annotation annotation) private IClass.IAnnotation[]
toIAnnotations
(Java.Annotation[] annotations) (package private) IClass.IConstructor
toIConstructor
(Java.ConstructorDeclarator constructorDeclarator) private IClass.IInvocable
toIMethod
(Java.MethodDeclarator methodDeclarator) private Java.Lvalue
private Java.Rvalue
private Java.Type
private boolean
tryAssignmentConversion
(Java.Locatable locatable, IType sourceType, IType targetType, Object constantValue) private boolean
tryBoxingConversion
(Java.Locatable locatable, IType sourceType, IType targetType) private boolean
tryCastConversion
(Java.Locatable locatable, IType sourceType, IType targetType, Object constantValue) private boolean
tryConstantAssignmentConversion
(Java.Locatable locatable, Object constantValue, IType targetType) Checks if "constant assignment conversion" (JLS7 5.2, paragraph 1) is possible.private boolean
tryIdentityConversion
(IType sourceType, IType targetType) Implements "identity conversion" (5.1.1).private boolean
tryNarrowingPrimitiveConversion
(Java.Locatable locatable, IType sourceType, IType targetType) Implements "narrowing primitive conversion" (JLS7 5.1.3).private boolean
tryNarrowingReferenceConversion
(Java.Locatable locatable, IType sourceType, IType targetType) Implements "narrowing reference conversion" (5.1.5).private boolean
tryWideningPrimitiveConversion
(Java.Locatable locatable, IType sourceType, IType targetType) Implements "widening primitive conversion" (5.1.2).private IType
private IClass
unaryNumericPromotion
(Java.Locatable locatable, IType type) Implements "unary numeric promotion" (JLS7 5.6.1).private IClass
unaryNumericPromotionType
(Java.Locatable locatable, IType type) private void
unboxingConversion
(Java.Locatable locatable, IType sourceType, IClass targetType) private static String
Decodes any escape sequences like\n
, or\377
, but not\uxxxx
.private void
updateLocalVariableInCurrentStackMap
(short lvIndex, ClassFile.StackMapTableAttribute.VerificationTypeInfo vti) verificationTypeInfo
(IType type) private void
Issues a warning with the given message an location an returns.private void
write
(int v) private void
writeByte
(int v) private void
writeConstantClassInfo
(IClass iClass) private void
writeConstantFieldrefInfo
(IClass iClass, String fieldName, IClass fieldType) private void
writeConstantInterfaceMethodrefInfo
(IClass iClass, String methodName, MethodDescriptor methodMd) private void
writeConstantMethodrefInfo
(IClass iClass, String methodName, MethodDescriptor methodMd) private void
writeInt
(int v) private void
writeLdc
(short constantPoolIndex) private void
writeLdc2
(short constantPoolIndex) private void
writeOffset
(CodeContext.Offset src, CodeContext.Offset dst) private void
writeShort
(int v) private void
writeUnsignedShort
(int v) private void
xaload
(Java.Locatable locatable, IType componentType) private void
xor
(Java.Locatable locatable, int opcode) private void
xreturn
(Java.Locatable locatable, IType returnType)
-
Field Details
-
LOGGER
-
disassembleClassFilesToStdout
private static final boolean disassembleClassFilesToStdout -
defaultTargetVersion
private static final int defaultTargetVersion -
STRING_CONCAT_LIMIT
private static final int STRING_CONCAT_LIMITThis constant determines the number of operands up to which thea.concat(b).concat(c)
strategy is used to implement string concatenation. For more operands, the
new StringBuilder(a).append(b).append(c).append(d).toString()
strategy is chosen.A very good article from Tom Gibara analyzes the impact of this decision and recommends a value of three.
- See Also:
-
JUMP_IF_TRUE
public static final boolean JUMP_IF_TRUESpecial value for the orientation parameter of thecompileBoolean(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.- See Also:
-
JUMP_IF_FALSE
public static final boolean JUMP_IF_FALSESpecial value for the orientation parameter of thecompileBoolean(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.- See Also:
-
LOOKS_LIKE_TYPE_PARAMETER
-
options
-
targetVersion
private int targetVersionJava version to compile for. -
MAY_HAVE_SIDE_EFFECTS_VISITOR
-
NOT_CONSTANT
Special return value for thegetConstantValue(Java.Rvalue)
method family indicating that the givenJava.Rvalue
does not evaluate to a constant value. -
TWO_E_31_INTEGER
2147483648 is the special value that can not be stored in an INT, but its negated value (-2147483648) can. -
TWO_E_63_LONG
9223372036854775808 is the special value that can not be stored in a LONG, but its negated value (-9223372036854775808) can. -
singleTypeImports
To be used only bygetSingleTypeImport(String, Location)
;null
means "not yet initialized" -
onDemandImportableTypes
-
PRIMITIVE_WIDENING_CONVERSIONS
-
PRIMITIVE_NARROWING_CONVERSIONS
-
EQ
private static final int EQ- See Also:
-
NE
private static final int NE- See Also:
-
LT
private static final int LT- See Also:
-
GE
private static final int GE- See Also:
-
GT
private static final int GT- See Also:
-
LE
private static final int LE- See Also:
-
codeContext
-
compileErrorHandler
-
compileErrorCount
private int compileErrorCount -
warningHandler
-
abstractCompilationUnit
-
iClassLoader
-
generatedClassFiles
Non-null
whilecompileUnit(boolean, boolean, boolean)
is executing. -
debugSource
private boolean debugSource -
debugLines
private boolean debugLines -
debugVars
private boolean debugVars
-
-
Constructor Details
-
UnitCompiler
public UnitCompiler(Java.AbstractCompilationUnit abstractCompilationUnit, IClassLoader iClassLoader)
-
-
Method Details
-
options
- Returns:
- A reference to the currently effective compilation options; changes to it take effect immediately
-
options
Sets the options for all future compilations. -
setTargetVersion
public void setTargetVersion(int version) Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's-target
command line option. By default, Java 6 .class files are generated. -
getAbstractCompilationUnit
- Returns:
- The
Java.AbstractCompilationUnit
that thisUnitCompiler
compiles
-
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
Compiles an (ordinary, not modular) compilation unit- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile
- Throws:
CompileException
-
compile2
Compiles a top-level class or enum declaration.- Throws:
CompileException
-
compile2
Compiles a top-level interface or annotation type declaration.- Throws:
CompileException
-
checkForNameConflictWithAnotherPackageMemberTypeDeclaration
private void checkForNameConflictWithAnotherPackageMemberTypeDeclaration(Java.PackageMemberTypeDeclaration pmtd) throws CompileException - Throws:
CompileException
-
checkForConflictWithSingleTypeImport
private void checkForConflictWithSingleTypeImport(String name, Location location) throws CompileException - Throws:
CompileException
-
compile2
- Throws:
CompileException
-
addClassFile
Adds the givenClassFile
to the result set. -
addFields
Creates and addsClassFile.FieldInfo
s to the cf for all fields declared by the fd.- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
fakeCompileVariableDeclaratorsAndInitializers
private void fakeCompileVariableDeclaratorsAndInitializers(Java.AbstractClassDeclaration cd) throws CompileException - Throws:
CompileException
-
compile2
- Throws:
CompileException
-
newClassFile
private ClassFile newClassFile(short accessFlags, IClass iClass, @Nullable IClass superclass, IClass[] interfaces) throws CompileException - Parameters:
superclass
-null
forObject
,Object
for interfaces- Throws:
CompileException
-
compileAnnotations
private void compileAnnotations(Java.Annotation[] annotations, Annotatable target, ClassFile cf) throws CompileException Converts and adds the annotations to the target.- Throws:
CompileException
-
compileElementValue
private ClassFile.ElementValue compileElementValue(Java.ElementValue elementValue, ClassFile cf) throws CompileException - Throws:
CompileException
-
maybeCreateInitMethod
private void maybeCreateInitMethod(Java.TypeDeclaration td, ClassFile cf, List<Java.BlockStatement> statements) throws CompileException Creates class/interface initialization method iff there is any initialization code.- Parameters:
td
- The type declarationcf
- The class file into which to put the methodstatements
- The statements for the method (possibly empty)- Throws:
CompileException
-
compileDeclaredMemberTypes
private void compileDeclaredMemberTypes(Java.TypeDeclaration decl, ClassFile cf) throws CompileException Compiles all of the types for this declarationNB: as a side effect this will fill in the synthetic field map
- Throws:
CompileException
-
compileDeclaredMethods
private void compileDeclaredMethods(Java.TypeDeclaration typeDeclaration, ClassFile cf) throws CompileException Compiles all of the methods for this declarationNB: as a side effect this will fill in the synthetic field map </p
- Throws:
CompileException
-
compileDeclaredMethods
private void compileDeclaredMethods(Java.TypeDeclaration typeDeclaration, ClassFile cf, int startPos) throws CompileException Compiles methods for this declaration starting at startPos.- Parameters:
startPos
- Starting parameter to fill in- Throws:
CompileException
-
hasAnnotation
private boolean hasAnnotation(Java.FunctionDeclarator fd, IClass annotationType) throws CompileException - Throws:
CompileException
-
overridesMethodFromSupertype
- Throws:
CompileException
-
overridesMethod
- Returns:
- Whether method overrides a method of type or any of its supertypes
- Throws:
CompileException
-
generateBridgeMethod
private void generateBridgeMethod(ClassFile cf, IClass declaringIClass, IClass.IMethod base, IClass.IMethod override) throws CompileException Generates and compiles a bridge method with signature base that delegates to override.- Throws:
CompileException
-
compile
- Returns:
- Whether this statement can complete normally (JLS7 14.1)
- Throws:
CompileException
-
fakeCompile
Called to check whether the givenJava.Rvalue
compiles or not.- Returns:
- Whether the block statement can complete normally
- Throws:
CompileException
-
getCodeContext
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compileStatements
private boolean compileStatements(List<? extends Java.BlockStatement> statements) throws CompileException - Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compileUnconditionalLoop
private boolean compileUnconditionalLoop(Java.ContinuableStatement cs, Java.BlockStatement body, @Nullable Java.Rvalue[] update) throws CompileException - Throws:
CompileException
-
compileUnconditionalLoopWithUpdate
private boolean compileUnconditionalLoopWithUpdate(Java.ContinuableStatement cs, Java.BlockStatement body, Java.Rvalue[] update) throws CompileException - Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
findLocalClassDeclaration
@Nullable private static Java.LocalClassDeclaration findLocalClassDeclaration(Java.Scope s, String name) Finds a local class declared in any block enclosing the given block statement. -
compile2
- Throws:
CompileException
-
verificationTypeInfo
private ClassFile.StackMapTableAttribute.VerificationTypeInfo verificationTypeInfo(@Nullable IType type) -
getLocalVariable
public Java.LocalVariable getLocalVariable(Java.LocalVariableDeclarationStatement lvds, Java.VariableDeclarator vd) throws CompileException - Returns:
- The
Java.LocalVariable
corresponding with the local variable declaration/declarator - Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compileTryCatchFinallyWithResources
private boolean compileTryCatchFinallyWithResources(Java.TryStatement ts, List<Java.TryStatement.Resource> resources, UnitCompiler.Compilable2 compileBody, @Nullable Java.Block finallY) throws CompileException Generates code for a TRY statement with (possibly zero) resources and an (optional) FINALLY clause.- Returns:
- Whether the code can complete normally
- Throws:
CompileException
-
compileTryCatchFinally
private boolean compileTryCatchFinally(Java.TryStatement ts, UnitCompiler.Compilable2 compileBody, @Nullable Java.BlockStatement finallY) throws CompileException Generates code for a TRY statement without resources, but with an (optional) FINALLY clause.- Returns:
- Whether the code can complete normally
- Throws:
CompileException
-
compileTryCatch
private boolean compileTryCatch(Java.TryStatement tryStatement, UnitCompiler.Compilable2 compileBody, CodeContext.Offset beginningOfBody, CodeContext.Offset afterStatement) throws CompileException Generates code for a TRY statement without resources and without a FINALLY clause.- Returns:
- Whether the code can complete normally
- Throws:
CompileException
-
compile
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
getTargetVersion
private int getTargetVersion() -
makeLocalVariableNames
Makes the variable name and class name Constant Pool names used by local variables. -
buildLocalVariableMap
- Throws:
CompileException
-
buildLocalVariableMap
private Map<String,Java.LocalVariable> buildLocalVariableMap(Java.BlockStatement blockStatement, Map<String, Java.LocalVariable> localVars) throws CompileExceptionComputes and fills in the 'local variable map' for the given blockStatement.- Throws:
CompileException
-
buildLocalVariableMap
private static Map<String,Java.LocalVariable> buildLocalVariableMap(Java.Statement s, Map<String, Java.LocalVariable> localVars) -
buildLocalVariableMap
private static Map<String,Java.LocalVariable> buildLocalVariableMap(Java.ConstructorInvocation ci, Map<String, Java.LocalVariable> localVars) -
buildLocalVariableMap
private void buildLocalVariableMap(Java.Block block, Map<String, Java.LocalVariable> localVars) throws CompileException- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.DoStatement ds, Map<String, Java.LocalVariable> localVars) throws CompileException- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.ForStatement fs, Map<String, Java.LocalVariable> localVars) throws CompileException- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.ForEachStatement fes, Map<String, Java.LocalVariable> localVars) throws CompileException- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.IfStatement is, Map<String, Java.LocalVariable> localVars) throws CompileException- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.Initializer i, Map<String, Java.LocalVariable> localVars) throws CompileException- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.SwitchStatement ss, Map<String, Java.LocalVariable> localVars) throws CompileException- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.SynchronizedStatement ss, Map<String, Java.LocalVariable> localVars) throws CompileException- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.TryStatement ts, Map<String, Java.LocalVariable> localVars) throws CompileException- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.WhileStatement ws, Map<String, Java.LocalVariable> localVars) throws CompileException- Throws:
CompileException
-
buildLocalVariableMap
private Map<String,Java.LocalVariable> buildLocalVariableMap(Java.LabeledStatement ls, Map<String, Java.LocalVariable> localVars) throws CompileException- Throws:
CompileException
-
buildLocalVariableMap
private Map<String,Java.LocalVariable> buildLocalVariableMap(Java.LocalVariableDeclarationStatement lvds, Map<String, Java.LocalVariable> localVars) throws CompileException- Throws:
CompileException
-
buildLocalVariableMap
protected void buildLocalVariableMap(Java.CatchClause catchClause, Map<String, Java.LocalVariable> localVars) throws CompileExceptionAdds the given localVars to the 'local variable map' of the given catchClause.- Throws:
CompileException
-
getLocalVariable
public Java.LocalVariable getLocalVariable(Java.FunctionDeclarator.FormalParameter parameter) throws CompileException - Returns:
- The
Java.LocalVariable
corresponding with the parameter - Throws:
CompileException
-
getLocalVariable
public Java.LocalVariable getLocalVariable(Java.FunctionDeclarator.FormalParameter parameter, boolean isVariableArityParameter) throws CompileException - Parameters:
isVariableArityParameter
- Whether the parameter is the last parameter of a 'variable arity' (a.k.a. 'varargs') method declaration- Returns:
- The
Java.LocalVariable
corresponding with the parameter - Throws:
CompileException
-
getLocalVariable
- Returns:
- The
Java.LocalVariable
corresponding with the parameter - Throws:
CompileException
-
fakeCompile
Called to check whether the givenJava.Rvalue
compiles or not.- Throws:
CompileException
-
compile
SomeJava.Rvalue
s compile more efficiently when their value is not needed, e.g. "i++".- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compileBoolean
private void compileBoolean(Java.Rvalue rv, CodeContext.Offset dst, boolean orientation) throws CompileException Compiles anJava.Rvalue
and branches, depending on the value.Many
Java.Rvalue
s compile more efficiently when their value is the condition for a branch, thus this method generally produces more efficient bytecode thancompile(Rvalue)
followed by#branch(Locatable, int, Offset)
.Notice that if rv is a constant, then either dst is never branched to, or it is unconditionally branched to; "Unexamined code" errors may result during bytecode validation.
- Parameters:
rv
- The value that determines whether to branch or notdst
- Where to jumporientation
-JUMP_IF_TRUE
orJUMP_IF_FALSE
- Throws:
CompileException
-
compileBoolean2
private void compileBoolean2(Java.Rvalue rv, CodeContext.Offset dst, boolean orientation) throws CompileException - Parameters:
dst
- Where to jumporientation
-JUMP_IF_TRUE
orJUMP_IF_FALSE
- Throws:
CompileException
-
compileBoolean2
private void compileBoolean2(Java.UnaryOperation ue, CodeContext.Offset dst, boolean orientation) throws CompileException - Parameters:
dst
- Where to jumporientation
-JUMP_IF_TRUE
orJUMP_IF_FALSE
- Throws:
CompileException
-
compileBoolean2
private void compileBoolean2(Java.BinaryOperation bo, CodeContext.Offset dst, boolean orientation) throws CompileException - Parameters:
dst
- Where to jumporientation
-JUMP_IF_TRUE
orJUMP_IF_FALSE
- Throws:
CompileException
-
compileBoolean2
private void compileBoolean2(Java.ParenthesizedExpression pe, CodeContext.Offset dst, boolean orientation) throws CompileException - Parameters:
dst
- Where to jumporientation
-JUMP_IF_TRUE
orJUMP_IF_FALSE
- Throws:
CompileException
-
compileContext
Generates code that determines the context of theJava.Rvalue
and puts it on the operand stack. Most expressions do not have a "context", but some do. E.g. for "x[y]", the context is "x, y". The bottom line is that for statements like "x[y] += 3" the context is only evaluated once.- Returns:
- The number of operands that is pushed on the operand stack (0, 1 or 2)
- Throws:
CompileException
-
compileContext2
-
compileContext2
- Throws:
CompileException
-
compileContext2
- Throws:
CompileException
-
compileContext2
- Throws:
CompileException
-
compileContext2
Array access expression; see JLS7 15.13 / JLS8+ 15.10.3.- Throws:
CompileException
-
compileContext2
- Throws:
CompileException
-
compileContext2
- Throws:
CompileException
-
compileContext2
- Throws:
CompileException
-
compileGet
Generates code that determines the value of theJava.Rvalue
and puts it on the operand stack. This method relies on that the "context" of theJava.Rvalue
is on top of the operand stack (seecompileContext(Rvalue)
).- Returns:
- The type of the
Java.Rvalue
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
-
compileGet2
- Throws:
CompileException
-
compileGet2
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
commonSupertype
- Throws:
CompileException
-
commonSupertype2
- Throws:
CompileException
-
isByteConstant
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
getComponentType
-
isPrimitive
-
getSuperclass
- Throws:
CompileException
-
isInterface
-
getInterfaces
- Throws:
CompileException
-
isArray
-
isAssignableFrom
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
isStaticContext
-
mayHaveSideEffects
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGetValue
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGetValue
Convenience function that callscompileContext(Rvalue)
andcompileGet(Rvalue)
.- Returns:
- The type of the Rvalue
- Throws:
CompileException
-
getConstantValue
Attempts to evaluate as a constant expression. The result is one of the following:Boolean
,Byte
,Short
,Integer
,Long
,Float
,Double
,Character
,String
,null
(representing thenull
literal.This method cannot be STATIC, because the constant value may refer to a constant declaration in this compilation unit.
- Returns:
NOT_CONSTANT
iff the rvalue is not a constant value- Throws:
CompileException
-
getConstantValue2
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Returns:
- An
Integer
or aLong
- Throws:
CompileException
-
getConstantValue2
- Returns:
- A
Float
or aDouble
- Throws:
CompileException
-
getConstantValue2
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
-
getConstantValue2
-
generatesCode
Checks whether invocation ofcompile(BlockStatement)
would generate more than zero code bytes.- Throws:
CompileException
-
generatesCode2
-
generatesCode2
-
generatesCode2
-
generatesCode2
-
generatesCode2
- Throws:
CompileException
-
generatesCode2
- Throws:
CompileException
-
generatesCode2
- Throws:
CompileException
-
generatesCode2
- Throws:
CompileException
-
leave
Cleans up the statement context. This is currently relevant for "try ... catch ... finally
" statements (executefinally
clause) andsynchronized
statements (monitorexit).Statements like
return
,break
,continue
must call this method for all the statements they terminate.- Throws:
CompileException
-
leave2
-
leave2
-
leave2
- Throws:
CompileException
-
compileSet
Generates code that stores a value in theJava.Lvalue
. Expects theJava.Lvalue
's context (seecompileContext(org.codehaus.janino.Java.Rvalue)
) and a value of theJava.Lvalue
's type on the operand stack.- Throws:
CompileException
-
compileSet2
- Throws:
CompileException
-
compileSet2
-
compileSet2
- Throws:
CompileException
-
compileSet2
- Throws:
CompileException
-
compileSet2
- Throws:
CompileException
-
compileSet2
- Throws:
CompileException
-
compileSet2
- Throws:
CompileException
-
getType
- Returns:
- For a
Java.Type
, the resolvedIClass
, for anJava.Rvalue
, the resolvedIClass
of the rvalue's type - Throws:
CompileException
- See Also:
-
rawTypeOf
-
rawTypesOf
-
getRawType
- Throws:
CompileException
-
getType
- Throws:
CompileException
-
getTypes
- Throws:
CompileException
-
getType
- Throws:
CompileException
-
getType
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
-
getType2
-
getType2
- Throws:
CompileException
-
getReferenceType
@Nullable private IType getReferenceType(Location location, Java.Scope scope, String[] identifiers, int n, @Nullable Java.TypeArgument[] typeArguments) throws CompileException - Parameters:
typeArguments
- Zero-length array if type has no type variables- Returns:
- The resolved
IClass
, orIParameterizedType
, ornull
- Throws:
CompileException
-
getReferenceType
private IType getReferenceType(Location location, String simpleTypeName, @Nullable Java.TypeArgument[] typeArguments, Java.Scope scope) throws CompileException JLS7 6.5.5.1 Simple type name (single identifier)- Parameters:
typeArguments
- Zero-length array if type is not parameterized- Returns:
- The resolved
IClass
orIParameterizedType
- Throws:
CompileException
-
typeArgumentToIType
- Throws:
CompileException
-
getRawReferenceType
private IClass getRawReferenceType(Location location, String simpleTypeName, Java.Scope scope) throws CompileException - Throws:
CompileException
-
importStaticOnDemand
Imports a member class or interface, static field or static method via the compilation unit's static import on-demand declarations.- Returns:
- A list of
IClass.IField
s,IClass.IMethod
s and/orIClass
es with that simpleName; may be empty - Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
-
getType2
- Throws:
CompileException
-
getType2
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
-
getType2
- Throws:
CompileException
-
getUnboxedType
- Returns:
- The type, or, iff type is a primitive wrapper type, the unwrapped type
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
-
getType2
-
getType2
-
getType2
-
getType2
-
getType2
-
getType2
-
isType
- Throws:
CompileException
-
isType2
-
isType2
- Throws:
CompileException
-
isAccessible
private boolean isAccessible(IClass.IMember member, Java.Scope contextScope) throws CompileException Determines whether the givenIClass.IMember
is accessible in the given context, according to JLS7 6.6.1.BL1.B4. Issues acompileError(String)
if not.- Throws:
CompileException
-
checkAccessible
private void checkAccessible(IClass.IMember member, Java.Scope contextScope, Location location) throws CompileException Checks whether the givenIClass.IMember
is accessible in the given context, according to JLS7 6.6.1.BL1.B4. Issues acompileError(String)
if not.- Throws:
CompileException
-
isAccessible
private boolean isAccessible(IClass iClassDeclaringMember, Access memberAccess, Java.Scope contextScope) throws CompileException Determines whether a member (class, interface, field or method) declared in a given class is accessible from a given block statement context, according to JLS7 6.6.1.4.- Throws:
CompileException
-
checkMemberAccessible
private void checkMemberAccessible(IClass iClassDeclaringMember, IClass.IMember member, Java.Scope contextScope, Location location) throws CompileException Verifies that a member (class, interface, field or method) declared in a given class is accessible from a given block statement context, according to JLS7 6.6.1.4. Issue acompileError(String)
if not.- Throws:
CompileException
-
internalCheckAccessible
@Nullable private String internalCheckAccessible(IClass iClassDeclaringMember, Access memberAccess, Java.Scope contextScope) throws CompileException - Returns:
- a descriptive text iff a member declared in that
IClass
with thatAccess
is inaccessible - Throws:
CompileException
-
isAccessible
Determines whether the givenIClass
is accessible in the given context, according to JLS7 6.6.1.2 and 6.6.1.4.- Throws:
CompileException
-
checkAccessible
private void checkAccessible(IClass type, Java.Scope contextScope, Location location) throws CompileException Checks whether the givenIClass
is accessible in the given context, according to JLS7 6.6.1.2 and 6.6.1.4. Issues acompileError(String)
if not.- Throws:
CompileException
-
internalCheckAccessible
@Nullable private String internalCheckAccessible(IClass type, Java.Scope contextScope) throws CompileException - Returns:
- An error message, or
null
- Throws:
CompileException
-
toTypeOrCompileException
- Throws:
CompileException
-
toRvalueOrCompileException
- Throws:
CompileException
-
toLvalueOrCompileException
- Throws:
CompileException
-
assignSyntheticParametersToSyntheticFields
void assignSyntheticParametersToSyntheticFields(Java.ConstructorDeclarator cd) throws CompileException Copies the values of the synthetic parameters of this constructor ("this$..." and "val$...") to the synthetic fields of the object ("this$..." and "val$...").- Throws:
CompileException
-
initializeInstanceVariablesAndInvokeInstanceInitializers
void initializeInstanceVariablesAndInvokeInstanceInitializers(Java.ConstructorDeclarator cd) throws CompileException Compiles the instance variable initializers and the instance initializers in their lexical order.- Throws:
CompileException
-
leaveStatements
Statements that jump out of blocks (return
,break
,continue
) must call this method to make sure that thefinally
clauses of alltry ... catch
andsynchronized
statements are executed.- Throws:
CompileException
-
compileArithmeticBinaryOperation
private IType compileArithmeticBinaryOperation(Java.Locatable locatable, IType lhsType, String operator, Java.Rvalue rhs) throws CompileException The LHS operand of type lhsType is expected on the stack.The following operators are supported:
| ^ & * / % + - << >> >>>
- Throws:
CompileException
-
compileArithmeticOperation
private IType compileArithmeticOperation(Java.Locatable locatable, @Nullable IType firstOperandType, Iterator<Java.Rvalue> operands, String operator) throws CompileException Executes an arithmetic operation on a sequence of operands. If type is non-null
, then the first operand with that type is already on the stack.The following operators are supported:
| ^ & * / % + - << >> >>>
- Throws:
CompileException
-
compileStringConcatenation
private IClass compileStringConcatenation(Java.Locatable locatable, IType type, Java.Rvalue secondOperand, Iterator<Java.Rvalue> operands) throws CompileException - Parameters:
type
- The type of the first operand, which is already on the stacksecondOperand
- The second operandoperands
- All following operands- Throws:
CompileException
-
stringConversion
Converts object of type "sourceType" to type "String" (JLS7 15.18.1.1).- Throws:
CompileException
-
invokeConstructor
private void invokeConstructor(Java.Locatable locatable, Java.Scope scope, @Nullable Java.Rvalue enclosingInstance, IType targetType, Java.Rvalue[] arguments) throws CompileException Expects the object to initialize on the stack.Notice: This method is used both for explicit constructor invocation (first statement of a constructor body) and implicit constructor invocation (right after NEW).
- Parameters:
enclosingInstance
- Used if the target class is an inner class- Throws:
CompileException
-
compileFields
- Returns:
- The
IClass.IField
s that are declared by the fieldDeclaration
-
compileField
private IClass.IField compileField(Java.TypeDeclaration declaringType, Java.Annotation[] annotations, Access access, boolean statiC, boolean finaL, Java.Type type, int brackets, String name, @Nullable Java.ArrayInitializerOrRvalue initializer) Compiles one variable declarator into anIClass.IField
.Example: "b" in in the variable declaration
class Foo { @Deprecated private int[] a, b[], c; }
- Parameters:
declaringType
- "class Foo
"type
- "int[]
"
-
getNonConstantFinalInitializer
@Nullable Java.ArrayInitializerOrRvalue getNonConstantFinalInitializer(Java.FieldDeclaration fd, Java.VariableDeclarator vd) throws CompileException Determines the non-constant-final initializer of the givenJava.VariableDeclarator
.- Returns:
null
if the variable is declared without an initializer or if the initializer is constant-final- Throws:
CompileException
-
reclassify
- Throws:
CompileException
-
toIAnnotations
- Throws:
CompileException
-
toIAnnotation
- Throws:
CompileException
-
reclassifyName
private Java.Atom reclassifyName(Location location, Java.Scope scope, String[] identifiers, int n) throws CompileException Reclassifies the ambiguous name consisting of the first n of the identifiers (JLS7 6.5.2.2).- Throws:
CompileException
-
findTypeByName
@Nullable private IClass findTypeByName(Location location, String className) throws CompileException Finds the namedIClass
in this compilation unit, or through theiClassLoader
.- Parameters:
className
- Fully qualified class name, e.g. "pkg1.pkg2.Outer$Inner"- Returns:
null
iff anIClass
with that name could not be loaded- Throws:
CompileException
- An exception was raised while loading theIClass
-
reclassifyName
private Java.Atom reclassifyName(Location location, Java.Scope scope, String identifier) throws CompileException JLS7 6.5.2.1- Throws:
CompileException
-
importSingleStatic
Imports a member class, member interface, static field or static method via the compilation unit's single static import declarations.- Returns:
- A list of
IClass.IField
s,IClass.IMethod
s and/orIClass
es with that simpleName; may be empty - Throws:
CompileException
-
importStatic
private void importStatic(IClass declaringIClass, String simpleName, Collection<Object> result, Location location) throws CompileException Finds all members (member classes, member interfaces, static fields and/or static methods) of the declaringIClass with the given simpleName and adds them to the result.- Parameters:
declaringIClass
- The class or interface that declares the membersresult
- Results (IClass
es,IClass.IField
s and/orIClass.IMethod
s) are added to this collection- Throws:
CompileException
-
determineValue
- Returns:
- Either the
Java.FieldAccess
or anJava.ArrayLength
- Throws:
CompileException
-
determineValue
private Java.Rvalue determineValue(Java.SuperclassFieldAccessExpression scfae) throws CompileException "super.fld", "Type.super.fld"- Throws:
CompileException
-
findIMethod
Finds methods of the mi.
target
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.- Returns:
- The selected
IClass.IMethod
- Throws:
CompileException
-
findIMethod
@Nullable private IClass.IMethod findIMethod(IType targetType, Java.Invocation invocation) throws CompileException Finds aIClass.IMethod
in the given targetType, its superclasses or superinterfaces which is applicable with the given invocation. If more than one such method exists, chooses the most specific one (JLS7 15.11.2).- Returns:
null
if no appropriate method could be found- Throws:
CompileException
-
fakeIMethod
private IClass.IMethod fakeIMethod(IClass targetType, String name, Java.Rvalue[] arguments) throws CompileException - Throws:
CompileException
-
getIMethods
public void getIMethods(IClass type, String methodName, List<IClass.IMethod> v) throws CompileException Adds all methods with the given methodName that are declared by the type, its superclasses and all their superinterfaces to the result list v.- Throws:
CompileException
-
findIMethod
public IClass.IMethod findIMethod(Java.SuperclassMethodInvocation superclassMethodInvocation) throws CompileException - Returns:
- The
IClass.IMethod
that implements the superclassMethodInvocation - Throws:
CompileException
-
findMostSpecificIInvocable
private IClass.IInvocable findMostSpecificIInvocable(Java.Locatable locatable, IClass.IInvocable[] iInvocables, Java.Rvalue[] arguments, Java.Scope contextScope) throws CompileException Determines the arguments' types, determine the applicable invocables and choose the most specific invocable and adjust arguments as needed (for varargs case).- Parameters:
iInvocables
- Length must be greater than zero- Returns:
- The selected
IClass.IInvocable
- Throws:
CompileException
-
findMostSpecificIInvocable
@Nullable public IClass.IInvocable findMostSpecificIInvocable(Java.Locatable locatable, IClass.IInvocable[] iInvocables, IClass[] argumentTypes, boolean boxingPermitted, Java.Scope contextScope) throws CompileException Determines the applicable invocables and choose the most specific invocable.- Returns:
- The maximally specific
IClass.IInvocable
ornull
if noIClass.IInvocable
is applicable - Throws:
CompileException
-
assertNonNull
-
isMethodInvocationConvertible
private boolean isMethodInvocationConvertible(IClass sourceType, IClass targetType, boolean boxingPermitted) throws CompileException Checks if "method invocation conversion" (5.3) is possible.- Throws:
CompileException
-
checkThrownExceptions
private void checkThrownExceptions(Java.Invocation in, IClass.IMethod iMethod) throws CompileException - Throws:
CompileException
- if theJava.Invocation
throws exceptions that are disallowed in the given scope
-
checkThrownException
private void checkThrownException(Java.Locatable locatable, IType type, Java.Scope scope) throws CompileException - Throws:
CompileException
- The exception with the given type must not be thrown in the given scope
-
getTargetIType
- Throws:
CompileException
-
isIntLv
Checks whether the operand is anint
local variable.- Returns:
null
iff c is not anint
local variable- Throws:
CompileException
-
resolve
-
referenceThis
private void referenceThis(Java.Locatable locatable, Java.AbstractTypeDeclaration declaringType, Java.TypeBodyDeclaration declaringTypeBodyDeclaration, IType targetIType) throws CompileException - Throws:
CompileException
-
getOuterClasses
Returns a list consisting of the given inner class and all its enclosing (outer) classes.- Returns:
List
ofJava.TypeDeclaration
; has length one iff inner has no enclosing instance
-
getOuterClass
- Returns:
- The
Java.TypeDeclaration
that immediately encloses the typeDeclaration, ornull
-
getIClass
- Throws:
CompileException
-
getReturnType
- Throws:
CompileException
-
toIConstructor
- Returns:
- the
IClass.IConstructor
that implements the constructorDeclarator
-
toIMethod
- Returns:
- The
IClass.IMethod
that implements the methodDeclarator
-
toIInvocable
-
importSingleType
@Nullable private IClass importSingleType(String simpleTypeName, Location location) throws CompileException If the given name was declared in a simple type import, load that class.- Throws:
CompileException
-
getSingleTypeImport
@Nullable public String[] getSingleTypeImport(String name, Location location) throws CompileException Checks 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
@Nullable public IClass importTypeOnDemand(String simpleTypeName, Location location) throws CompileException 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 given simpleTypeName cannot be resolved through any of the type-import-on-demand declarations- Throws:
CompileException
-
importTypeOnDemand2
@Nullable private IClass importTypeOnDemand2(String simpleTypeName, Location location) throws CompileException - Returns:
null
if the given simpleTypeName cannot be resolved through any of the type-import-on-demand declarations- Throws:
CompileException
-
getTypeImportOnDemandImportDeclarations
private Collection<Java.AbstractCompilationUnit.TypeImportOnDemandDeclaration> getTypeImportOnDemandImportDeclarations() -
consT
Pushes one value on the operand stack and pushes the respectiveClassFile.StackMapTableAttribute.VerificationTypeInfo
operand to the stack map.value Operand stack value Verification type info Character
Byte
Short
Integer
Boolean
int
integer_variable_info
Float
float
float_variable_info
Long
msb+lsb
oflong
long_variable_info
Double
msb+lsb
ofdouble
double_variable_info
String
ConstantStringInfo
CP indexobject_variable_info(String)
IClass
ConstantClassInfo
CP indexobject_variable_info(iClass.descriptor())
null
null
null_variable_info(iClass.descriptor())
- Returns:
- The computational type of the value that was pushed, e.g.
IClass.INT
forByte
orIClass.VOID
fornull
- Throws:
CompileException
-
makeUtf8Able
Only strings that can be UTF8-encoded into 65535 bytes can be stored as a constant string info.- Parameters:
s
- The string to split into suitable chunks- Returns:
- Strings that can be UTF8-encoded into 65535 bytes
-
consT
-
consT
-
consT
-
consT
-
consT
-
consT
-
consT
-
castConversion
private void castConversion(Java.Locatable locatable, IType sourceType, IType targetType, @Nullable Object constantValue) throws CompileException - Throws:
CompileException
-
tryCastConversion
private boolean tryCastConversion(Java.Locatable locatable, IType sourceType, IType targetType, @Nullable Object constantValue) throws CompileException - Throws:
CompileException
-
assignmentConversion
private void assignmentConversion(Java.Locatable locatable, IType sourceType, IType targetType, @Nullable Object constantValue) throws CompileException Implements "assignment conversion" (JLS7 5.2).- Throws:
CompileException
-
tryAssignmentConversion
private boolean tryAssignmentConversion(Java.Locatable locatable, IType sourceType, IType targetType, @Nullable Object constantValue) throws CompileException - Throws:
CompileException
-
assignmentConversion
@Nullable private Object assignmentConversion(Java.Locatable locatable, @Nullable Object value, IType targetType) throws CompileException Implements "assignment conversion" (JLS7 5.2) on a constant value. -
unaryNumericPromotion
Implements "unary numeric promotion" (JLS7 5.6.1).- Returns:
- The promoted type
- Throws:
CompileException
-
reverseUnaryNumericPromotion
private void reverseUnaryNumericPromotion(Java.Locatable locatable, IClass sourceType, IType targetType) throws CompileException - Throws:
CompileException
-
convertToPrimitiveNumericType
private IClass convertToPrimitiveNumericType(Java.Locatable locatable, IType type) throws CompileException If the given type is a primitive type, return that type. If the given type is a primitive wrapper class, unbox the operand on top of the operand stack and return the primitive type. Otherwise, issue a compile error.- Throws:
CompileException
-
numericPromotion
-
unaryNumericPromotionType
private IClass unaryNumericPromotionType(Java.Locatable locatable, IType type) throws CompileException - Throws:
CompileException
-
binaryNumericPromotionType
private IClass binaryNumericPromotionType(Java.Locatable locatable, IType type1, IType type2) throws CompileException - Throws:
CompileException
-
isIdentityConvertible
Checks whether "identity conversion" (5.1.1) is possible.- Returns:
- Whether the conversion is possible
-
tryIdentityConversion
Implements "identity conversion" (5.1.1).- Returns:
- Whether the conversion was possible
-
isWideningPrimitiveConvertible
-
tryWideningPrimitiveConversion
private boolean tryWideningPrimitiveConversion(Java.Locatable locatable, IType sourceType, IType targetType) Implements "widening primitive conversion" (5.1.2).- Returns:
- Whether the conversion succeeded
-
fillConversionMap
-
isWideningReferenceConvertible
private boolean isWideningReferenceConvertible(IType sourceType, IType targetType) throws CompileException Checks if "widening reference conversion" (5.1.4) is possible.- Returns:
- Whether the conversion is possible
- Throws:
CompileException
-
isNarrowingPrimitiveConvertible
Checks whether "narrowing primitive conversion" (JLS7 5.1.3) is possible. -
tryNarrowingPrimitiveConversion
private boolean tryNarrowingPrimitiveConversion(Java.Locatable locatable, IType sourceType, IType targetType) Implements "narrowing primitive conversion" (JLS7 5.1.3).- Returns:
- Whether the conversion succeeded
-
tryConstantAssignmentConversion
private boolean tryConstantAssignmentConversion(Java.Locatable locatable, @Nullable Object constantValue, IType targetType) throws CompileException Checks if "constant assignment conversion" (JLS7 5.2, paragraph 1) is possible.- Parameters:
constantValue
- The constant value that is to be convertedtargetType
- The type to convert to- Throws:
CompileException
-
isNarrowingReferenceConvertible
private boolean isNarrowingReferenceConvertible(IType sourceType, IType targetType) throws CompileException Checks whether "narrowing reference conversion" (JLS7 5.1.5) is possible.- Throws:
CompileException
-
tryNarrowingReferenceConversion
private boolean tryNarrowingReferenceConversion(Java.Locatable locatable, IType sourceType, IType targetType) throws CompileException Implements "narrowing reference conversion" (5.1.5).- Returns:
- Whether the conversion succeeded
- Throws:
CompileException
-
isCastReferenceConvertible
private boolean isCastReferenceConvertible(IType sourceType, IType targetType) throws CompileException JLS7 5.5- Throws:
CompileException
-
isBoxingConvertible
- Returns:
- The boxed type or
null
-
tryBoxingConversion
private boolean tryBoxingConversion(Java.Locatable locatable, IType sourceType, IType targetType) throws CompileException - Throws:
CompileException
-
boxingConversion
private void boxingConversion(Java.Locatable locatable, IType sourceType, IType targetType) throws CompileException - Parameters:
sourceType
- a primitive type (except VOID)targetType
- the corresponding wrapper type- Throws:
CompileException
-
isUnboxingConvertible
- Returns:
- Iff sourceType is a primitive wrapper type, the unboxed type, otherwise
null
-
isConvertibleToPrimitiveNumeric
- Returns:
- Whether the sourceType is a primitive numeric type, or a wrapper type of a primitive numeric type
-
unboxingConversion
private void unboxingConversion(Java.Locatable locatable, IType sourceType, IClass targetType) throws CompileException - Parameters:
targetType
- a primitive type (except VOID)sourceType
- the corresponding wrapper type- Throws:
CompileException
-
findTypeByFullyQualifiedName
@Nullable private IClass findTypeByFullyQualifiedName(Location location, String[] identifiers) throws CompileException Attempts to load anIClass
by fully-qualified name throughiClassLoader
.- Parameters:
identifiers
- The fully qualified type name, e.g. '{ "pkg", "Outer", "Inner" }
'- Returns:
null
if a class with the given name could not be loaded- Throws:
CompileException
- The type exists, but a problem occurred when it was loaded
-
ifNumeric
private void ifNumeric(Java.Locatable locatable, int opIdx, CodeContext.Offset dst, boolean orientation) - Parameters:
opIdx
- One ofEQ
,NE
,LT
,GE
,GT
orLE
orientation
-JUMP_IF_TRUE
orJUMP_IF_FALSE
-
aconstnull
-
add
-
andOrXor
-
anewarray
-
arraylength
-
arraystore
-
athrow
-
checkcast
-
cmp
-
dup
Duplicates the top operand: ... a => ... a a -
dup2
Duplicates the top two operands: ... a b => ... a b a b. This works iff both the top operand and the top-but-one operand have size 1. -
dupn
Duplicates the top n operands.- n == 0
- (nothing)
- n == 1
- ... a => ... a a
- n == 2
- ... a b => ... a b a b
-
dupx
Copies the top operand one position down: b a => a b a -
dupx2
Copies the top operand two positions down: c b a => a c b a. This works iff the top-but-one and top-but-two operands both have size 1. -
dupxx
Copies the top operand positions down.- n == 0
- ... a => ... a a
- n == 1
- ... b a => ... a b a
- n == 2
- ... c b a => ... a c b a
-
getfield
- Throws:
CompileException
-
getfield
private void getfield(Java.Locatable locatable, IClass declaringIClass, String fieldName, IClass fieldType, boolean statiC) -
gotO
- Parameters:
opcode
- One of IF* and GOTO
-
if_acmpxx
-
if_icmpxx
-
ifnonnull
-
ifnull
-
ifxx
-
iinc
- Parameters:
operator
- Must be either "++" or "--", as an @linkinterned
string
-
instanceoF
-
invoke
private void invoke(Java.Locatable locatable, int opcode, IClass declaringIClass, String methodName, MethodDescriptor methodDescriptor, boolean useInterfaceMethodRef) Expects the target object and the arguments on the operand stack. -
l2i
-
load
-
load
-
lookupswitch
private void lookupswitch(Java.Locatable locatable, SortedMap<Integer, CodeContext.Offset> caseLabelMap, CodeContext.Offset switchOffset, CodeContext.Offset defaultLabelOffset) -
monitorenter
-
monitorexit
-
mulDivRemAddSub
- Parameters:
operator
- One of* / % + -
-
multianewarray
private void multianewarray(Java.Locatable locatable, int dimExprCount, int dims, IType componentType) -
neg
- Parameters:
operandType
- One of BYTE, CHAR, INT, SHORT, LONG, BOOLEAN, LONG, FLOAT, DOUBLE
-
neW
-
newarray
-
pop
-
putfield
- Throws:
CompileException
-
returN
-
shift
- Parameters:
operator
- One of<< >> >>>
-
store
Assigns the top operand to the given local variable. -
store
- Parameters:
lvIndex
- (two slots for LONG and DOUBLE local variables)
-
sub
-
swap
-
tableswitch
private void tableswitch(Java.Locatable locatable, SortedMap<Integer, CodeContext.Offset> caseLabelMap, CodeContext.Offset switchOffset, CodeContext.Offset defaultLabelOffset) -
xaload
-
xor
-
xreturn
-
ilfd
- Parameters:
t
- One of BYTE, CHAR, INT, SHORT, LONG, BOOLEAN, LONG, FLOAT, DOUBLE
-
ilfd
-
ilfda
-
il
-
ilfdabcs
-
findIField
@Nullable private IClass.IField findIField(IClass iClass, String name, Location location) throws CompileException Finds a named field in the givenIClass
. Honors superclasses and interfaces. See JLS7 8.3.- Returns:
null
if no field is found- Throws:
CompileException
-
findMemberType
@Nullable private IClass findMemberType(IType iType, String name, @Nullable Java.TypeArgument[] typeArguments, Location location) throws CompileException Finds a named type in the givenIClass
orIParameterizedType
. Honors superclasses, interfaces and enclosing type declarations.- Returns:
null
if no type with the given name is found- Throws:
CompileException
-
findClass
Finds one class or interface declaration in this compilation unit and resolves it into anIClass
.- 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
-
compileError
Equivalent withcompileError(String, Location)
with anull
location argument.- Throws:
CompileException
-
compileError
Issues a compile error with the given message. This is done through theErrorHandler
that was installed throughsetCompileErrorHandler(ErrorHandler)
. Such a handler typically throws aCompileException
, but it may as well decide to return normally. Consequently, the calling code must be prepared thatcompileError(String, Location)
returns normally, and must attempt to continue compiling.- Parameters:
message
- The message to reportlocation
- The location to report- Throws:
CompileException
-
warning
private void warning(String handle, String message, @Nullable Location location) throws CompileException Issues a warning with the given message an location an returns. This is done through aWarningHandler
that was installed throughsetWarningHandler(WarningHandler)
.The handle argument qualifies the warning and is typically used by the
WarningHandler
to suppress individual warnings.- Throws:
CompileException
-
setCompileErrorHandler
By default,CompileException
s 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 aCompileException
when a limit is reached.If the given
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: TheErrorHandler
may throw aCompileException
or not, butcompileUnit(boolean, boolean, boolean)
will definitely throw aCompileException
if one or more compile errors have occurred.- Parameters:
compileErrorHandler
-null
to restore the default behavior (throwing aCompileException
)
-
setWarningHandler
By default, warnings are discarded, but an application my install a customWarningHandler
.- Parameters:
warningHandler
-null
to indicate that no warnings be issued
-
replaceCodeContext
-
addLineNumberOffset
-
write
private void write(int v) -
writeByte
private void writeByte(int v) -
writeShort
private void writeShort(int v) -
writeUnsignedShort
private void writeUnsignedShort(int v) -
writeInt
private void writeInt(int v) -
writeLdc
private void writeLdc(short constantPoolIndex) -
writeLdc2
private void writeLdc2(short constantPoolIndex) -
invokeMethod
Invokes the iMethod; assumes thatthis
(unless iMethod is static) and the correct number and types of arguments are on the operand stack.- Throws:
CompileException
-
invokeConstructor
private void invokeConstructor(Java.Locatable locatable, IClass.IConstructor iConstructor) throws CompileException Invokes the iConstructor; assumes thatthis
and the correct number and types of arguments are on the operand stack.- Throws:
CompileException
-
writeOffset
-
addConstantStringInfo
-
addConstantIntegerInfo
private short addConstantIntegerInfo(int value) -
addConstantLongInfo
private short addConstantLongInfo(long value) -
addConstantFloatInfo
private short addConstantFloatInfo(float value) -
addConstantDoubleInfo
private short addConstantDoubleInfo(double value) -
addConstantClassInfo
-
addConstantFieldrefInfo
-
addConstantMethodrefInfo
-
addConstantInterfaceMethodrefInfo
-
writeConstantClassInfo
-
writeConstantFieldrefInfo
-
writeConstantMethodrefInfo
private void writeConstantMethodrefInfo(IClass iClass, String methodName, MethodDescriptor methodMd) -
writeConstantInterfaceMethodrefInfo
private void writeConstantInterfaceMethodrefInfo(IClass iClass, String methodName, MethodDescriptor methodMd) -
getWhereToBreak
-
getDeclaringTypeBodyDeclaration
private Java.TypeBodyDeclaration getDeclaringTypeBodyDeclaration(Java.QualifiedThisReference qtr) throws CompileException - Throws:
CompileException
-
getDeclaringClass
private Java.AbstractClassDeclaration getDeclaringClass(Java.QualifiedThisReference qtr) throws CompileException - Throws:
CompileException
-
referenceThis
-
newArray
Expects dimExprCount values of typeint
on the operand stack. Creates an array of dimExprCount+
dims dimensions of componentType.- Returns:
- The type of the created array
-
last
-
allButLast
-
concat
-
compileException
-
unescape
Decodes any escape sequences like\n
, or\377
, but not\uxxxx
.- Returns:
- s, with all escape sequences replaced with their literal values
- Throws:
CompileException
- s contains an invalid escape sequenceIndexOutOfBoundsException
- sends with a backslash
-
accessFlags
- Throws:
CompileException
-
accessModifiers
-
changeAccessibility
private static short changeAccessibility(short accessFlags, short newAccessibility) -
getLocalVariableTypeInfo
private ClassFile.StackMapTableAttribute.VerificationTypeInfo getLocalVariableTypeInfo(short lvIndex) - Parameters:
lvIndex
- (two slots for LONG and DOUBLE local variables)
-
updateLocalVariableInCurrentStackMap
private void updateLocalVariableInCurrentStackMap(short lvIndex, ClassFile.StackMapTableAttribute.VerificationTypeInfo vti)
-