Class UnitCompiler
- java.lang.Object
-
- org.codehaus.janino.UnitCompiler
-
public class UnitCompiler extends java.lang.Object
This class actually implements the Java compiler. It is associated with exactly one compilation unit which it compiles.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interface
UnitCompiler.Compilable
Helper interface for string conversion.(package private) static interface
UnitCompiler.Compilable2
Interface for delayed code generation.static class
UnitCompiler.SimpleIField
Short-hand implementation ofIClass.IField
that implements a non-constant, non-static, package-accessible field.private static class
UnitCompiler.SwitchKind
-
Field Summary
Fields Modifier and Type Field Description private Java.AbstractCompilationUnit
abstractCompilationUnit
private CodeContext
codeContext
private int
compileErrorCount
private ErrorHandler
compileErrorHandler
private boolean
debugLines
private boolean
debugSource
private boolean
debugVars
private static int
defaultTargetVersion
private static boolean
disassembleClassFilesToStdout
private static int
EQ
private static int
GE
private java.util.List<ClassFile>
generatedClassFiles
Non-null
whilecompileUnit(boolean, boolean, boolean)
is executing.private static int
GT
private IClassLoader
iClassLoader
static boolean
JUMP_IF_FALSE
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 boolean
JUMP_IF_TRUE
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 int
LE
private static java.util.logging.Logger
LOGGER
private static java.util.regex.Pattern
LOOKS_LIKE_TYPE_PARAMETER
private static int
LT
private static Visitor.RvalueVisitor<java.lang.Boolean,java.lang.RuntimeException>
MAY_HAVE_SIDE_EFFECTS_VISITOR
private static int
NE
static java.lang.Object
NOT_CONSTANT
Special return value for thegetConstantValue(Java.Rvalue)
method family indicating that the givenJava.Rvalue
does not evaluate to a constant value.private java.util.Map<java.lang.String,IClass>
onDemandImportableTypes
private java.util.EnumSet<JaninoOption>
options
private static java.util.Map<java.lang.String,int[]>
PRIMITIVE_NARROWING_CONVERSIONS
private static java.util.Map<java.lang.String,int[]>
PRIMITIVE_WIDENING_CONVERSIONS
private java.util.Map<java.lang.String,java.lang.String[]>
singleTypeImports
To be used only bygetSingleTypeImport(String, Location)
;null
means "not yet initialized"private static int
STRING_CONCAT_LIMIT
This constant determines the number of operands up to which theprivate int
targetVersion
private static java.util.regex.Pattern
TWO_E_31_INTEGER
2147483648 is the special value that can not be stored in an INT, but its negated value (-2147483648) can.private static java.util.regex.Pattern
TWO_E_63_LONG
9223372036854775808 is the special value that can not be stored in a LONG, but its negated value (-9223372036854775808) can.private WarningHandler
warningHandler
-
Constructor Summary
Constructors Constructor Description UnitCompiler(Java.AbstractCompilationUnit abstractCompilationUnit, IClassLoader iClassLoader)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private short
accessFlags(Java.Modifier[] modifiers)
private static Java.Modifier[]
accessModifiers(Location location, java.lang.String... keywords)
private void
aconstnull(Java.Locatable locatable)
private void
add(Java.Locatable locatable)
private void
addClassFile(ClassFile cf)
Adds the givenClassFile
to the result set.private short
addConstantClassInfo(IClass iClass)
private short
addConstantDoubleInfo(double value)
private short
addConstantFieldrefInfo(IClass iClass, java.lang.String fieldName, IClass fieldType)
private short
addConstantFloatInfo(float value)
private short
addConstantIntegerInfo(int value)
private short
addConstantInterfaceMethodrefInfo(IClass iClass, java.lang.String methodName, java.lang.String methodFd)
private short
addConstantLongInfo(long value)
private short
addConstantMethodrefInfo(IClass iClass, java.lang.String methodName, java.lang.String methodFd)
private short
addConstantStringInfo(java.lang.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 java.lang.String[]
allButLast(java.lang.String[] sa)
private void
andOrXor(Java.Locatable locatable, java.lang.String operator)
private void
anewarray(Java.Locatable locatable, IClass componentType)
private void
arraylength(Java.Locatable locatable)
private void
arraystore(Java.Locatable locatable, IClass lhsComponentType)
private static <T> T
assertNonNull(T subject)
private java.lang.Object
assignmentConversion(Java.Locatable locatable, java.lang.Object value, IClass targetType)
Implements "assignment conversion" (JLS7 5.2) on a constant value.private void
assignmentConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, java.lang.Object constantValue)
Implements "assignment conversion" (JLS7 5.2).(package private) void
assignSyntheticParametersToSyntheticFields(Java.ConstructorDeclarator cd)
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, IClass type1, IClass type2)
private void
boxingConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
private void
buildLocalVariableMap(Java.Block block, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private java.util.Map<java.lang.String,Java.LocalVariable>
buildLocalVariableMap(Java.BlockStatement blockStatement, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
Computes and fills in the 'local variable map' for the given blockStatement.protected void
buildLocalVariableMap(Java.CatchClause catchClause, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
Adds the given localVars to the 'local variable map' of the given catchClause.private static java.util.Map<java.lang.String,Java.LocalVariable>
buildLocalVariableMap(Java.ConstructorInvocation ci, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.DoStatement ds, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.ForEachStatement fes, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.ForStatement fs, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.FunctionDeclarator fd)
private void
buildLocalVariableMap(Java.IfStatement is, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.Initializer i, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private java.util.Map<java.lang.String,Java.LocalVariable>
buildLocalVariableMap(Java.LabeledStatement ls, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private java.util.Map<java.lang.String,Java.LocalVariable>
buildLocalVariableMap(Java.LocalVariableDeclarationStatement lvds, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private static java.util.Map<java.lang.String,Java.LocalVariable>
buildLocalVariableMap(Java.Statement s, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.SwitchStatement ss, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.SynchronizedStatement ss, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.TryStatement ts, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
buildLocalVariableMap(Java.WhileStatement ws, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
private void
castConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, java.lang.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, IClass targetType)
private void
checkForConflictWithSingleTypeImport(java.lang.String name, Location location)
private void
checkForNameConflictWithAnotherPackageMemberTypeDeclaration(Java.PackageMemberTypeDeclaration pmtd)
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, IClass type, Java.Scope scope)
private void
checkThrownExceptions(Java.Invocation in, IClass.IMethod iMethod)
private void
cmp(Java.Locatable locatable, int opIdx)
private IClass
commonSupertype(IClass t1, IClass t2)
private IClass
commonSupertype2(IClass t1, IClass t2)
private boolean
compile(Java.BlockStatement bs)
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
compile(Java.TypeDeclaration td)
private void
compile2(Java.AbstractClassDeclaration cd)
private boolean
compile2(Java.AlternateConstructorInvocation aci)
private void
compile2(Java.AnonymousClassDeclaration acd)
private boolean
compile2(Java.AssertStatement as)
private void
compile2(Java.Assignment a)
private boolean
compile2(Java.Block b)
private boolean
compile2(Java.BreakStatement bs)
private void
compile2(Java.CompilationUnit cu)
Compiles an (ordinary, not modular) compilation unitprivate boolean
compile2(Java.ContinueStatement cs)
private void
compile2(Java.Crement c)
private boolean
compile2(Java.DoStatement ds)
private boolean
compile2(Java.EmptyStatement es)
private boolean
compile2(Java.ExpressionStatement ee)
private boolean
compile2(Java.FieldDeclaration fd)
private boolean
compile2(Java.ForEachStatement fes)
private boolean
compile2(Java.ForStatement fs)
private void
compile2(Java.FunctionDeclarator fd, ClassFile classFile)
private boolean
compile2(Java.IfStatement is)
private boolean
compile2(Java.Initializer i)
private void
compile2(Java.InnerClassDeclaration icd)
private void
compile2(Java.InterfaceDeclaration id)
private boolean
compile2(Java.LabeledStatement ls)
private void
compile2(Java.LocalClassDeclaration lcd)
private boolean
compile2(Java.LocalClassDeclarationStatement lcds)
private boolean
compile2(Java.LocalVariableDeclarationStatement lvds)
private void
compile2(Java.ModularCompilationUnit mcu)
private void
compile2(Java.PackageMemberClassDeclaration pmcd)
Compiles a top-level class or enum declaration.private void
compile2(Java.PackageMemberInterfaceDeclaration pmid)
Compiles a top-level interface or annotation type declaration.private void
compile2(Java.ParenthesizedExpression pe)
private boolean
compile2(Java.ReturnStatement rs)
private void
compile2(Java.Rvalue rv)
private boolean
compile2(Java.SuperConstructorInvocation sci)
private boolean
compile2(Java.SwitchStatement ss)
private boolean
compile2(Java.SynchronizedStatement ss)
private boolean
compile2(Java.ThrowStatement ts)
private boolean
compile2(Java.TryStatement ts)
private boolean
compile2(Java.WhileStatement ws)
private void
compileAnnotations(Java.Annotation[] annotations, Annotatable target, ClassFile cf)
Converts and adds the annotations to the target.private IClass
compileArithmeticBinaryOperation(Java.Locatable locatable, IClass lhsType, java.lang.String operator, Java.Rvalue rhs)
The LHS operand of type lhsType is expected on the stack.private IClass
compileArithmeticOperation(Java.Locatable locatable, IClass firstOperandType, java.util.Iterator<Java.Rvalue> operands, java.lang.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
compileContext(Java.Rvalue rv)
Generates code that determines the context of theJava.Rvalue
and puts it on the operand stack.private int
compileContext2(Java.AmbiguousName an)
private int
compileContext2(Java.ArrayAccessExpression aae)
Array access expression; see JLS7 15.13 / JLS8+ 15.10.3.private int
compileContext2(Java.ArrayLength al)
private int
compileContext2(Java.FieldAccess fa)
private int
compileContext2(Java.FieldAccessExpression fae)
private int
compileContext2(Java.ParenthesizedExpression pe)
private int
compileContext2(Java.Rvalue rv)
private int
compileContext2(Java.SuperclassFieldAccessExpression scfae)
private void
compileDeclaredMemberTypes(Java.TypeDeclaration decl, ClassFile cf)
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(java.lang.String message)
Equivalent withcompileError(String, Location)
with anull
location argument.private void
compileError(java.lang.String message, Location location)
Issues a compile error with the given message.private static CompileException
compileException(Java.Locatable locatable, java.lang.String message)
private IClass.IField
compileField(Java.TypeDeclaration declaringType, Java.Annotation[] annotations, Access access, boolean statiC, boolean finaL, Java.Type type, int brackets, java.lang.String name, Java.ArrayInitializerOrRvalue initializer)
Compiles one variable declarator into anIClass.IField
.private IClass.IField[]
compileFields(Java.FieldDeclaration fieldDeclaration)
private IClass
compileGet(Java.Rvalue rv)
Generates code that determines the value of theJava.Rvalue
and puts it on the operand stack.private IClass
compileGet2(Java.AmbiguousName an)
private IClass
compileGet2(Java.ArrayAccessExpression aae)
private IClass
compileGet2(Java.ArrayCreationReference acr)
private IClass
compileGet2(Java.ArrayLength al)
private IClass
compileGet2(Java.Assignment a)
private IClass
compileGet2(Java.BinaryOperation bo)
private IClass
compileGet2(Java.BooleanRvalue brv)
private IClass
compileGet2(Java.Cast c)
private IClass
compileGet2(Java.ClassInstanceCreationReference cicr)
private IClass
compileGet2(Java.ClassLiteral cl)
private IClass
compileGet2(Java.ConditionalExpression ce)
private IClass
compileGet2(Java.Crement c)
private IClass
compileGet2(Java.FieldAccess fa)
private IClass
compileGet2(Java.FieldAccessExpression fae)
private IClass
compileGet2(Java.Instanceof io)
private IClass
compileGet2(Java.LambdaExpression le)
private IClass
compileGet2(Java.Literal l)
private IClass
compileGet2(Java.LocalVariableAccess lva)
private IClass
compileGet2(Java.MethodInvocation mi)
private IClass
compileGet2(Java.MethodReference mr)
private IClass
compileGet2(Java.NewAnonymousClassInstance naci)
private IClass
compileGet2(Java.NewArray na)
private IClass
compileGet2(Java.NewClassInstance nci)
private IClass
compileGet2(Java.NewInitializedArray nia)
private IClass
compileGet2(Java.ParameterAccess pa)
private IClass
compileGet2(Java.ParenthesizedExpression pe)
private IClass
compileGet2(Java.QualifiedThisReference qtr)
private IClass
compileGet2(Java.SimpleConstant sl)
private IClass
compileGet2(Java.SuperclassFieldAccessExpression scfae)
private IClass
compileGet2(Java.SuperclassMethodInvocation scmi)
private IClass
compileGet2(Java.ThisReference tr)
private IClass
compileGet2(Java.UnaryOperation uo)
private void
compileGetValue(Java.ArrayInitializer ai, IClass arrayType)
private IClass
compileGetValue(Java.Rvalue rv)
Convenience function that callscompileContext(Rvalue)
andcompileGet(Rvalue)
.private void
compileSet(Java.Lvalue lv)
Generates code that stores a value in theJava.Lvalue
.private void
compileSet2(Java.AmbiguousName an)
private void
compileSet2(Java.ArrayAccessExpression aae)
private void
compileSet2(Java.FieldAccess fa)
private void
compileSet2(Java.FieldAccessExpression fae)
private void
compileSet2(Java.LocalVariableAccess lva)
private void
compileSet2(Java.ParenthesizedExpression pe)
private void
compileSet2(Java.SuperclassFieldAccessExpression scfae)
private boolean
compileStatements(java.util.List<? extends Java.BlockStatement> statements)
private IClass
compileStringConcatenation(Java.Locatable locatable, IClass type, Java.Rvalue secondOperand, java.util.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, java.util.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)
ClassFile[]
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 java.lang.String[]
concat(java.lang.String[] sa, java.lang.String s)
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, java.lang.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, java.lang.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, IClass type)
If the given type is a primitive type, return that type.private Java.Rvalue
determineValue(Java.FieldAccessExpression fae)
private Java.Rvalue
determineValue(Java.SuperclassFieldAccessExpression scfae)
"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
fakeCompile(Java.BlockStatement bs)
Called to check whether the givenJava.Rvalue
compiles or not.private void
fakeCompile(Java.Rvalue rv)
Called to check whether the givenJava.Rvalue
compiles or not.private void
fakeCompileVariableDeclaratorsAndInitializers(Java.AbstractClassDeclaration cd)
private IClass.IMethod
fakeIMethod(IClass targetType, java.lang.String name, Java.Rvalue[] arguments)
private static void
fillConversionMap(java.lang.Object[] array, java.util.Map<java.lang.String,int[]> map)
IClass
findClass(java.lang.String className)
Finds one class or interface declaration in this compilation unit and resolves it into anIClass
.private IClass.IField
findIField(IClass iClass, java.lang.String name, Location location)
Finds a named field in the givenIClass
.private IClass.IMethod
findIMethod(IClass targetType, Java.Invocation invocation)
Finds aIClass.IMethod
in the given targetType, its superclasses or superinterfaces which is applicable with the given invocation.IClass.IMethod
findIMethod(Java.MethodInvocation mi)
Finds methods of the mi.
target
named mi.
methodName
, examines the argument types and chooses the most specific method.IClass.IMethod
findIMethod(Java.SuperclassMethodInvocation superclassMethodInvocation)
private static Java.LocalClassDeclaration
findLocalClassDeclaration(Java.Scope s, java.lang.String name)
Finds a local class declared in any block enclosing the given block statement.private IClass
findMemberType(IClass iClass, java.lang.String name, Location location)
Finds a named type in the givenIClass
.IClass.IInvocable
findMostSpecificIInvocable(Java.Locatable locatable, IClass.IInvocable[] iInvocables, IClass[] argumentTypes, boolean boxingPermitted, Java.Scope contextScope)
Determines the applicable invocables and choose the most specific invocable.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, java.lang.String[] identifiers)
Attempts to load anIClass
by fully-qualified name throughiClassLoader
.private IClass
findTypeByName(Location location, java.lang.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
generatesCode(Java.BlockStatement bs)
Checks whether invocation ofcompile(BlockStatement)
would generate more than zero code bytes.private boolean
generatesCode2(java.util.List<Java.BlockStatement> l)
private boolean
generatesCode2(Java.AssertStatement as)
private boolean
generatesCode2(Java.Block b)
private boolean
generatesCode2(Java.BlockStatement bs)
private boolean
generatesCode2(Java.EmptyStatement es)
private boolean
generatesCode2(Java.FieldDeclaration fd)
private boolean
generatesCode2(Java.Initializer i)
private boolean
generatesCode2(Java.LocalClassDeclarationStatement lcds)
Java.AbstractCompilationUnit
getAbstractCompilationUnit()
private CodeContext
getCodeContext()
java.lang.Object
getConstantValue(Java.Rvalue rv)
Attempts to evaluate as a constant expression.private java.lang.Object
getConstantValue2(Java.AmbiguousName an)
private java.lang.Object
getConstantValue2(Java.BinaryOperation bo)
private boolean
getConstantValue2(Java.BooleanLiteral bl)
private java.lang.Object
getConstantValue2(Java.Cast c)
private char
getConstantValue2(Java.CharacterLiteral cl)
private java.lang.Object
getConstantValue2(Java.ConditionalExpression ce)
private java.lang.Object
getConstantValue2(Java.FieldAccess fa)
private java.lang.Object
getConstantValue2(Java.FloatingPointLiteral fpl)
private java.lang.Object
getConstantValue2(Java.IntegerLiteral il)
private java.lang.Object
getConstantValue2(Java.LocalVariableAccess lva)
private java.lang.Object
getConstantValue2(Java.NullLiteral nl)
private java.lang.Object
getConstantValue2(Java.ParenthesizedExpression pe)
private java.lang.Object
getConstantValue2(Java.Rvalue rv)
private java.lang.Object
getConstantValue2(Java.SimpleConstant sl)
private java.lang.String
getConstantValue2(Java.StringLiteral sl)
private java.lang.Object
getConstantValue2(Java.UnaryOperation uo)
private Java.AbstractClassDeclaration
getDeclaringClass(Java.QualifiedThisReference qtr)
private Java.TypeBodyDeclaration
getDeclaringTypeBodyDeclaration(Java.QualifiedThisReference qtr)
private void
getfield(Java.Locatable locatable, IClass.IField iField)
private void
getfield(Java.Locatable locatable, IClass declaringIClass, java.lang.String fieldName, IClass fieldType, boolean statiC)
private IClass
getIClass(Java.ThisReference tr)
void
getIMethods(IClass type, java.lang.String methodName, java.util.List<IClass.IMethod> v)
Adds all methods with the given methodName that are declared by the type, its superclasses and all their superinterfaces to the result list v.Java.LocalVariable
getLocalVariable(Java.CatchParameter parameter)
Java.LocalVariable
getLocalVariable(Java.FunctionDeclarator.FormalParameter parameter)
Java.LocalVariable
getLocalVariable(Java.FunctionDeclarator.FormalParameter parameter, boolean isVariableArityParameter)
Java.LocalVariable
getLocalVariable(Java.LocalVariableDeclarationStatement lvds, Java.VariableDeclarator vd)
private ClassFile.StackMapTableAttribute.VerificationTypeInfo
getLocalVariableTypeInfo(short lvIndex)
(package private) Java.ArrayInitializerOrRvalue
getNonConstantFinalInitializer(Java.FieldDeclaration fd, Java.VariableDeclarator vd)
Determines the non-constant-final initializer of the givenJava.VariableDeclarator
.(package private) static Java.TypeDeclaration
getOuterClass(Java.TypeDeclaration typeDeclaration)
private static java.util.List<Java.TypeDeclaration>
getOuterClasses(Java.TypeDeclaration inner)
Returns a list consisting of the given inner class and all its enclosing (outer) classes.private IClass
getReferenceType(Location location, java.lang.String simpleTypeName, Java.Scope scope)
JLS7 6.5.5.1 Simple type name (single identifier)private IClass
getReferenceType(Location location, Java.Scope scope, java.lang.String[] identifiers, int n)
private IClass
getReturnType(Java.FunctionDeclarator fd)
java.lang.String[]
getSingleTypeImport(java.lang.String name, Location location)
Checks if the given simple name was imported through a single type import.private IClass
getTargetIClass(Java.QualifiedThisReference qtr)
private int
getTargetVersion()
private IClass
getType(Java.Atom a)
private IClass
getType(Java.Lvalue lv)
private IClass
getType(Java.Rvalue rv)
private IClass
getType(Java.Type t)
private IClass
getType2(Java.AmbiguousName an)
private IClass
getType2(Java.ArrayAccessExpression aae)
private IClass
getType2(Java.ArrayCreationReference acr)
private IClass
getType2(Java.ArrayLength al)
private IClass
getType2(Java.ArrayType at)
private IClass
getType2(Java.Assignment a)
private IClass
getType2(Java.BinaryOperation bo)
private IClass
getType2(Java.BooleanLiteral bl)
private IClass
getType2(Java.Cast c)
private IClass
getType2(Java.CharacterLiteral cl)
private IClass
getType2(Java.ClassInstanceCreationReference cicr)
private IClass
getType2(Java.ClassLiteral cl)
private IClass
getType2(Java.ConditionalExpression ce)
private IClass
getType2(Java.ConstructorInvocation ci)
private IClass
getType2(Java.Crement c)
private IClass
getType2(Java.FieldAccess fa)
private IClass
getType2(Java.FieldAccessExpression fae)
private IClass
getType2(Java.FloatingPointLiteral fpl)
private IClass
getType2(Java.Instanceof io)
private IClass
getType2(Java.IntegerLiteral il)
private IClass
getType2(Java.LambdaExpression le)
private IClass
getType2(Java.LocalVariableAccess lva)
private IClass
getType2(Java.MethodInvocation mi)
private IClass
getType2(Java.MethodReference mr)
private IClass
getType2(Java.NewAnonymousClassInstance naci)
private IClass
getType2(Java.NewArray na)
private IClass
getType2(Java.NewClassInstance nci)
private IClass
getType2(Java.NewInitializedArray nia)
private IClass
getType2(Java.NullLiteral nl)
private IClass
getType2(Java.Package p)
private IClass
getType2(Java.ParameterAccess pa)
private IClass
getType2(Java.ParenthesizedExpression pe)
private IClass
getType2(Java.PrimitiveType bt)
private IClass
getType2(Java.QualifiedThisReference qtr)
private IClass
getType2(Java.ReferenceType rt)
private IClass
getType2(Java.RvalueMemberType rvmt)
private IClass
getType2(Java.SimpleConstant sl)
private IClass
getType2(Java.SimpleType st)
private IClass
getType2(Java.StringLiteral sl)
private IClass
getType2(Java.SuperclassFieldAccessExpression scfae)
private IClass
getType2(Java.SuperclassMethodInvocation scmi)
private IClass
getType2(Java.ThisReference tr)
private IClass
getType2(Java.UnaryOperation uo)
private java.util.Collection<Java.AbstractCompilationUnit.TypeImportOnDemandDeclaration>
getTypeImportOnDemandImportDeclarations()
private IClass[]
getTypes(Java.Type[] types)
private IClass
getUnboxedType(IClass type)
private CodeContext.Offset
getWhereToBreak(Java.BreakableStatement bs)
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, java.lang.String operator)
private static int
il(ClassFile.StackMapTableAttribute.VerificationTypeInfo vti)
private static int
ilfd(IClass t)
private static int
ilfd(ClassFile.StackMapTableAttribute.VerificationTypeInfo vti)
private static int
ilfda(IClass t)
private static int
ilfdabcs(IClass t)
private java.util.List<java.lang.Object>
importSingleStatic(java.lang.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(java.lang.String simpleTypeName, Location location)
If the given name was declared in a simple type import, load that class.private void
importStatic(IClass declaringIClass, java.lang.String simpleName, java.util.Collection<java.lang.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.private java.util.List<java.lang.Object>
importStaticOnDemand(java.lang.String simpleName)
Imports a member class or interface, static field or static method via the compilation unit's static import on-demand declarations.IClass
importTypeOnDemand(java.lang.String simpleTypeName, Location location)
6.5.2.BL1.B1.B5, 6.5.2.BL1.B1.B6 Type-import-on-demand.
6.5.5.1.6 Type-import-on-demand declaration.private IClass
importTypeOnDemand2(java.lang.String simpleTypeName, Location location)
(package private) void
initializeInstanceVariablesAndInvokeInstanceInitializers(Java.ConstructorDeclarator cd)
Compiles the instance variable initializers and the instance initializers in their lexical order.private void
instanceoF(Java.Locatable locatable, IClass rhsType)
private java.lang.String
internalCheckAccessible(IClass iClassDeclaringMember, Access memberAccess, Java.Scope contextScope)
private java.lang.String
internalCheckAccessible(IClass type, Java.Scope contextScope)
private void
invoke(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
invoke(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 void
invokeConstructor(Java.Locatable locatable, Java.Scope scope, Java.Rvalue enclosingInstance, IClass targetClass, Java.Rvalue[] arguments)
Expects the object to initialize on the stack.private void
invokeMethod(Java.Locatable locatable, int opcode, IClass declaringIClass, java.lang.String methodName, MethodDescriptor methodDescriptor, boolean useInterfaceMethodRef)
Expects the target object and the arguments 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 IClass
isBoxingConvertible(IClass sourceType)
private static java.lang.Byte
isByteConstant(java.lang.Object o)
private boolean
isCastReferenceConvertible(IClass sourceType, IClass targetType)
JLS7 5.5private boolean
isConvertibleToPrimitiveNumeric(IClass sourceType)
private boolean
isIdentityConvertible(IClass sourceType, IClass targetType)
Checks whether "identity conversion" (5.1.1) is possible.(package private) Java.LocalVariable
isIntLv(Java.Crement c)
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(IClass sourceType, IClass targetType)
Checks whether "narrowing primitive conversion" (JLS7 5.1.3) is possible.private boolean
isNarrowingReferenceConvertible(IClass sourceType, IClass targetType)
Checks whether "narrowing reference conversion" (JLS7 5.1.5) is possible.private static boolean
isStaticContext(Java.TypeBodyDeclaration tbd)
private boolean
isType(Java.Atom a)
private boolean
isType2(Java.AmbiguousName an)
private boolean
isType2(Java.Atom a)
private IClass
isUnboxingConvertible(IClass sourceType)
private boolean
isWideningPrimitiveConvertible(IClass sourceType, IClass targetType)
private boolean
isWideningReferenceConvertible(IClass sourceType, IClass targetType)
Checks if "widening reference conversion" (5.1.4) is possible.private void
l2i(Java.Locatable locatable)
private static java.lang.String
last(java.lang.String[] sa)
private void
leave(Java.BlockStatement bs)
Cleans up the statement context.private void
leave2(Java.BlockStatement bs)
private void
leave2(Java.SynchronizedStatement ss)
private void
leave2(Java.TryStatement ts)
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, IClass localVariableType, int localVariableIndex)
private IClass
load(Java.Locatable locatable, Java.LocalVariable localVariable)
private void
lookupswitch(Java.Locatable locatable, java.util.SortedMap<java.lang.Integer,CodeContext.Offset> caseLabelMap, CodeContext.Offset switchOffset, CodeContext.Offset defaultLabelOffset)
private static void
makeLocalVariableNames(CodeContext cc, ClassFile.MethodInfo mi)
Makes the variable name and class name Constant Pool names used by local variables.private static java.lang.String[]
makeUtf8Able(java.lang.String s)
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, java.util.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, java.lang.String operator)
private void
multianewarray(Java.Locatable locatable, int dimExprCount, int dims, IClass componentType)
private void
neg(Java.Locatable locatable, IClass operandType)
private void
neW(Java.Locatable locatable, IClass iClass)
private void
newarray(Java.Locatable locatable, IClass componentType)
private IClass
newArray(Java.Locatable locatable, int dimExprCount, int dims, IClass 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, IClass sourceType, IClass targetType)
java.util.EnumSet<JaninoOption>
options()
UnitCompiler
options(java.util.EnumSet<JaninoOption> options)
Sets the options for all future compilations.private boolean
overridesMethod(IClass.IMethod method, IClass type)
private boolean
overridesMethodFromSupertype(IClass.IMethod m, IClass type)
private void
pop(Java.Locatable locatable, IClass type)
private void
putfield(Java.Locatable locatable, IClass.IField iField)
private Java.Atom
reclassify(Java.AmbiguousName an)
private Java.Atom
reclassifyName(Location location, Java.Scope scope, java.lang.String identifier)
JLS7 6.5.2.1private Java.Atom
reclassifyName(Location location, Java.Scope scope, java.lang.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.AbstractClassDeclaration declaringClass, Java.TypeBodyDeclaration declaringTypeBodyDeclaration, IClass targetIClass)
private CodeContext
replaceCodeContext(CodeContext newCodeContext)
private IClass
resolve(Java.TypeDeclaration td)
private void
returN(Java.Locatable locatable)
private void
reverseUnaryNumericPromotion(Java.Locatable locatable, IClass sourceType, IClass 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, java.lang.String operator)
private void
store(Java.Locatable locatable, IClass 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, IClass 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, java.util.SortedMap<java.lang.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
toIInvocable(Java.FunctionDeclarator fd)
IClass.IMethod
toIMethod(Java.MethodDeclarator methodDeclarator)
private Java.Lvalue
toLvalueOrCompileException(Java.Atom a)
private Java.Rvalue
toRvalueOrCompileException(Java.Atom a)
private Java.Type
toTypeOrCompileException(Java.Atom a)
private boolean
tryAssignmentConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, java.lang.Object constantValue)
private boolean
tryBoxingConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
private boolean
tryCastConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, java.lang.Object constantValue)
private boolean
tryConstantAssignmentConversion(Java.Locatable locatable, java.lang.Object constantValue, IClass targetType)
Checks if "constant assignment conversion" (JLS7 5.2, paragraph 1) is possible.private boolean
tryIdentityConversion(IClass sourceType, IClass targetType)
Implements "identity conversion" (5.1.1).private boolean
tryNarrowingPrimitiveConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
Implements "narrowing primitive conversion" (JLS7 5.1.3).private boolean
tryNarrowingReferenceConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
Implements "narrowing reference conversion" (5.1.5).private boolean
tryWideningPrimitiveConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
Implements "widening primitive conversion" (5.1.2).private IClass
unaryNumericPromotion(Java.Locatable locatable, IClass type)
Implements "unary numeric promotion" (JLS7 5.6.1).private IClass
unaryNumericPromotionType(Java.Locatable locatable, IClass type)
private void
unboxingConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
private static java.lang.String
unescape(java.lang.String s, Location location)
Decodes any escape sequences like\n
, or\377
, but not\uxxxx
.private void
updateLocalVariableInCurrentStackMap(short lvIndex, ClassFile.StackMapTableAttribute.VerificationTypeInfo vti)
private ClassFile.StackMapTableAttribute.VerificationTypeInfo
verificationTypeInfo(IClass type)
private void
warning(java.lang.String handle, java.lang.String message, Location location)
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, java.lang.String fieldName, IClass fieldType)
private void
writeConstantInterfaceMethodrefInfo(IClass iClass, java.lang.String methodName, MethodDescriptor methodMd)
private void
writeConstantMethodrefInfo(IClass iClass, java.lang.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, IClass componentType)
private void
xor(Java.Locatable locatable, int opcode)
private void
xreturn(Java.Locatable locatable, IClass returnType)
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
disassembleClassFilesToStdout
private static final boolean disassembleClassFilesToStdout
-
defaultTargetVersion
private static final int defaultTargetVersion
-
STRING_CONCAT_LIMIT
private static final int STRING_CONCAT_LIMIT
This 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:
- Constant Field Values
-
JUMP_IF_TRUE
public static final boolean JUMP_IF_TRUE
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.- See Also:
- Constant Field Values
-
JUMP_IF_FALSE
public static final boolean JUMP_IF_FALSE
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.- See Also:
- Constant Field Values
-
LOOKS_LIKE_TYPE_PARAMETER
private static final java.util.regex.Pattern LOOKS_LIKE_TYPE_PARAMETER
-
options
private java.util.EnumSet<JaninoOption> options
-
targetVersion
private int targetVersion
-
MAY_HAVE_SIDE_EFFECTS_VISITOR
private static final Visitor.RvalueVisitor<java.lang.Boolean,java.lang.RuntimeException> MAY_HAVE_SIDE_EFFECTS_VISITOR
-
NOT_CONSTANT
public static final java.lang.Object 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
private static final java.util.regex.Pattern 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
private static final java.util.regex.Pattern TWO_E_63_LONG
9223372036854775808 is the special value that can not be stored in a LONG, but its negated value (-9223372036854775808) can.
-
singleTypeImports
@Nullable private java.util.Map<java.lang.String,java.lang.String[]> singleTypeImports
To be used only bygetSingleTypeImport(String, Location)
;null
means "not yet initialized"
-
onDemandImportableTypes
private final java.util.Map<java.lang.String,IClass> onDemandImportableTypes
-
PRIMITIVE_WIDENING_CONVERSIONS
private static final java.util.Map<java.lang.String,int[]> PRIMITIVE_WIDENING_CONVERSIONS
-
PRIMITIVE_NARROWING_CONVERSIONS
private static final java.util.Map<java.lang.String,int[]> PRIMITIVE_NARROWING_CONVERSIONS
-
EQ
private static final int EQ
- See Also:
- Constant Field Values
-
NE
private static final int NE
- See Also:
- Constant Field Values
-
LT
private static final int LT
- See Also:
- Constant Field Values
-
GE
private static final int GE
- See Also:
- Constant Field Values
-
GT
private static final int GT
- See Also:
- Constant Field Values
-
LE
private static final int LE
- See Also:
- Constant Field Values
-
codeContext
@Nullable private CodeContext codeContext
-
compileErrorHandler
@Nullable private ErrorHandler compileErrorHandler
-
compileErrorCount
private int compileErrorCount
-
warningHandler
@Nullable private WarningHandler warningHandler
-
abstractCompilationUnit
private final Java.AbstractCompilationUnit abstractCompilationUnit
-
iClassLoader
private final IClassLoader iClassLoader
-
generatedClassFiles
@Nullable private java.util.List<ClassFile> generatedClassFiles
Non-null
whilecompileUnit(boolean, boolean, boolean)
is executing.
-
debugSource
private boolean debugSource
-
debugLines
private boolean debugLines
-
debugVars
private boolean debugVars
-
-
Constructor Detail
-
UnitCompiler
public UnitCompiler(Java.AbstractCompilationUnit abstractCompilationUnit, IClassLoader iClassLoader)
-
-
Method Detail
-
options
public java.util.EnumSet<JaninoOption> options()
- Returns:
- A reference to the currently effective compilation options; changes to it take effect immediately
-
options
public UnitCompiler options(java.util.EnumSet<JaninoOption> 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
public Java.AbstractCompilationUnit 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
private void compile2(Java.CompilationUnit cu) throws CompileException
Compiles an (ordinary, not modular) compilation unit- Throws:
CompileException
-
compile2
private void compile2(Java.ModularCompilationUnit mcu) throws CompileException
- Throws:
CompileException
-
compile
private void compile(Java.TypeDeclaration td) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.PackageMemberClassDeclaration pmcd) throws CompileException
Compiles a top-level class or enum declaration.- Throws:
CompileException
-
compile2
private void compile2(Java.PackageMemberInterfaceDeclaration pmid) throws CompileException
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(java.lang.String name, Location location) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.AbstractClassDeclaration cd) throws CompileException
- Throws:
CompileException
-
addFields
private void addFields(Java.FieldDeclaration fd, ClassFile cf) throws CompileException
Creates and addsClassFile.FieldInfo
s to the cf for all fields declared by the fd.- Throws:
CompileException
-
compile2
private void compile2(Java.AnonymousClassDeclaration acd) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.LocalClassDeclaration lcd) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.InnerClassDeclaration icd) throws CompileException
- Throws:
CompileException
-
fakeCompileVariableDeclaratorsAndInitializers
private void fakeCompileVariableDeclaratorsAndInitializers(Java.AbstractClassDeclaration cd) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.InterfaceDeclaration id) throws CompileException
- 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, java.util.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
- 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
private boolean overridesMethodFromSupertype(IClass.IMethod m, IClass type) throws CompileException
- Throws:
CompileException
-
overridesMethod
private boolean overridesMethod(IClass.IMethod method, IClass type) throws CompileException
- 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
private boolean compile(Java.BlockStatement bs) throws CompileException
- Returns:
- Whether this statement can complete normally (JLS7 14.1)
- Throws:
CompileException
-
fakeCompile
private boolean fakeCompile(Java.BlockStatement bs) throws CompileException
Called to check whether the givenJava.Rvalue
compiles or not.- Returns:
- Whether the block statement can complete normally
- Throws:
CompileException
-
getCodeContext
private CodeContext getCodeContext()
-
compile2
private boolean compile2(Java.Initializer i) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.Block b) throws CompileException
- Throws:
CompileException
-
compileStatements
private boolean compileStatements(java.util.List<? extends Java.BlockStatement> statements) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.DoStatement ds) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.ForStatement fs) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.ForEachStatement fes) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.WhileStatement ws) throws CompileException
- 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
private boolean compile2(Java.LabeledStatement ls) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.SwitchStatement ss) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.BreakStatement bs) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.ContinueStatement cs) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.AssertStatement as) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.EmptyStatement es)
-
compile2
private boolean compile2(Java.ExpressionStatement ee) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.FieldDeclaration fd) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.IfStatement is) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.LocalClassDeclarationStatement lcds) throws CompileException
- Throws:
CompileException
-
findLocalClassDeclaration
@Nullable private static Java.LocalClassDeclaration findLocalClassDeclaration(Java.Scope s, java.lang.String name)
Finds a local class declared in any block enclosing the given block statement.
-
compile2
private boolean compile2(Java.LocalVariableDeclarationStatement lvds) throws CompileException
- Throws:
CompileException
-
verificationTypeInfo
private ClassFile.StackMapTableAttribute.VerificationTypeInfo verificationTypeInfo(@Nullable IClass 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
private boolean compile2(Java.ReturnStatement rs) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.SynchronizedStatement ss) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.ThrowStatement ts) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.TryStatement ts) throws CompileException
- Throws:
CompileException
-
compileTryCatchFinallyWithResources
private boolean compileTryCatchFinallyWithResources(Java.TryStatement ts, java.util.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
private void compile(Java.FunctionDeclarator fd, ClassFile classFile) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.FunctionDeclarator fd, ClassFile classFile) throws CompileException
- Throws:
CompileException
-
getTargetVersion
private int getTargetVersion()
-
makeLocalVariableNames
private static void makeLocalVariableNames(CodeContext cc, ClassFile.MethodInfo mi)
Makes the variable name and class name Constant Pool names used by local variables.
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.FunctionDeclarator fd) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private java.util.Map<java.lang.String,Java.LocalVariable> buildLocalVariableMap(Java.BlockStatement blockStatement, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
Computes and fills in the 'local variable map' for the given blockStatement.- Throws:
CompileException
-
buildLocalVariableMap
private static java.util.Map<java.lang.String,Java.LocalVariable> buildLocalVariableMap(Java.Statement s, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
-
buildLocalVariableMap
private static java.util.Map<java.lang.String,Java.LocalVariable> buildLocalVariableMap(Java.ConstructorInvocation ci, java.util.Map<java.lang.String,Java.LocalVariable> localVars)
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.Block block, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.DoStatement ds, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.ForStatement fs, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.ForEachStatement fes, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.IfStatement is, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.Initializer i, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.SwitchStatement ss, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.SynchronizedStatement ss, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.TryStatement ts, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.WhileStatement ws, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private java.util.Map<java.lang.String,Java.LocalVariable> buildLocalVariableMap(Java.LabeledStatement ls, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
private java.util.Map<java.lang.String,Java.LocalVariable> buildLocalVariableMap(Java.LocalVariableDeclarationStatement lvds, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
- Throws:
CompileException
-
buildLocalVariableMap
protected void buildLocalVariableMap(Java.CatchClause catchClause, java.util.Map<java.lang.String,Java.LocalVariable> localVars) throws CompileException
Adds 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
public Java.LocalVariable getLocalVariable(Java.CatchParameter parameter) throws CompileException
- Returns:
- The
Java.LocalVariable
corresponding with the parameter - Throws:
CompileException
-
fakeCompile
private void fakeCompile(Java.Rvalue rv) throws CompileException
Called to check whether the givenJava.Rvalue
compiles or not.- Throws:
CompileException
-
compile
private void compile(Java.Rvalue rv) throws CompileException
SomeJava.Rvalue
s compile more efficiently when their value is not needed, e.g. "i++".- Throws:
CompileException
-
compile2
private void compile2(Java.Rvalue rv) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.Assignment a) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.Crement c) throws CompileException
- Throws:
CompileException
-
compile2
private void compile2(Java.ParenthesizedExpression pe) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.AlternateConstructorInvocation aci) throws CompileException
- Throws:
CompileException
-
compile2
private boolean compile2(Java.SuperConstructorInvocation sci) throws CompileException
- 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
private int compileContext(Java.Rvalue rv) throws CompileException
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
private int compileContext2(Java.Rvalue rv)
-
compileContext2
private int compileContext2(Java.AmbiguousName an) throws CompileException
- Throws:
CompileException
-
compileContext2
private int compileContext2(Java.FieldAccess fa) throws CompileException
- Throws:
CompileException
-
compileContext2
private int compileContext2(Java.ArrayLength al) throws CompileException
- Throws:
CompileException
-
compileContext2
private int compileContext2(Java.ArrayAccessExpression aae) throws CompileException
Array access expression; see JLS7 15.13 / JLS8+ 15.10.3.- Throws:
CompileException
-
compileContext2
private int compileContext2(Java.FieldAccessExpression fae) throws CompileException
- Throws:
CompileException
-
compileContext2
private int compileContext2(Java.SuperclassFieldAccessExpression scfae) throws CompileException
- Throws:
CompileException
-
compileContext2
private int compileContext2(Java.ParenthesizedExpression pe) throws CompileException
- Throws:
CompileException
-
compileGet
private IClass compileGet(Java.Rvalue rv) throws CompileException
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
private IClass compileGet2(Java.BooleanRvalue brv) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.AmbiguousName an) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.LocalVariableAccess lva)
-
compileGet2
private IClass compileGet2(Java.FieldAccess fa) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.ArrayLength al)
-
compileGet2
private IClass compileGet2(Java.ThisReference tr) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.LambdaExpression le) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.MethodReference mr) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.ClassInstanceCreationReference cicr) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.ArrayCreationReference acr) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.QualifiedThisReference qtr) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.ClassLiteral cl) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.Assignment a) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.ConditionalExpression ce) throws CompileException
- Throws:
CompileException
-
commonSupertype
private IClass commonSupertype(IClass t1, IClass t2) throws CompileException
- Throws:
CompileException
-
commonSupertype2
private IClass commonSupertype2(IClass t1, IClass t2) throws CompileException
- Throws:
CompileException
-
isByteConstant
@Nullable private static java.lang.Byte isByteConstant(@Nullable java.lang.Object o)
-
compileGet2
private IClass compileGet2(Java.Crement c) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.ArrayAccessExpression aae) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.FieldAccessExpression fae) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.SuperclassFieldAccessExpression scfae) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.UnaryOperation uo) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.Instanceof io) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.BinaryOperation bo) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.Cast c) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.ParenthesizedExpression pe) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.MethodInvocation mi) throws CompileException
- Throws:
CompileException
-
isStaticContext
private static boolean isStaticContext(Java.TypeBodyDeclaration tbd)
-
mayHaveSideEffects
private static boolean mayHaveSideEffects(Java.Rvalue... rvalues)
-
compileGet2
private IClass compileGet2(Java.SuperclassMethodInvocation scmi) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.NewClassInstance nci) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.NewAnonymousClassInstance naci) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.ParameterAccess pa) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.NewArray na) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.NewInitializedArray nia) throws CompileException
- Throws:
CompileException
-
compileGetValue
private void compileGetValue(Java.ArrayInitializer ai, IClass arrayType) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.Literal l) throws CompileException
- Throws:
CompileException
-
compileGet2
private IClass compileGet2(Java.SimpleConstant sl) throws CompileException
- Throws:
CompileException
-
compileGetValue
private IClass compileGetValue(Java.Rvalue rv) throws CompileException
Convenience function that callscompileContext(Rvalue)
andcompileGet(Rvalue)
.- Returns:
- The type of the Rvalue
- Throws:
CompileException
-
getConstantValue
@Nullable public final java.lang.Object getConstantValue(Java.Rvalue rv) throws CompileException
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
@Nullable private java.lang.Object getConstantValue2(Java.Rvalue rv)
-
getConstantValue2
@Nullable private java.lang.Object getConstantValue2(Java.AmbiguousName an) throws CompileException
- Throws:
CompileException
-
getConstantValue2
@Nullable private java.lang.Object getConstantValue2(Java.FieldAccess fa) throws CompileException
- Throws:
CompileException
-
getConstantValue2
@Nullable private java.lang.Object getConstantValue2(Java.UnaryOperation uo) throws CompileException
- Throws:
CompileException
-
getConstantValue2
@Nullable private java.lang.Object getConstantValue2(Java.ConditionalExpression ce) throws CompileException
- Throws:
CompileException
-
getConstantValue2
@Nullable private java.lang.Object getConstantValue2(Java.BinaryOperation bo) throws CompileException
- Throws:
CompileException
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.Cast c) throws CompileException
- Throws:
CompileException
-
getConstantValue2
@Nullable private java.lang.Object getConstantValue2(Java.ParenthesizedExpression pe) throws CompileException
- Throws:
CompileException
-
getConstantValue2
@Nullable private java.lang.Object getConstantValue2(Java.LocalVariableAccess lva) throws CompileException
- Throws:
CompileException
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.IntegerLiteral il) throws CompileException
- Returns:
- An
Integer
or aLong
- Throws:
CompileException
-
getConstantValue2
private java.lang.Object getConstantValue2(Java.FloatingPointLiteral fpl) throws CompileException
- Returns:
- A
Float
or aDouble
- Throws:
CompileException
-
getConstantValue2
private boolean getConstantValue2(Java.BooleanLiteral bl)
-
getConstantValue2
private char getConstantValue2(Java.CharacterLiteral cl) throws CompileException
- Throws:
CompileException
-
getConstantValue2
private java.lang.String getConstantValue2(Java.StringLiteral sl) throws CompileException
- Throws:
CompileException
-
getConstantValue2
@Nullable private java.lang.Object getConstantValue2(Java.NullLiteral nl)
-
getConstantValue2
@Nullable private java.lang.Object getConstantValue2(Java.SimpleConstant sl)
-
generatesCode
private boolean generatesCode(Java.BlockStatement bs) throws CompileException
Checks whether invocation ofcompile(BlockStatement)
would generate more than zero code bytes.- Throws:
CompileException
-
generatesCode2
private boolean generatesCode2(Java.BlockStatement bs)
-
generatesCode2
private boolean generatesCode2(Java.AssertStatement as)
-
generatesCode2
private boolean generatesCode2(Java.EmptyStatement es)
-
generatesCode2
private boolean generatesCode2(Java.LocalClassDeclarationStatement lcds)
-
generatesCode2
private boolean generatesCode2(Java.Initializer i) throws CompileException
- Throws:
CompileException
-
generatesCode2
private boolean generatesCode2(java.util.List<Java.BlockStatement> l) throws CompileException
- Throws:
CompileException
-
generatesCode2
private boolean generatesCode2(Java.Block b) throws CompileException
- Throws:
CompileException
-
generatesCode2
private boolean generatesCode2(Java.FieldDeclaration fd) throws CompileException
- Throws:
CompileException
-
leave
private void leave(Java.BlockStatement bs) throws CompileException
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
private void leave2(Java.BlockStatement bs)
-
leave2
private void leave2(Java.SynchronizedStatement ss)
-
leave2
private void leave2(Java.TryStatement ts) throws CompileException
- Throws:
CompileException
-
compileSet
private void compileSet(Java.Lvalue lv) throws CompileException
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
private void compileSet2(Java.AmbiguousName an) throws CompileException
- Throws:
CompileException
-
compileSet2
private void compileSet2(Java.LocalVariableAccess lva)
-
compileSet2
private void compileSet2(Java.FieldAccess fa) throws CompileException
- Throws:
CompileException
-
compileSet2
private void compileSet2(Java.ArrayAccessExpression aae) throws CompileException
- Throws:
CompileException
-
compileSet2
private void compileSet2(Java.FieldAccessExpression fae) throws CompileException
- Throws:
CompileException
-
compileSet2
private void compileSet2(Java.SuperclassFieldAccessExpression scfae) throws CompileException
- Throws:
CompileException
-
compileSet2
private void compileSet2(Java.ParenthesizedExpression pe) throws CompileException
- Throws:
CompileException
-
getType
private IClass getType(Java.Atom a) throws CompileException
- Returns:
- For a
Java.Type
, the resolvedIClass
, for anJava.Rvalue
, the resolvedIClass
of the rvalue's type - Throws:
CompileException
- See Also:
resolve(TypeDeclaration)
-
getType
private IClass getType(Java.Type t) throws CompileException
- Throws:
CompileException
-
getTypes
private IClass[] getTypes(Java.Type[] types) throws CompileException
- Throws:
CompileException
-
getType
private IClass getType(Java.Rvalue rv) throws CompileException
- Throws:
CompileException
-
getType
private IClass getType(Java.Lvalue lv) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.ConstructorInvocation ci) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.SimpleType st)
-
getType2
private IClass getType2(Java.PrimitiveType bt)
-
getType2
private IClass getType2(Java.ReferenceType rt) throws CompileException
- Throws:
CompileException
-
getReferenceType
@Nullable private IClass getReferenceType(Location location, Java.Scope scope, java.lang.String[] identifiers, int n) throws CompileException
- Returns:
- The resolved
IClass
, ornull
- Throws:
CompileException
-
getReferenceType
private IClass getReferenceType(Location location, java.lang.String simpleTypeName, Java.Scope scope) throws CompileException
JLS7 6.5.5.1 Simple type name (single identifier)- Returns:
- The resolved
IClass
- Throws:
CompileException
-
importStaticOnDemand
private java.util.List<java.lang.Object> importStaticOnDemand(java.lang.String simpleName) throws CompileException
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
private IClass getType2(Java.RvalueMemberType rvmt) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.ArrayType at) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.AmbiguousName an) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.Package p) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.LocalVariableAccess lva)
-
getType2
private IClass getType2(Java.FieldAccess fa) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.ArrayLength al)
-
getType2
private IClass getType2(Java.ThisReference tr) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.LambdaExpression le) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.MethodReference mr) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.ClassInstanceCreationReference cicr) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.ArrayCreationReference acr) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.QualifiedThisReference qtr) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.ClassLiteral cl)
-
getType2
private IClass getType2(Java.Assignment a) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.ConditionalExpression ce) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.Crement c) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.ArrayAccessExpression aae) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.FieldAccessExpression fae) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.SuperclassFieldAccessExpression scfae) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.UnaryOperation uo) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.Instanceof io)
-
getType2
private IClass getType2(Java.BinaryOperation bo) throws CompileException
- Throws:
CompileException
-
getUnboxedType
private IClass getUnboxedType(IClass type)
- Returns:
- The type, or, iff type is a primitive wrapper type, the unwrapped type
-
getType2
private IClass getType2(Java.Cast c) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.ParenthesizedExpression pe) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.MethodInvocation mi) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.SuperclassMethodInvocation scmi) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.NewClassInstance nci) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.NewAnonymousClassInstance naci)
-
getType2
private IClass getType2(Java.ParameterAccess pa) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.NewArray na) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.NewInitializedArray nia) throws CompileException
- Throws:
CompileException
-
getType2
private IClass getType2(Java.IntegerLiteral il)
-
getType2
private IClass getType2(Java.FloatingPointLiteral fpl)
-
getType2
private IClass getType2(Java.BooleanLiteral bl)
-
getType2
private IClass getType2(Java.CharacterLiteral cl)
-
getType2
private IClass getType2(Java.StringLiteral sl)
-
getType2
private IClass getType2(Java.NullLiteral nl)
-
getType2
private IClass getType2(Java.SimpleConstant sl)
-
isType
private boolean isType(Java.Atom a) throws CompileException
- Throws:
CompileException
-
isType2
private boolean isType2(Java.Atom a)
-
isType2
private boolean isType2(Java.AmbiguousName an) throws CompileException
- 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 java.lang.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
private boolean isAccessible(IClass type, Java.Scope contextScope) throws CompileException
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 java.lang.String internalCheckAccessible(IClass type, Java.Scope contextScope) throws CompileException
- Returns:
- An error message, or
null
- Throws:
CompileException
-
toTypeOrCompileException
private Java.Type toTypeOrCompileException(Java.Atom a) throws CompileException
- Throws:
CompileException
-
toRvalueOrCompileException
private Java.Rvalue toRvalueOrCompileException(Java.Atom a) throws CompileException
- Throws:
CompileException
-
toLvalueOrCompileException
private Java.Lvalue toLvalueOrCompileException(Java.Atom a) throws CompileException
- 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
private void leaveStatements(Java.Scope from, Java.Scope to) throws CompileException
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 IClass compileArithmeticBinaryOperation(Java.Locatable locatable, IClass lhsType, java.lang.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 IClass compileArithmeticOperation(Java.Locatable locatable, @Nullable IClass firstOperandType, java.util.Iterator<Java.Rvalue> operands, java.lang.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, IClass type, Java.Rvalue secondOperand, java.util.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
private void stringConversion(Java.Locatable locatable, IClass sourceType) throws CompileException
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, IClass targetClass, 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
private IClass.IField[] compileFields(Java.FieldDeclaration fieldDeclaration)
- 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, java.lang.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
private Java.Atom reclassify(Java.AmbiguousName an) throws CompileException
- Throws:
CompileException
-
toIAnnotations
private IClass.IAnnotation[] toIAnnotations(Java.Annotation[] annotations) throws CompileException
- Throws:
CompileException
-
toIAnnotation
private IClass.IAnnotation toIAnnotation(Java.Annotation annotation) throws CompileException
- Throws:
CompileException
-
reclassifyName
private Java.Atom reclassifyName(Location location, Java.Scope scope, java.lang.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, java.lang.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, java.lang.String identifier) throws CompileException
JLS7 6.5.2.1- Throws:
CompileException
-
importSingleStatic
private java.util.List<java.lang.Object> importSingleStatic(java.lang.String simpleName) throws CompileException
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, java.lang.String simpleName, java.util.Collection<java.lang.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
private Java.Rvalue determineValue(Java.FieldAccessExpression fae) throws CompileException
- 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
public IClass.IMethod findIMethod(Java.MethodInvocation mi) throws CompileException
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(IClass 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, java.lang.String name, Java.Rvalue[] arguments) throws CompileException
- Throws:
CompileException
-
getIMethods
public void getIMethods(IClass type, java.lang.String methodName, java.util.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
private static <T> T assertNonNull(@Nullable T subject)
-
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, IClass type, Java.Scope scope) throws CompileException
- Throws:
CompileException
- The exception with the given type must not be thrown in the given scope
-
getTargetIClass
private IClass getTargetIClass(Java.QualifiedThisReference qtr) throws CompileException
- Throws:
CompileException
-
isIntLv
@Nullable Java.LocalVariable isIntLv(Java.Crement c) throws CompileException
Checks whether the operand is anint
local variable.- Returns:
null
iff c is not anint
local variable- Throws:
CompileException
-
resolve
private IClass resolve(Java.TypeDeclaration td)
-
referenceThis
private void referenceThis(Java.Locatable locatable, Java.AbstractClassDeclaration declaringClass, Java.TypeBodyDeclaration declaringTypeBodyDeclaration, IClass targetIClass) throws CompileException
- Throws:
CompileException
-
getOuterClasses
private static java.util.List<Java.TypeDeclaration> getOuterClasses(Java.TypeDeclaration inner)
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
@Nullable static Java.TypeDeclaration getOuterClass(Java.TypeDeclaration typeDeclaration)
- Returns:
- The
Java.TypeDeclaration
that immediately encloses the typeDeclaration, ornull
-
getIClass
private IClass getIClass(Java.ThisReference tr) throws CompileException
- Throws:
CompileException
-
getReturnType
private IClass getReturnType(Java.FunctionDeclarator fd) throws CompileException
- Throws:
CompileException
-
toIConstructor
IClass.IConstructor toIConstructor(Java.ConstructorDeclarator constructorDeclarator)
- Returns:
- the
IClass.IConstructor
that implements the constructorDeclarator
-
toIMethod
public IClass.IMethod toIMethod(Java.MethodDeclarator methodDeclarator)
- Returns:
- The
IClass.IMethod
that implements the methodDeclarator
-
toIInvocable
private IClass.IInvocable toIInvocable(Java.FunctionDeclarator fd)
-
importSingleType
@Nullable private IClass importSingleType(java.lang.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 java.lang.String[] getSingleTypeImport(java.lang.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(java.lang.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(java.lang.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 java.util.Collection<Java.AbstractCompilationUnit.TypeImportOnDemandDeclaration> getTypeImportOnDemandImportDeclarations()
-
consT
private IClass consT(Java.Locatable locatable, @Nullable java.lang.Object value) throws CompileException
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
private static java.lang.String[] makeUtf8Able(java.lang.String s)
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
private void consT(Java.Locatable locatable, IClass t, int value)
-
consT
private void consT(Java.Locatable locatable, int value)
-
consT
private void consT(Java.Locatable locatable, long value)
-
consT
private void consT(Java.Locatable locatable, float value)
-
consT
private void consT(Java.Locatable locatable, double value)
-
consT
private void consT(Java.Locatable locatable, java.lang.String s)
-
consT
private void consT(Java.Locatable locatable, IClass iClass)
-
castConversion
private void castConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, @Nullable java.lang.Object constantValue) throws CompileException
- Throws:
CompileException
-
tryCastConversion
private boolean tryCastConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, @Nullable java.lang.Object constantValue) throws CompileException
- Throws:
CompileException
-
assignmentConversion
private void assignmentConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, @Nullable java.lang.Object constantValue) throws CompileException
Implements "assignment conversion" (JLS7 5.2).- Throws:
CompileException
-
tryAssignmentConversion
private boolean tryAssignmentConversion(Java.Locatable locatable, IClass sourceType, IClass targetType, @Nullable java.lang.Object constantValue) throws CompileException
- Throws:
CompileException
-
assignmentConversion
@Nullable private java.lang.Object assignmentConversion(Java.Locatable locatable, @Nullable java.lang.Object value, IClass targetType) throws CompileException
Implements "assignment conversion" (JLS7 5.2) on a constant value.- Parameters:
value
- Must be aBoolean
,String
,Byte
,Short
,Integer
,Character
,Long
,Float
,Double
ornull
- Returns:
- A
Boolean
,String
,Byte
,Short
,Integer
,Character
,Long
,Float
,Double
ornull
- Throws:
CompileException
-
unaryNumericPromotion
private IClass unaryNumericPromotion(Java.Locatable locatable, IClass type) throws CompileException
Implements "unary numeric promotion" (JLS7 5.6.1).- Returns:
- The promoted type
- Throws:
CompileException
-
reverseUnaryNumericPromotion
private void reverseUnaryNumericPromotion(Java.Locatable locatable, IClass sourceType, IClass targetType) throws CompileException
- Throws:
CompileException
-
convertToPrimitiveNumericType
private IClass convertToPrimitiveNumericType(Java.Locatable locatable, IClass 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
private void numericPromotion(Java.Locatable locatable, IClass sourceType, IClass targetType)
-
unaryNumericPromotionType
private IClass unaryNumericPromotionType(Java.Locatable locatable, IClass type) throws CompileException
- Throws:
CompileException
-
binaryNumericPromotionType
private IClass binaryNumericPromotionType(Java.Locatable locatable, IClass type1, IClass type2) throws CompileException
- Throws:
CompileException
-
isIdentityConvertible
private boolean isIdentityConvertible(IClass sourceType, IClass targetType)
Checks whether "identity conversion" (5.1.1) is possible.- Returns:
- Whether the conversion is possible
-
tryIdentityConversion
private boolean tryIdentityConversion(IClass sourceType, IClass targetType)
Implements "identity conversion" (5.1.1).- Returns:
- Whether the conversion was possible
-
isWideningPrimitiveConvertible
private boolean isWideningPrimitiveConvertible(IClass sourceType, IClass targetType)
-
tryWideningPrimitiveConversion
private boolean tryWideningPrimitiveConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
Implements "widening primitive conversion" (5.1.2).- Returns:
- Whether the conversion succeeded
-
fillConversionMap
private static void fillConversionMap(java.lang.Object[] array, java.util.Map<java.lang.String,int[]> map)
-
isWideningReferenceConvertible
private boolean isWideningReferenceConvertible(IClass sourceType, IClass targetType) throws CompileException
Checks if "widening reference conversion" (5.1.4) is possible.- Returns:
- Whether the conversion is possible
- Throws:
CompileException
-
isNarrowingPrimitiveConvertible
private boolean isNarrowingPrimitiveConvertible(IClass sourceType, IClass targetType)
Checks whether "narrowing primitive conversion" (JLS7 5.1.3) is possible.
-
tryNarrowingPrimitiveConversion
private boolean tryNarrowingPrimitiveConversion(Java.Locatable locatable, IClass sourceType, IClass targetType)
Implements "narrowing primitive conversion" (JLS7 5.1.3).- Returns:
- Whether the conversion succeeded
-
tryConstantAssignmentConversion
private boolean tryConstantAssignmentConversion(Java.Locatable locatable, @Nullable java.lang.Object constantValue, IClass 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(IClass sourceType, IClass targetType) throws CompileException
Checks whether "narrowing reference conversion" (JLS7 5.1.5) is possible.- Throws:
CompileException
-
tryNarrowingReferenceConversion
private boolean tryNarrowingReferenceConversion(Java.Locatable locatable, IClass sourceType, IClass targetType) throws CompileException
Implements "narrowing reference conversion" (5.1.5).- Returns:
- Whether the conversion succeeded
- Throws:
CompileException
-
isCastReferenceConvertible
private boolean isCastReferenceConvertible(IClass sourceType, IClass targetType) throws CompileException
JLS7 5.5- Throws:
CompileException
-
isBoxingConvertible
@Nullable private IClass isBoxingConvertible(IClass sourceType)
- Returns:
- The boxed type or
null
-
tryBoxingConversion
private boolean tryBoxingConversion(Java.Locatable locatable, IClass sourceType, IClass targetType) throws CompileException
- Throws:
CompileException
-
boxingConversion
private void boxingConversion(Java.Locatable locatable, IClass sourceType, IClass targetType) throws CompileException
- Parameters:
sourceType
- a primitive type (except VOID)targetType
- the corresponding wrapper type- Throws:
CompileException
-
isUnboxingConvertible
@Nullable private IClass isUnboxingConvertible(IClass sourceType)
- Returns:
- Iff sourceType is a primitive wrapper type, the unboxed type, otherwise
null
-
isConvertibleToPrimitiveNumeric
private boolean isConvertibleToPrimitiveNumeric(IClass sourceType)
- 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, IClass 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, java.lang.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
private void aconstnull(Java.Locatable locatable)
-
add
private void add(Java.Locatable locatable)
-
andOrXor
private void andOrXor(Java.Locatable locatable, java.lang.String operator)
-
anewarray
private void anewarray(Java.Locatable locatable, IClass componentType)
-
arraylength
private void arraylength(Java.Locatable locatable)
-
arraystore
private void arraystore(Java.Locatable locatable, IClass lhsComponentType)
-
athrow
private void athrow(Java.Locatable locatable)
-
checkcast
private void checkcast(Java.Locatable locatable, IClass targetType)
-
cmp
private void cmp(Java.Locatable locatable, int opIdx)
-
dup
private void dup(Java.Locatable locatable)
Duplicates the top operand: ... a => ... a a
-
dup2
private void dup2(Java.Locatable locatable)
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
private void dupn(Java.Locatable locatable, int n)
Duplicates the top n operands.- n == 0
- (nothing)
- n == 1
- ... a => ... a a
- n == 2
- ... a b => ... a b a b
-
dupx
private void dupx(Java.Locatable locatable)
Copies the top operand one position down: b a => a b a
-
dupx2
private void dupx2(Java.Locatable locatable)
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
private void dupxx(Java.Locatable locatable, int positions)
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
private void getfield(Java.Locatable locatable, IClass.IField iField) throws CompileException
- Throws:
CompileException
-
getfield
private void getfield(Java.Locatable locatable, IClass declaringIClass, java.lang.String fieldName, IClass fieldType, boolean statiC)
-
gotO
private void gotO(Java.Locatable locatable, CodeContext.Offset dst)
- Parameters:
opcode
- One of IF* and GOTO
-
if_acmpxx
private void if_acmpxx(Java.Locatable locatable, int opIdx, CodeContext.Offset dst)
-
if_icmpxx
private void if_icmpxx(Java.Locatable locatable, int opIdx, CodeContext.Offset dst)
-
ifnonnull
private void ifnonnull(Java.Locatable locatable, CodeContext.Offset dst)
-
ifnull
private void ifnull(Java.Locatable locatable, CodeContext.Offset dst)
-
ifxx
private void ifxx(Java.Locatable locatable, int opIdx, CodeContext.Offset dst)
-
iinc
private void iinc(Java.Locatable locatable, Java.LocalVariable lv, java.lang.String operator)
- Parameters:
operator
- Must be either "++" or "--", as an @linkinterned
string
-
instanceoF
private void instanceoF(Java.Locatable locatable, IClass rhsType)
-
invokeMethod
private void invokeMethod(Java.Locatable locatable, int opcode, IClass declaringIClass, java.lang.String methodName, MethodDescriptor methodDescriptor, boolean useInterfaceMethodRef) throws CompileException
Expects the target object and the arguments on the operand stack.- Throws:
CompileException
-
l2i
private void l2i(Java.Locatable locatable)
-
load
private IClass load(Java.Locatable locatable, Java.LocalVariable localVariable)
-
load
private void load(Java.Locatable locatable, IClass localVariableType, int localVariableIndex)
-
lookupswitch
private void lookupswitch(Java.Locatable locatable, java.util.SortedMap<java.lang.Integer,CodeContext.Offset> caseLabelMap, CodeContext.Offset switchOffset, CodeContext.Offset defaultLabelOffset)
-
monitorenter
private void monitorenter(Java.Locatable locatable)
-
monitorexit
private void monitorexit(Java.Locatable locatable)
-
mulDivRemAddSub
private void mulDivRemAddSub(Java.Locatable locatable, java.lang.String operator)
- Parameters:
operator
- One of* / % + -
-
multianewarray
private void multianewarray(Java.Locatable locatable, int dimExprCount, int dims, IClass componentType)
-
neg
private void neg(Java.Locatable locatable, IClass operandType)
- Parameters:
operandType
- One of BYTE, CHAR, INT, SHORT, LONG, BOOLEAN, LONG, FLOAT, DOUBLE
-
neW
private void neW(Java.Locatable locatable, IClass iClass)
-
newarray
private void newarray(Java.Locatable locatable, IClass componentType)
-
pop
private void pop(Java.Locatable locatable, IClass type)
-
putfield
private void putfield(Java.Locatable locatable, IClass.IField iField) throws CompileException
- Throws:
CompileException
-
returN
private void returN(Java.Locatable locatable)
-
shift
private void shift(Java.Locatable locatable, java.lang.String operator)
- Parameters:
operator
- One of<< >> >>>
-
store
private void store(Java.Locatable locatable, Java.LocalVariable localVariable)
Assigns the top operand to the given local variable.
-
store
private void store(Java.Locatable locatable, IClass lvType, short lvIndex)
- Parameters:
lvIndex
- (two slots for LONG and DOUBLE local variables)
-
sub
private void sub(Java.Locatable locatable)
-
swap
private void swap(Java.Locatable locatable)
-
tableswitch
private void tableswitch(Java.Locatable locatable, java.util.SortedMap<java.lang.Integer,CodeContext.Offset> caseLabelMap, CodeContext.Offset switchOffset, CodeContext.Offset defaultLabelOffset)
-
xaload
private void xaload(Java.Locatable locatable, IClass componentType)
-
xor
private void xor(Java.Locatable locatable, int opcode)
-
xreturn
private void xreturn(Java.Locatable locatable, IClass returnType)
-
ilfd
private static int ilfd(IClass t)
- Parameters:
t
- One of BYTE, CHAR, INT, SHORT, LONG, BOOLEAN, LONG, FLOAT, DOUBLE
-
ilfd
private static int ilfd(ClassFile.StackMapTableAttribute.VerificationTypeInfo vti)
-
ilfda
private static int ilfda(IClass t)
-
il
private static int il(ClassFile.StackMapTableAttribute.VerificationTypeInfo vti)
-
ilfdabcs
private static int ilfdabcs(IClass t)
-
findIField
@Nullable private IClass.IField findIField(IClass iClass, java.lang.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(IClass iClass, java.lang.String name, Location location) throws CompileException
Finds a named type in the givenIClass
. Honors superclasses, interfaces and enclosing type declarations.- Returns:
null
if no type with the given name is found- Throws:
CompileException
-
findClass
@Nullable public IClass findClass(java.lang.String className)
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
private void compileError(java.lang.String message) throws CompileException
Equivalent withcompileError(String, Location)
with anull
location argument.- Throws:
CompileException
-
compileError
private void compileError(java.lang.String message, @Nullable Location location) throws CompileException
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(java.lang.String handle, java.lang.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
public void setCompileErrorHandler(@Nullable ErrorHandler compileErrorHandler)
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
public void setWarningHandler(@Nullable WarningHandler warningHandler)
By default, warnings are discarded, but an application my install a customWarningHandler
.- Parameters:
warningHandler
-null
to indicate that no warnings be issued
-
replaceCodeContext
@Nullable private CodeContext replaceCodeContext(@Nullable CodeContext newCodeContext)
-
addLineNumberOffset
private void addLineNumberOffset(Java.Locatable locatable)
-
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)
-
invoke
private void invoke(Java.Locatable locatable, IClass.IMethod iMethod) throws CompileException
Invokes the iMethod; assumes thatthis
(unless iMethod is static) and the correct number and types of arguments are on the operand stack.- Throws:
CompileException
-
invoke
private void invoke(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
private void writeOffset(CodeContext.Offset src, CodeContext.Offset dst)
-
addConstantStringInfo
private short addConstantStringInfo(java.lang.String value)
-
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
private short addConstantClassInfo(IClass iClass)
-
addConstantFieldrefInfo
private short addConstantFieldrefInfo(IClass iClass, java.lang.String fieldName, IClass fieldType)
-
addConstantMethodrefInfo
private short addConstantMethodrefInfo(IClass iClass, java.lang.String methodName, java.lang.String methodFd)
-
addConstantInterfaceMethodrefInfo
private short addConstantInterfaceMethodrefInfo(IClass iClass, java.lang.String methodName, java.lang.String methodFd)
-
writeConstantClassInfo
private void writeConstantClassInfo(IClass iClass)
-
writeConstantFieldrefInfo
private void writeConstantFieldrefInfo(IClass iClass, java.lang.String fieldName, IClass fieldType)
-
writeConstantMethodrefInfo
private void writeConstantMethodrefInfo(IClass iClass, java.lang.String methodName, MethodDescriptor methodMd)
-
writeConstantInterfaceMethodrefInfo
private void writeConstantInterfaceMethodrefInfo(IClass iClass, java.lang.String methodName, MethodDescriptor methodMd)
-
getWhereToBreak
private CodeContext.Offset getWhereToBreak(Java.BreakableStatement bs)
-
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
private void referenceThis(Java.Locatable locatable, IClass currentIClass)
-
newArray
private IClass newArray(Java.Locatable locatable, int dimExprCount, int dims, IClass componentType)
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
private static java.lang.String last(java.lang.String[] sa)
-
allButLast
private static java.lang.String[] allButLast(java.lang.String[] sa)
-
concat
private static java.lang.String[] concat(java.lang.String[] sa, java.lang.String s)
-
compileException
private static CompileException compileException(Java.Locatable locatable, java.lang.String message)
-
unescape
private static java.lang.String unescape(java.lang.String s, @Nullable Location location) throws CompileException
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 sequencejava.lang.IndexOutOfBoundsException
- sends with a backslash
-
accessFlags
private short accessFlags(Java.Modifier[] modifiers) throws CompileException
- Throws:
CompileException
-
accessModifiers
private static Java.Modifier[] accessModifiers(Location location, java.lang.String... keywords)
-
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)
-
-