Class UnitCompiler
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface(package private) static interfaceHelper interface for string conversion.(package private) static interfaceInterface for delayed code generation.static classShort-hand implementation ofIClass.IFieldthat implements a non-constant, non-static, package-accessible field.private static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Java.AbstractCompilationUnitprivate CodeContextprivate intprivate ErrorHandlerprivate booleanprivate booleanprivate booleanprivate static final intprivate static final intprivate static final intprivate static final intprivate final IClassLoaderstatic final booleanSpecial value for the orientation parameter of thecompileBoolean(Java.Rvalue, CodeContext.Offset, boolean)methods, indicating that the code should be generated such that execution branches if the value on top of the operand stack is FALSE.static final booleanSpecial value for the orientation parameter of thecompileBoolean(Java.Rvalue, CodeContext.Offset, boolean)methods, indicating that the code should be generated such that execution branches if the value on top of the operand stack is TRUE.private static final intprivate static final Loggerprivate static final Patternprivate static final intprivate static final Visitor.ArrayInitializerOrRvalueVisitor<Boolean, RuntimeException> private static final intstatic final ObjectSpecial return value for thegetConstantValue(Java.Rvalue)method family indicating that the givenJava.Rvaluedoes not evaluate to a constant value.private EnumSet<JaninoOption> To be used only bygetSingleTypeImport(String, Location);nullmeans "not yet initialized"private UnitCompiler.ClassFileConsumerNon-nullwhilecompileUnit(boolean, boolean, boolean, ClassFileConsumer)is executing.private static final intThis constant determines the number of operands up to which theprivate intJava version to compile for.private static final Pattern2147483648 is the special value that can not be stored in an INT, but its negated value (-2147483648) can.private static final Pattern9223372036854775808 is the special value that can not be stored in a LONG, but its negated value (-9223372036854775808) can.private WarningHandler -
Constructor Summary
ConstructorsConstructorDescriptionUnitCompiler(Java.AbstractCompilationUnit abstractCompilationUnit, IClassLoader iClassLoader) -
Method Summary
Modifier and TypeMethodDescriptionprivate shortaccessFlags(Java.Modifier[] modifiers) private static Java.Modifier[]accessModifiers(Location location, String... keywords) private voidaconstnull(Java.Locatable locatable) private voidadd(Java.Locatable locatable) private voidAdds the givenClassFileto the result set.private shortaddConstantClassInfo(IClass iClass) private shortaddConstantDoubleInfo(double value) private shortaddConstantFieldrefInfo(IClass iClass, String fieldName, IClass fieldType) private shortaddConstantFloatInfo(float value) private shortaddConstantIntegerInfo(int value) private shortaddConstantInterfaceMethodrefInfo(IClass iClass, String methodName, String methodFd) private shortaddConstantLongInfo(long value) private shortaddConstantMethodrefInfo(IClass iClass, String methodName, String methodFd) private shortaddConstantStringInfo(String value) private voidaddFields(Java.FieldDeclaration fd, ClassFile cf) Creates and addsClassFile.FieldInfos to the cf for all fields declared by the fd.private voidaddLineNumberOffset(Java.Locatable locatable) private static ClassFile.MethodInfoaddMethodInfo(Java.Locatable locatable, ClassFile classFile, short accessFlags, String methodName, MethodDescriptor methodMd) private static String[]allButLast(String[] sa) private Java.LocalVariableallocateLocalVariable(boolean finaL, IType localVariableType) private Java.LocalVariableallocateLocalVariableAndMarkAsInitialized(boolean finaL, IType localVariableType) private Java.LocalVariableSlotallocateLocalVariableSlot(IType localVariableType, String localVariableName) private Java.LocalVariableSlotallocateLocalVariableSlotAndMarkAsInitialized(IType localVariableType, String localVariableName) private voidandOrXor(Java.Locatable locatable, String operator) private voidanewarray(Java.Locatable locatable, IClass componentType) private voidarraylength(Java.Locatable locatable) private voidarraystore(Java.Locatable locatable, IType lhsComponentType) private static <T> TassertNonNull(T subject) private voidassignmentConversion(Java.Locatable locatable, IType sourceType, IType targetType, Object constantValue) Implements "assignment conversion" (JLS7 5.2) (more precisely: "assignment contexts".)(package private) voidCopies the values of the synthetic parameters of this constructor ("this$..." and "val$...") to the synthetic fields of the object ("this$..." and "val$...").private voidathrow(Java.Locatable locatable) private IClassbinaryNumericPromotionType(Java.Locatable locatable, IType type1, IType type2) private voidboxingConversion(Java.Locatable locatable, IType sourceType, IType targetType) private voidbuildLocalVariableMap(Java.Block block, Map<String, Java.LocalVariable> localVars) private Map<String, Java.LocalVariable> buildLocalVariableMap(Java.BlockStatement blockStatement, Map<String, Java.LocalVariable> localVars) Computes and fills in the 'local variable map' for the given blockStatement.protected voidbuildLocalVariableMap(Java.CatchClause catchClause, Map<String, Java.LocalVariable> localVars) Adds the given localVars to the 'local variable map' of the given catchClause.private static Map<String, Java.LocalVariable> buildLocalVariableMap(Java.ConstructorInvocation ci, Map<String, Java.LocalVariable> localVars) private voidbuildLocalVariableMap(Java.DoStatement ds, Map<String, Java.LocalVariable> localVars) private voidbuildLocalVariableMap(Java.ForEachStatement fes, Map<String, Java.LocalVariable> localVars) private voidbuildLocalVariableMap(Java.ForStatement fs, Map<String, Java.LocalVariable> localVars) private voidprivate voidbuildLocalVariableMap(Java.IfStatement is, Map<String, Java.LocalVariable> localVars) private voidbuildLocalVariableMap(Java.Initializer i, Map<String, Java.LocalVariable> localVars) private Map<String, Java.LocalVariable> buildLocalVariableMap(Java.LabeledStatement ls, Map<String, Java.LocalVariable> localVars) private Map<String, Java.LocalVariable> buildLocalVariableMap(Java.LocalVariableDeclarationStatement lvds, Map<String, Java.LocalVariable> localVars) private static Map<String, Java.LocalVariable> buildLocalVariableMap(Java.Statement s, Map<String, Java.LocalVariable> localVars) private voidbuildLocalVariableMap(Java.SwitchStatement ss, Map<String, Java.LocalVariable> localVars) private voidbuildLocalVariableMap(Java.SynchronizedStatement ss, Map<String, Java.LocalVariable> localVars) private voidbuildLocalVariableMap(Java.TryStatement ts, Map<String, Java.LocalVariable> localVars) private voidbuildLocalVariableMap(Java.WhileStatement ws, Map<String, Java.LocalVariable> localVars) private voidcastConversion(Java.Locatable locatable, IType sourceType, IType targetType, Object constantValue) private static shortchangeAccessibility(short accessFlags, short newAccessibility) private voidcheckAccessible(IClass.IMember member, Java.Scope contextScope, Location location) Checks whether the givenIClass.IMemberis accessible in the given context, according to JLS7 6.6.1.BL1.B4.private voidcheckAccessible(IClass type, Java.Scope contextScope, Location location) Checks whether the givenIClassis accessible in the given context, according to JLS7 6.6.1.2 and 6.6.1.4.private voidcheckcast(Java.Locatable locatable, IType targetType) private voidcheckForConflictWithSingleTypeImport(String name, Location location) private voidprivate voidcheckMemberAccessible(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 voidcheckThrownException(Java.Locatable locatable, IType type, Java.Scope scope) private voidcheckThrownExceptions(Java.Invocation in, IClass.IMethod iMethod) private voidcmp(Java.Locatable locatable, int opIdx) private ITypecommonSupertype(IType t1, IType t2) private ITypecommonSupertype2(IType t1, IType t2) private voidcompile(Java.ArrayInitializerOrRvalue aiorv, IType arrayType) private booleanprivate voidcompile(Java.FunctionDeclarator fd, ClassFile classFile) private voidcompile(Java.Rvalue rv) SomeJava.Rvalues compile more efficiently when their value is not needed, e.g.private voidprivate voidprivate booleanprivate voidprivate booleanprivate voidprivate booleanprivate booleanprivate voidCompiles an (ordinary, not modular) compilation unitprivate booleanprivate voidprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate voidcompile2(Java.FunctionDeclarator fd, ClassFile classFile) private booleanprivate booleanprivate voidprivate voidprivate booleanprivate voidprivate booleanprivate booleanprivate voidprivate voidCompiles a top-level class or enum declaration.private voidCompiles a top-level interface or annotation type declaration.private voidprivate booleanprivate voidcompile2(Java.Rvalue rv) private booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate voidcompileAnnotations(Java.Annotation[] annotations, Annotatable target, ClassFile cf) Converts and adds the annotations to the target.private ITypecompileArithmeticBinaryOperation(Java.Locatable locatable, IType lhsType, String operator, Java.Rvalue rhs) The LHS operand of type lhsType is expected on the stack.private ITypecompileArithmeticOperation(Java.Locatable locatable, IType firstOperandType, Iterator<Java.Rvalue> operands, String operator) Executes an arithmetic operation on a sequence of operands.private voidcompileBoolean(Java.Rvalue rv, CodeContext.Offset dst, boolean orientation) Compiles anJava.Rvalueand branches, depending on the value.private voidcompileBoolean2(Java.BinaryOperation bo, CodeContext.Offset dst, boolean orientation) private voidcompileBoolean2(Java.ParenthesizedExpression pe, CodeContext.Offset dst, boolean orientation) private voidcompileBoolean2(Java.Rvalue rv, CodeContext.Offset dst, boolean orientation) private voidcompileBoolean2(Java.UnaryOperation ue, CodeContext.Offset dst, boolean orientation) private intGenerates code that determines the context of theJava.Rvalueand puts it on the operand stack.private intprivate intArray access expression; see JLS7 15.13 / JLS8+ 15.10.3.private intprivate intprivate intprivate intprivate intprivate intprivate voidCompiles all of the types for this declarationprivate voidcompileDeclaredMethods(Java.TypeDeclaration typeDeclaration, ClassFile cf) Compiles all of the methods for this declarationprivate voidcompileDeclaredMethods(Java.TypeDeclaration typeDeclaration, ClassFile cf, int startPos) Compiles methods for this declaration starting at startPos.private ClassFile.ElementValuecompileElementValue(Java.ElementValue elementValue, ClassFile cf, boolean compileAsArray) private voidcompileError(String message) Equivalent withcompileError(String, Location)with anulllocation argument.private voidcompileError(String message, Location location) Issues a compile error with the given message.private static CompileExceptioncompileException(Java.Locatable locatable, String message) private IClass.IFieldcompileField(Java.TypeDeclaration declaringType, Java.Annotation[] annotations, Access access, boolean statiC, boolean finaL, Java.Type type, int brackets, String name, Java.ArrayInitializerOrRvalue initializer) Compiles one variable declarator into anIClass.IField.private IClass.IField[]compileFields(Java.FieldDeclaration fieldDeclaration) private ITypeGenerates code that determines the value of theJava.Rvalueand puts it on the operand stack.private ITypeprivate ITypeprivate IClassprivate IClassprivate ITypeprivate ITypeprivate IClassprivate ITypeprivate IClassprivate IClassprivate ITypeprivate ITypeprivate ITypeprivate ITypeprivate IClassprivate IClassprivate IClassprivate ITypeprivate IClassprivate IClassprivate IClassprivate IClassprivate ITypeprivate ITypeprivate ITypeprivate ITypeprivate ITypeprivate IClassprivate ITypeprivate IClassprivate IClassprivate IClassprivate voidcompileGetValue(Java.ArrayInitializer ai, IType arrayType) private ITypeConvenience function that callscompileContext(Rvalue)andcompileGet(Rvalue).private voidGenerates code that stores a value in theJava.Lvalue.private voidprivate voidprivate voidprivate voidprivate voidprivate voidprivate voidprivate booleancompileStatements(List<? extends Java.BlockStatement> statements) private IClasscompileStringConcatenation(Java.Locatable locatable, IType type, Java.Rvalue secondOperand, Iterator<Java.Rvalue> operands) private booleancompileTryCatch(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 booleancompileTryCatchFinally(Java.TryStatement ts, UnitCompiler.Compilable2 compileBody, Java.BlockStatement finallY) Generates code for a TRY statement without resources, but with an (optional) FINALLY clause.private booleancompileTryCatchFinallyWithResources(Java.TryStatement ts, List<Java.TryStatement.Resource> resources, UnitCompiler.Compilable2 compileBody, Java.Block finallY) Generates code for a TRY statement with (possibly zero) resources and an (optional) FINALLY clause.private booleancompileUnconditionalLoop(Java.ContinuableStatement cs, Java.BlockStatement body, Java.Rvalue[] update) private booleancompileUnconditionalLoopWithUpdate(Java.ContinuableStatement cs, Java.BlockStatement body, Java.Rvalue[] update) voidcompileUnit(boolean debugSource, boolean debugLines, boolean debugVars, Collection<ClassFile> generatedClassFiles) Generates a set ofClassFileobjects which represent the classes and interfaces declared in the compilation unit.voidcompileUnit(boolean debugSource, boolean debugLines, boolean debugVars, UnitCompiler.ClassFileConsumer storesClassFiles) Generates a set ofClassFileobjects which represent the classes and interfaces declared in the compilation unit.private static String[]private voidconsT(Java.Locatable locatable, double value) private voidconsT(Java.Locatable locatable, float value) private voidconsT(Java.Locatable locatable, int value) private voidconsT(Java.Locatable locatable, long value) private IClassconsT(Java.Locatable locatable, Object value) Pushes one value on the operand stack and pushes the respectiveClassFile.StackMapTableAttribute.VerificationTypeInfooperand to the stack map.private voidconsT(Java.Locatable locatable, String s) private voidconsT(Java.Locatable locatable, IClass iClass) private voidconsT(Java.Locatable locatable, IClass t, int value) private ObjectconstantAssignmentConversion(Java.Locatable locatable, Object value, IType targetType) Implements "assignment conversion" (JLS7 5.2) on a constant value.private IClassconvertToPrimitiveNumericType(Java.Locatable locatable, IType type) If the given type is a primitive type, return that type.private Java.Rvalueprivate Java.Rvalue"super.fld", "Type.super.fld"private voiddup(Java.Locatable locatable) Duplicates the top operand: ...private voiddup2(Java.Locatable locatable) Duplicates the top two operands: ...private voiddupn(Java.Locatable locatable, int n) Duplicates the top n operands.private voiddupx(Java.Locatable locatable) Copies the top operand one position down: b a => a b aprivate voiddupx2(Java.Locatable locatable) Copies the top operand two positions down: c b a => a c b a.private voiddupxx(Java.Locatable locatable, int positions) Copies the top operand positions down.private booleanCalled to check whether the givenJava.BlockStatementcompiles or not.private voidCalled to check whether the givenJava.Rvaluecompiles or not.private voidprivate IClass.IMethodfakeIMethod(IClass targetType, String name, Java.Rvalue[] arguments) private static voidfillConversionMap(Object[] array, Map<String, int[]> map) Finds one class or interface declaration in this compilation unit and resolves it into anIClass.private IClass.IFieldfindIField(IClass iClass, String name, Location location) Finds a named field in the givenIClass.private IClass.IMethodfindIMethod(IType targetType, Java.Invocation invocation) Finds aIClass.IMethodin the given targetType, its superclasses or superinterfaces which is applicable with the given invocation.Finds methods of the mi.targetnamed mi.methodName, examines the argument types and chooses the most specific method.findIMethod(Java.SuperclassMethodInvocation superclassMethodInvocation) private static Java.LocalClassDeclarationfindLocalClassDeclaration(Java.Scope s, String name) Finds a local class declared in any block enclosing the given block statement.private IClassfindMemberType(IType iType, String name, Java.TypeArgument[] typeArguments, Location location) Finds a named type in the givenIClassorIParameterizedType.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.IInvocablefindMostSpecificIInvocable(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 IClassfindTypeByFullyQualifiedName(Location location, String[] identifiers) Attempts to load anIClassby fully-qualified name throughiClassLoader.private IClassfindTypeByName(Location location, String className) Finds the namedIClassin this compilation unit, or through theiClassLoader.private voidgenerateBridgeMethod(ClassFile cf, IClass declaringIClass, IClass.IMethod base, IClass.IMethod override) Generates and compiles a bridge method with signature base that delegates to override.private booleanChecks whether invocation ofcompile(BlockStatement)would generate more than zero code bytes.private booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanprivate CodeContextprivate static ITypegetComponentType(IType expressionType) final ObjectAttempts to evaluate as a constant expression.final ObjectAttempts to evaluate as a constant expression.private Objectprivate Objectprivate booleanprivate Objectprivate charprivate Objectprivate Objectprivate Objectprivate Objectprivate Objectprivate Objectprivate Objectprivate Objectprivate Objectprivate Stringprivate Stringprivate Objectprivate Java.AbstractClassDeclarationprivate Java.TypeBodyDeclarationstatic intprivate voidgetfield(Java.Locatable locatable, IClass.IField iField) private voidgetfield(Java.Locatable locatable, IClass declaringIClass, String fieldName, IClass fieldType, boolean statiC) private IClassvoidgetIMethods(IClass type, String methodName, List<IClass.IMethod> v) Adds all methods with the given methodName that are declared by the type, its superclasses and all their superinterfaces to the result list v.private static IType[]getInterfaces(IType t1) getLocalVariable(Java.CatchParameter parameter) getLocalVariable(Java.FunctionDeclarator.FormalParameter parameter, boolean isVariableArityParameter) getLocalVariableTypeInfo(short lvIndex) (package private) Java.ArrayInitializerOrRvalueDetermines the non-constant-final initializer of the givenJava.VariableDeclarator.(package private) static Java.TypeDeclarationgetOuterClass(Java.TypeDeclaration typeDeclaration) private static List<Java.TypeDeclaration> Returns a list consisting of the given inner class and all its enclosing (outer) classes.private IClassgetRawReferenceType(Location location, String simpleTypeName, Java.Scope scope) private IClassprivate ITypegetReferenceType(Location location, String simpleTypeName, Java.TypeArgument[] typeArguments, Java.Scope scope) JLS7 6.5.5.1 Simple type name (single identifier)private ITypegetReferenceType(Location location, Java.Scope scope, String[] identifiers, int n, Java.TypeArgument[] typeArguments) private ITypeString[]getSingleTypeImport(String name, Location location) Checks if the given simple name was imported through a single type import.private static ITypegetSuperclass(IType type) private ITypeintprivate ITypeprivate ITypegetType(Java.Lvalue lv) private ITypegetType(Java.Rvalue rv) private ITypeprivate ITypeprivate ITypeprivate IClassprivate IClassprivate IClassprivate ITypeprivate ITypeprivate IClassprivate ITypeprivate IClassprivate IClassprivate IClassprivate ITypeprivate IClassprivate ITypeprivate ITypeprivate ITypeprivate IClassprivate IClassprivate IClassprivate IClassprivate ITypeprivate IClassprivate IClassprivate IClassprivate IClassprivate ITypeprivate ITypeprivate IClassprivate IClassprivate ITypeprivate ITypeprivate IClassprivate ITypeprivate ITypeprivate IClassprivate IClassprivate ITypeprivate IClassprivate ITypeprivate IClassprivate IClassprivate IClassprivate IClassprivate IType[]private ITypegetUnboxedType(IType type) private CodeContext.Offsetprivate voidgotO(Java.Locatable locatable, CodeContext.Offset dst) private booleanhasAnnotation(Java.FunctionDeclarator fd, IClass annotationType) private voidif_acmpxx(Java.Locatable locatable, int opIdx, CodeContext.Offset dst) private voidif_icmpxx(Java.Locatable locatable, int opIdx, CodeContext.Offset dst) private voidifnonnull(Java.Locatable locatable, CodeContext.Offset dst) private voidifnull(Java.Locatable locatable, CodeContext.Offset dst) private voidifNumeric(Java.Locatable locatable, int opIdx, CodeContext.Offset dst, boolean orientation) private voidifxx(Java.Locatable locatable, int opIdx, CodeContext.Offset dst) private voidiinc(Java.Locatable locatable, Java.LocalVariable lv, String operator) private static intprivate static intprivate static intprivate static intprivate static intimportSingleStatic(String simpleName) Imports a member class, member interface, static field or static method via the compilation unit's single static import declarations.private IClassimportSingleType(String simpleTypeName, Location location) If the given name was declared in a simple type import, load that class.private voidimportStatic(IClass declaringIClass, String simpleName, Collection<Object> result, Location location) Finds all members (member classes, member interfaces, static fields and/or static methods) of the declaringIClass with the given simpleName and adds them to the result.importStaticOnDemand(String simpleName) Imports a member class or interface, static field or static method via the compilation unit's static import on-demand declarations.importTypeOnDemand(String simpleTypeName, Location location) 6.5.2.BL1.B1.B5, 6.5.2.BL1.B1.B6 Type-import-on-demand.
6.5.5.1.6 Type-import-on-demand declaration.private IClassimportTypeOnDemand2(String simpleTypeName, Location location) (package private) voidCompiles the instance variable initializers and the instance initializers in their lexical order.private voidinstanceoF(Java.Locatable locatable, IType rhsType) private StringinternalCheckAccessible(IClass iClassDeclaringMember, Access memberAccess, Java.Scope contextScope) private StringinternalCheckAccessible(IClass type, Java.Scope contextScope) private voidinvoke(Java.Locatable locatable, int opcode, IClass declaringIClass, String methodName, MethodDescriptor methodDescriptor, boolean useInterfaceMethodRef) Expects the target object and the arguments on the operand stack.private voidinvokeConstructor(Java.Locatable locatable, IClass.IConstructor iConstructor) Invokes the iConstructor; assumes thatthisand the correct number and types of arguments are on the operand stack.private voidinvokeConstructor(Java.Locatable locatable, Java.Scope scope, Java.Rvalue enclosingInstance, IType targetType, Java.Rvalue[] arguments) Expects the object to initialize on the stack.private voidinvokeMethod(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 booleanisAccessible(IClass.IMember member, Java.Scope contextScope) Determines whether the givenIClass.IMemberis accessible in the given context, according to JLS7 6.6.1.BL1.B4.private booleanisAccessible(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 booleanisAccessible(IClass type, Java.Scope contextScope) Determines whether the givenIClassis accessible in the given context, according to JLS7 6.6.1.2 and 6.6.1.4.private static booleanprivate static booleanisAssignableFrom(IType targetType, IType sourceType) private IClassisBoxingConvertible(IType sourceType) private static Byteprivate booleanisCastReferenceConvertible(IType sourceType, IType targetType) JLS7 5.5private booleanisConvertibleToPrimitiveNumeric(IType sourceType) private booleanisIdentityConvertible(IType sourceType, IType targetType) Checks whether "identity conversion" (5.1.1) is possible.private static booleanisInterface(IType type) (package private) Java.LocalVariableChecks whether the operand is anintlocal variable.private booleanisMethodInvocationConvertible(IClass sourceType, IClass targetType, boolean boxingPermitted) Checks if "method invocation conversion" (5.3) is possible.private booleanisNarrowingPrimitiveConvertible(IType sourceType, IType targetType) Checks whether "narrowing primitive conversion" (JLS7 5.1.3) is possible.private booleanisNarrowingReferenceConvertible(IType sourceType, IType targetType) Checks whether "narrowing reference conversion" (JLS7 5.1.5) is possible.private booleanisNullConvertible(IType sourceType, IType targetType) private static booleanisPrimitive(IType type) private static booleanprivate booleanprivate booleanprivate booleanprivate IClassisUnboxingConvertible(IType sourceType) private booleanisWideningPrimitiveConvertible(IClass sourceType, IType targetType) private booleanisWideningReferenceConvertible(IType sourceType, IType targetType) Checks if "widening reference conversion" (5.1.4) is possible.private voidl2i(Java.Locatable locatable) private static Stringprivate voidCleans up the statement context.private voidprivate voidprivate voidprivate voidleaveStatements(Java.Scope from, Java.Scope to) Statements that jump out of blocks (return,break,continue) must call this method to make sure that thefinallyclauses of alltry ... catchandsynchronizedstatements are executed.private voidload(Java.Locatable locatable, IType localVariableType, int localVariableIndex) private ITypeload(Java.Locatable locatable, Java.LocalVariable localVariable) private voidlookupswitch(Java.Locatable locatable, SortedMap<Integer, CodeContext.Offset> caseLabelMap, CodeContext.Offset defaultLabelOffset) private static voidMakes the variable name and class name Constant Pool names used by local variables.private static String[]Only strings that can be UTF8-encoded into 65535 bytes can be stored as a constant string info.private voidmaybeCreateInitMethod(Java.TypeDeclaration td, ClassFile cf, List<Java.BlockStatement> statements) Creates class/interface initialization method iff there is any initialization code.private static booleanmayHaveSideEffects(Java.ArrayInitializerOrRvalue arrayInitializerOrRvalue) private static booleanmayHaveSideEffects(Java.ArrayInitializerOrRvalue... arrayInitializersOrRvalues) private voidmonitorenter(Java.Locatable locatable) private voidmonitorexit(Java.Locatable locatable) private voidmulDivRemAddSub(Java.Locatable locatable, String operator) private voidmultianewarray(Java.Locatable locatable, int dimExprCount, int dims, IType componentType) private voidneg(Java.Locatable locatable, IClass operandType) private voidneW(Java.Locatable locatable, IType iType) private voidnewarray(Java.Locatable locatable, IType componentType) private IClassnewArray(Java.Locatable locatable, int dimExprCount, int dims, IType componentType) Expects dimExprCount values of typeinton the operand stack.private ClassFilenewClassFile(short accessFlags, IClass iClass, IClass superclass, IClass[] interfaces) private voidnumericPromotion(Java.Locatable locatable, IType sourceType, IClass targetType) options()options(EnumSet<JaninoOption> options) Sets the options for all future compilations.private booleanoverridesMethod(IClass.IMethod method, IClass type) private booleanprivate voidpop(Java.Locatable locatable, IType type) private voidputfield(Java.Locatable locatable, IClass.IField iField) private static IClassprivate static IClass[]rawTypesOf(IType[] iTypes) private Java.Atomprivate Java.AtomreclassifyName(Location location, Java.Scope scope, String identifier) JLS7 6.5.2.1private Java.AtomreclassifyName(Location location, Java.Scope scope, String[] identifiers, int n) Reclassifies the ambiguous name consisting of the first n of the identifiers (JLS7 6.5.2.2).private voidreferenceThis(Java.Locatable locatable, IClass currentIClass) private voidreferenceThis(Java.Locatable locatable, Java.AbstractTypeDeclaration declaringType, Java.TypeBodyDeclaration declaringTypeBodyDeclaration, IType targetIType) private CodeContextreplaceCodeContext(CodeContext newCodeContext) private IClassprivate voidreturN(Java.Locatable locatable) private voidreverseUnaryNumericPromotion(Java.Locatable locatable, IClass sourceType, IType targetType) voidsetCompileErrorHandler(ErrorHandler compileErrorHandler) By default,CompileExceptions are thrown on compile errors, but an application my install its own (thread-local)ErrorHandler.voidsetTargetVersion(int version) Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's-targetcommand line option.voidsetWarningHandler(WarningHandler warningHandler) By default, warnings are discarded, but an application my install a customWarningHandler.private voidshift(Java.Locatable locatable, String operator) private voidstore(Java.Locatable locatable, IType lvType, short lvIndex) private voidstore(Java.Locatable locatable, Java.LocalVariable localVariable) Assigns the top operand to the given local variable.private voidstringConversion(Java.Locatable locatable, IType sourceType) Converts object of type "sourceType" to type "String" (JLS7 15.18.1.1).private voidsub(Java.Locatable locatable) private voidswap(Java.Locatable locatable) private voidtableswitch(Java.Locatable locatable, SortedMap<Integer, CodeContext.Offset> caseLabelMap, CodeContext.Offset defaultLabelOffset) private IClass.IAnnotationtoIAnnotation(Java.Annotation annotation) private IClass.IAnnotation[]toIAnnotations(Java.Annotation[] annotations) (package private) IClass.IConstructortoIConstructor(Java.ConstructorDeclarator constructorDeclarator) private IClass.IInvocabletoIMethod(Java.MethodDeclarator methodDeclarator) private Java.Lvalueprivate Java.Rvalueprivate Java.Typeprivate booleantryAssignmentConversion(Java.Locatable locatable, IType sourceType, IType targetType, Object constantValue) private booleantryBoxingConversion(Java.Locatable locatable, IType sourceType, IType targetType) private booleantryCastConversion(Java.Locatable locatable, IType sourceType, IType targetType, Object constantValue) private booleantryConstantAssignmentConversion(Java.Locatable locatable, Object constantValue, IType targetType) Checks if "constant assignment conversion" (JLS7 5.2, paragraph 1) is possible.private booleantryIdentityConversion(IType sourceType, IType targetType) Implements "identity conversion" (5.1.1).private booleantryNarrowingPrimitiveConversion(Java.Locatable locatable, IType sourceType, IType targetType) Implements "narrowing primitive conversion" (JLS7 5.1.3).private booleantryNarrowingReferenceConversion(Java.Locatable locatable, IType sourceType, IType targetType) Implements "narrowing reference conversion" (5.1.5).private booleantryNullConversion(IType sourceType, IType targetType) JLS11 5.2: "Finally, a value of the null type (the null reference is the only such value) may be assigned to any reference type".private booleantryWideningPrimitiveConversion(Java.Locatable locatable, IType sourceType, IType targetType) Implements "widening primitive conversion" (5.1.2).private ITypeprivate IClassunaryNumericPromotion(Java.Locatable locatable, IType type) Implements "unary numeric promotion" (JLS7 5.6.1).private IClassunaryNumericPromotionType(Java.Locatable locatable, IType type) private voidunboxingConversion(Java.Locatable locatable, IType sourceType, IClass targetType) private static StringDecodes any escape sequences like\n, or\377, but not\uxxxx.private voidupdateLocalVariableInCurrentStackMap(short lvIndex, ClassFile.StackMapTableAttribute.VerificationTypeInfo vti) verificationTypeInfo(IType type) private voidIssues a warning with the given message an location an returns.private voidwrite(int v) private voidwriteByte(int v) private voidwriteConstantClassInfo(IClass iClass) private voidwriteConstantFieldrefInfo(IClass iClass, String fieldName, IClass fieldType) private voidwriteConstantInterfaceMethodrefInfo(IClass iClass, String methodName, MethodDescriptor methodMd) private voidwriteConstantMethodrefInfo(IClass iClass, String methodName, MethodDescriptor methodMd) private voidwriteInt(int v) private voidwriteLdc(short constantPoolIndex) private voidwriteLdc2(short constantPoolIndex) private voidwriteOffset(CodeContext.Offset src, CodeContext.Offset dst) private voidwriteShort(int v) private voidwriteUnsignedShort(int v) private voidxaload(Java.Locatable locatable, IType componentType) private voidxor(Java.Locatable locatable, int opcode) private voidxreturn(Java.Locatable locatable, IType returnType)
-
Field Details
-
LOGGER
-
defaultTargetVersion
private static final int defaultTargetVersion -
STRING_CONCAT_LIMIT
private static final int STRING_CONCAT_LIMITThis constant determines the number of operands up to which thea.concat(b).concat(c)strategy is used to implement string concatenation. For more operands, the
new StringBuilder(a).append(b).append(c).append(d).toString()strategy is chosen.A very good article from Tom Gibara analyzes the impact of this decision and recommends a value of three.
- See Also:
-
JUMP_IF_TRUE
public static final boolean JUMP_IF_TRUESpecial value for the orientation parameter of thecompileBoolean(Java.Rvalue, CodeContext.Offset, boolean)methods, indicating that the code should be generated such that execution branches if the value on top of the operand stack is TRUE.- See Also:
-
JUMP_IF_FALSE
public static final boolean JUMP_IF_FALSESpecial value for the orientation parameter of thecompileBoolean(Java.Rvalue, CodeContext.Offset, boolean)methods, indicating that the code should be generated such that execution branches if the value on top of the operand stack is FALSE.- See Also:
-
LOOKS_LIKE_TYPE_PARAMETER
-
options
-
targetVersion
private int targetVersionJava version to compile for. -
MAY_HAVE_SIDE_EFFECTS_VISITOR
private static final Visitor.ArrayInitializerOrRvalueVisitor<Boolean, RuntimeException> MAY_HAVE_SIDE_EFFECTS_VISITOR -
NOT_CONSTANT
Special return value for thegetConstantValue(Java.Rvalue)method family indicating that the givenJava.Rvaluedoes not evaluate to a constant value. -
TWO_E_31_INTEGER
2147483648 is the special value that can not be stored in an INT, but its negated value (-2147483648) can. -
TWO_E_63_LONG
9223372036854775808 is the special value that can not be stored in a LONG, but its negated value (-9223372036854775808) can. -
singleTypeImports
To be used only bygetSingleTypeImport(String, Location);nullmeans "not yet initialized" -
onDemandImportableTypes
-
PRIMITIVE_WIDENING_CONVERSIONS
-
PRIMITIVE_NARROWING_CONVERSIONS
-
EQ
private static final int EQ- See Also:
-
NE
private static final int NE- See Also:
-
LT
private static final int LT- See Also:
-
GE
private static final int GE- See Also:
-
GT
private static final int GT- See Also:
-
LE
private static final int LE- See Also:
-
codeContext
-
compileErrorHandler
-
compileErrorCount
private int compileErrorCount -
warningHandler
-
abstractCompilationUnit
-
iClassLoader
-
storesClassFiles
Non-nullwhilecompileUnit(boolean, boolean, boolean, ClassFileConsumer)is executing. -
debugSource
private boolean debugSource -
debugLines
private boolean debugLines -
debugVars
private boolean debugVars
-
-
Constructor Details
-
UnitCompiler
public UnitCompiler(Java.AbstractCompilationUnit abstractCompilationUnit, IClassLoader iClassLoader)
-
-
Method Details
-
options
- Returns:
- A reference to the currently effective compilation options; changes to it take effect immediately
-
options
Sets the options for all future compilations. -
setTargetVersion
public void setTargetVersion(int version) Generates class files that target a specified release of the virtual machine, in analogy with JAVAC's-targetcommand line option. By default, Java 6 .class files are generated. -
getAbstractCompilationUnit
- Returns:
- The
Java.AbstractCompilationUnitthat thisUnitCompilercompiles
-
compileUnit
public void compileUnit(boolean debugSource, boolean debugLines, boolean debugVars, Collection<ClassFile> generatedClassFiles) throws CompileException Generates a set ofClassFileobjects which represent the classes and interfaces declared in the compilation unit.- Parameters:
generatedClassFiles- Adds generatedClassFiles to thisCollection- Throws:
CompileException
-
compileUnit
public void compileUnit(boolean debugSource, boolean debugLines, boolean debugVars, UnitCompiler.ClassFileConsumer storesClassFiles) throws CompileException Generates a set ofClassFileobjects which represent the classes and interfaces declared in the compilation unit.- Parameters:
storesClassFiles- Consumes each generatedClassFile- Throws:
CompileException
-
compile2
Compiles an (ordinary, not modular) compilation unit- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile
- Throws:
CompileException
-
compile2
Compiles a top-level class or enum declaration.- Throws:
CompileException
-
compile2
Compiles a top-level interface or annotation type declaration.- Throws:
CompileException
-
checkForNameConflictWithAnotherPackageMemberTypeDeclaration
private void checkForNameConflictWithAnotherPackageMemberTypeDeclaration(Java.PackageMemberTypeDeclaration pmtd) throws CompileException - Throws:
CompileException
-
checkForConflictWithSingleTypeImport
private void checkForConflictWithSingleTypeImport(String name, Location location) throws CompileException - Throws:
CompileException
-
compile2
- Throws:
CompileException
-
addClassFile
-
addFields
Creates and addsClassFile.FieldInfos to the cf for all fields declared by the fd.- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
fakeCompileVariableDeclaratorsAndInitializers
private void fakeCompileVariableDeclaratorsAndInitializers(Java.AbstractClassDeclaration cd) throws CompileException - Throws:
CompileException
-
compile2
- Throws:
CompileException
-
newClassFile
private ClassFile newClassFile(short accessFlags, IClass iClass, @Nullable IClass superclass, IClass[] interfaces) throws CompileException - Parameters:
superclass-nullforObject,Objectfor 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, boolean compileAsArray) throws CompileException - Throws:
CompileException
-
maybeCreateInitMethod
private void maybeCreateInitMethod(Java.TypeDeclaration td, ClassFile cf, List<Java.BlockStatement> statements) throws CompileException Creates class/interface initialization method iff there is any initialization code.- Parameters:
td- The type declarationcf- The class file into which to put the methodstatements- The statements for the method (possibly empty)- Throws:
CompileException
-
compileDeclaredMemberTypes
private void compileDeclaredMemberTypes(Java.TypeDeclaration decl, ClassFile cf) throws CompileException Compiles all of the types for this declarationNB: as a side effect this will fill in the synthetic field map
- Throws:
CompileException
-
compileDeclaredMethods
private void compileDeclaredMethods(Java.TypeDeclaration typeDeclaration, ClassFile cf) throws CompileException Compiles all of the methods for this declarationNB: as a side effect this will fill in the synthetic field map invalid input: '<'/p
- Throws:
CompileException
-
compileDeclaredMethods
private void compileDeclaredMethods(Java.TypeDeclaration typeDeclaration, ClassFile cf, int startPos) throws CompileException Compiles methods for this declaration starting at startPos.- Parameters:
startPos- Starting parameter to fill in- Throws:
CompileException
-
hasAnnotation
private boolean hasAnnotation(Java.FunctionDeclarator fd, IClass annotationType) throws CompileException - Throws:
CompileException
-
overridesMethodFromSupertype
- Throws:
CompileException
-
overridesMethod
- Returns:
- Whether method overrides a method of type or any of its supertypes
- Throws:
CompileException
-
generateBridgeMethod
private void generateBridgeMethod(ClassFile cf, IClass declaringIClass, IClass.IMethod base, IClass.IMethod override) throws CompileException Generates and compiles a bridge method with signature base that delegates to override.- Throws:
CompileException
-
compile
- Returns:
- Whether this statement can complete normally (JLS7 14.1)
- Throws:
CompileException
-
fakeCompile
Called to check whether the givenJava.BlockStatementcompiles or not. Updates the stack map of the current inserter.- Returns:
- Whether the block statement can complete normally
- Throws:
CompileException
-
getCodeContext
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compileStatements
private boolean compileStatements(List<? extends Java.BlockStatement> statements) throws CompileException - Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
allocateLocalVariable
-
allocateLocalVariableAndMarkAsInitialized
private Java.LocalVariable allocateLocalVariableAndMarkAsInitialized(boolean finaL, IType localVariableType) -
compile2
- Throws:
CompileException
-
compileUnconditionalLoop
private boolean compileUnconditionalLoop(Java.ContinuableStatement cs, Java.BlockStatement body, @Nullable Java.Rvalue[] update) throws CompileException - Throws:
CompileException
-
compileUnconditionalLoopWithUpdate
private boolean compileUnconditionalLoopWithUpdate(Java.ContinuableStatement cs, Java.BlockStatement body, Java.Rvalue[] update) throws CompileException - Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
findLocalClassDeclaration
@Nullable private static Java.LocalClassDeclaration findLocalClassDeclaration(Java.Scope s, String name) Finds a local class declared in any block enclosing the given block statement. -
compile2
- Throws:
CompileException
-
compile
- Throws:
CompileException
-
verificationTypeInfo
private ClassFile.StackMapTableAttribute.VerificationTypeInfo verificationTypeInfo(@Nullable IType type) -
getLocalVariable
public Java.LocalVariable getLocalVariable(Java.LocalVariableDeclarationStatement lvds, Java.VariableDeclarator vd) throws CompileException - Returns:
- The
Java.LocalVariablecorresponding with the local variable declaration/declarator - Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compileTryCatchFinallyWithResources
private boolean compileTryCatchFinallyWithResources(Java.TryStatement ts, List<Java.TryStatement.Resource> resources, UnitCompiler.Compilable2 compileBody, @Nullable Java.Block finallY) throws CompileException Generates code for a TRY statement with (possibly zero) resources and an (optional) FINALLY clause.- Returns:
- Whether the code can complete normally
- Throws:
CompileException
-
compileTryCatchFinally
private boolean compileTryCatchFinally(Java.TryStatement ts, UnitCompiler.Compilable2 compileBody, @Nullable Java.BlockStatement finallY) throws CompileException Generates code for a TRY statement without resources, but with an (optional) FINALLY clause.- Returns:
- Whether the code can complete normally
- Throws:
CompileException
-
compileTryCatch
private boolean compileTryCatch(Java.TryStatement tryStatement, UnitCompiler.Compilable2 compileBody, CodeContext.Offset beginningOfBody, CodeContext.Offset afterStatement) throws CompileException Generates code for a TRY statement without resources and without a FINALLY clause.- Returns:
- Whether the code can complete normally
- Throws:
CompileException
-
compile
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
addMethodInfo
private static ClassFile.MethodInfo addMethodInfo(Java.Locatable locatable, ClassFile classFile, short accessFlags, String methodName, MethodDescriptor methodMd) throws CompileException - Throws:
CompileException
-
getTargetVersion
public int getTargetVersion() -
getDefaultTargetVersion
public static int getDefaultTargetVersion()- Returns:
- The target version that applies iff no target version is actively configured with
setTargetVersion(int)
-
makeLocalVariableNames
Makes the variable name and class name Constant Pool names used by local variables. -
buildLocalVariableMap
- Throws:
CompileException
-
allocateLocalVariableSlot
private Java.LocalVariableSlot allocateLocalVariableSlot(IType localVariableType, @Nullable String localVariableName) -
allocateLocalVariableSlotAndMarkAsInitialized
private Java.LocalVariableSlot allocateLocalVariableSlotAndMarkAsInitialized(IType localVariableType, @Nullable String localVariableName) -
buildLocalVariableMap
private Map<String, Java.LocalVariable> buildLocalVariableMap(Java.BlockStatement blockStatement, Map<String, Java.LocalVariable> localVars) throws CompileException Computes and fills in the 'local variable map' for the given blockStatement.- Throws:
CompileException
-
buildLocalVariableMap
private static Map<String, Java.LocalVariable> buildLocalVariableMap(Java.Statement s, Map<String, Java.LocalVariable> localVars) -
buildLocalVariableMap
private static Map<String, Java.LocalVariable> buildLocalVariableMap(Java.ConstructorInvocation ci, Map<String, Java.LocalVariable> localVars) -
buildLocalVariableMap
private void buildLocalVariableMap(Java.Block block, Map<String, Java.LocalVariable> localVars) throws CompileException - Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.DoStatement ds, Map<String, Java.LocalVariable> localVars) throws CompileException - Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.ForStatement fs, Map<String, Java.LocalVariable> localVars) throws CompileException - Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.ForEachStatement fes, Map<String, Java.LocalVariable> localVars) throws CompileException - Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.IfStatement is, Map<String, Java.LocalVariable> localVars) throws CompileException - Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.Initializer i, Map<String, Java.LocalVariable> localVars) throws CompileException - Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.SwitchStatement ss, Map<String, Java.LocalVariable> localVars) throws CompileException - Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.SynchronizedStatement ss, Map<String, Java.LocalVariable> localVars) throws CompileException - Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.TryStatement ts, Map<String, Java.LocalVariable> localVars) throws CompileException - Throws:
CompileException
-
buildLocalVariableMap
private void buildLocalVariableMap(Java.WhileStatement ws, Map<String, Java.LocalVariable> localVars) throws CompileException - Throws:
CompileException
-
buildLocalVariableMap
private Map<String, Java.LocalVariable> buildLocalVariableMap(Java.LabeledStatement ls, Map<String, Java.LocalVariable> localVars) throws CompileException - Throws:
CompileException
-
buildLocalVariableMap
private Map<String, Java.LocalVariable> buildLocalVariableMap(Java.LocalVariableDeclarationStatement lvds, Map<String, Java.LocalVariable> localVars) throws CompileException - Throws:
CompileException
-
buildLocalVariableMap
protected void buildLocalVariableMap(Java.CatchClause catchClause, Map<String, Java.LocalVariable> localVars) throws 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.LocalVariablecorresponding 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.LocalVariablecorresponding with the parameter - Throws:
CompileException
-
getLocalVariable
- Returns:
- The
Java.LocalVariablecorresponding with the parameter - Throws:
CompileException
-
fakeCompile
Called to check whether the givenJava.Rvaluecompiles or not.- Throws:
CompileException
-
compile
SomeJava.Rvalues compile more efficiently when their value is not needed, e.g. "i++".- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compile2
- Throws:
CompileException
-
compileBoolean
private void compileBoolean(Java.Rvalue rv, CodeContext.Offset dst, boolean orientation) throws CompileException Compiles anJava.Rvalueand branches, depending on the value.Many
Java.Rvalues compile more efficiently when their value is the condition for a branch, thus this method generally produces more efficient bytecode thancompile(Rvalue)followed by.invalid reference
#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_TRUEorJUMP_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_TRUEorJUMP_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_TRUEorJUMP_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_TRUEorJUMP_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_TRUEorJUMP_IF_FALSE- Throws:
CompileException
-
compileContext
Generates code that determines the context of theJava.Rvalueand puts it on the operand stack. Most expressions do not have a "context", but some do. E.g. for "x[y]", the context is "x, y". The bottom line is that for statements like "x[y] += 3" the context is only evaluated once.- Returns:
- The number of operands that is pushed on the operand stack (0, 1 or 2)
- Throws:
CompileException
-
compileContext2
-
compileContext2
- Throws:
CompileException
-
compileContext2
- Throws:
CompileException
-
compileContext2
- Throws:
CompileException
-
compileContext2
Array access expression; see JLS7 15.13 / JLS8+ 15.10.3.- Throws:
CompileException
-
compileContext2
- Throws:
CompileException
-
compileContext2
- Throws:
CompileException
-
compileContext2
- Throws:
CompileException
-
compileGet
Generates code that determines the value of theJava.Rvalueand puts it on the operand stack. This method relies on that the "context" of theJava.Rvalueis on top of the operand stack (seecompileContext(Rvalue)).- Returns:
- The type of the
Java.Rvalue - Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
-
compileGet2
- Throws:
CompileException
-
compileGet2
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
commonSupertype
- Throws:
CompileException
-
commonSupertype2
- Throws:
CompileException
-
isByteConstant
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
getComponentType
-
isPrimitive
-
getSuperclass
- Throws:
CompileException
-
isInterface
-
getInterfaces
- Throws:
CompileException
-
isArray
-
isAssignableFrom
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
isStaticContext
-
mayHaveSideEffects
private static boolean mayHaveSideEffects(Java.ArrayInitializerOrRvalue... arrayInitializersOrRvalues) -
mayHaveSideEffects
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGetValue
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGet2
- Throws:
CompileException
-
compileGetValue
Convenience function that callscompileContext(Rvalue)andcompileGet(Rvalue).- Returns:
- The type of the Rvalue
- Throws:
CompileException
-
getConstantValue
@Nullable public final Object getConstantValue(Java.ArrayInitializerOrRvalue 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 thenullliteral.This method cannot be STATIC, because the constant value may refer to a constant declaration in this compilation unit.
- Returns:
NOT_CONSTANTiff the rvalue is not a constant value- Throws:
CompileException
-
getConstantValue
Attempts to evaluate as a constant expression. The result is one of the following:Boolean,Byte,Short,Integer,Long,Float,Double,Character,String,null(representing thenullliteral.This method cannot be STATIC, because the constant value may refer to a constant declaration in this compilation unit.
- Returns:
NOT_CONSTANTiff the rvalue is not a constant value- Throws:
CompileException
-
getConstantValue2
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Returns:
- An
Integeror aLong - Throws:
CompileException
-
getConstantValue2
- Returns:
- A
Floator aDouble - Throws:
CompileException
-
getConstantValue2
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
- Throws:
CompileException
-
getConstantValue2
-
getConstantValue2
-
generatesCode
Checks whether invocation ofcompile(BlockStatement)would generate more than zero code bytes.- Throws:
CompileException
-
generatesCode2
-
generatesCode2
-
generatesCode2
-
generatesCode2
-
generatesCode2
- Throws:
CompileException
-
generatesCode2
- Throws:
CompileException
-
generatesCode2
- Throws:
CompileException
-
generatesCode2
- Throws:
CompileException
-
leave
Cleans up the statement context. This is currently relevant for "try ... catch ... finally" statements (executefinallyclause) andsynchronizedstatements (monitorexit).Statements like
return,break,continuemust call this method for all the statements they terminate.- Throws:
CompileException
-
leave2
-
leave2
-
leave2
- Throws:
CompileException
-
compileSet
Generates code that stores a value in theJava.Lvalue. Expects theJava.Lvalue's context (seecompileContext(Java.Rvalue)) and a value of theJava.Lvalue's type on the operand stack.- Throws:
CompileException
-
compileSet2
- Throws:
CompileException
-
compileSet2
-
compileSet2
- Throws:
CompileException
-
compileSet2
- Throws:
CompileException
-
compileSet2
- Throws:
CompileException
-
compileSet2
- Throws:
CompileException
-
compileSet2
- Throws:
CompileException
-
getType
- Returns:
- For a
Java.Type, the resolvedIClass, for anJava.Rvalue, the resolvedIClassof the rvalue's type - Throws:
CompileException- See Also:
-
rawTypeOf
-
rawTypesOf
-
getRawType
- Throws:
CompileException
-
getType
- Throws:
CompileException
-
getTypes
- Throws:
CompileException
-
getType
- Throws:
CompileException
-
getType
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
-
getType2
-
getType2
- Throws:
CompileException
-
getReferenceType
@Nullable private IType getReferenceType(Location location, Java.Scope scope, String[] identifiers, int n, @Nullable Java.TypeArgument[] typeArguments) throws CompileException - Parameters:
typeArguments- Zero-length array if type has no type variables- Returns:
- The resolved
IClass, orIParameterizedType, ornull - Throws:
CompileException
-
getReferenceType
private IType getReferenceType(Location location, String simpleTypeName, @Nullable Java.TypeArgument[] typeArguments, Java.Scope scope) throws CompileException JLS7 6.5.5.1 Simple type name (single identifier)- Parameters:
typeArguments- Zero-length array if type is not parameterized- Returns:
- The resolved
IClassorIParameterizedType - Throws:
CompileException
-
typeArgumentToIType
- Throws:
CompileException
-
getRawReferenceType
private IClass getRawReferenceType(Location location, String simpleTypeName, Java.Scope scope) throws CompileException - Throws:
CompileException
-
importStaticOnDemand
Imports a member class or interface, static field or static method via the compilation unit's static import on-demand declarations.- Returns:
- A list of
IClass.IFields,IClass.IMethods and/orIClasses with that simpleName; may be empty - Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
-
getType2
- Throws:
CompileException
-
getType2
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
-
getType2
- Throws:
CompileException
-
getUnboxedType
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
- Throws:
CompileException
-
getType2
-
getType2
-
getType2
-
getType2
-
getType2
-
getType2
-
getType2
-
getType2
-
isType
- Throws:
CompileException
-
isType2
-
isType2
- Throws:
CompileException
-
isAccessible
private boolean isAccessible(IClass.IMember member, Java.Scope contextScope) throws CompileException Determines whether the givenIClass.IMemberis 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.IMemberis accessible in the given context, according to JLS7 6.6.1.BL1.B4. Issues acompileError(String)if not.- Throws:
CompileException
-
isAccessible
private boolean isAccessible(IClass iClassDeclaringMember, Access memberAccess, Java.Scope contextScope) throws CompileException Determines whether a member (class, interface, field or method) declared in a given class is accessible from a given block statement context, according to JLS7 6.6.1.4.- Throws:
CompileException
-
checkMemberAccessible
private void checkMemberAccessible(IClass iClassDeclaringMember, IClass.IMember member, Java.Scope contextScope, Location location) throws CompileException Verifies that a member (class, interface, field or method) declared in a given class is accessible from a given block statement context, according to JLS7 6.6.1.4. Issue acompileError(String)if not.- Throws:
CompileException
-
internalCheckAccessible
@Nullable private String internalCheckAccessible(IClass iClassDeclaringMember, Access memberAccess, Java.Scope contextScope) throws CompileException - Returns:
- a descriptive text iff a member declared in that
IClasswith thatAccessis inaccessible - Throws:
CompileException
-
isAccessible
Determines whether the givenIClassis 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 givenIClassis accessible in the given context, according to JLS7 6.6.1.2 and 6.6.1.4. Issues acompileError(String)if not.- Throws:
CompileException
-
internalCheckAccessible
@Nullable private String internalCheckAccessible(IClass type, Java.Scope contextScope) throws CompileException - Returns:
- An error message, or
null - Throws:
CompileException
-
toTypeOrCompileException
- Throws:
CompileException
-
toRvalueOrCompileException
- Throws:
CompileException
-
toLvalueOrCompileException
- Throws:
CompileException
-
assignSyntheticParametersToSyntheticFields
void assignSyntheticParametersToSyntheticFields(Java.ConstructorDeclarator cd) throws CompileException Copies the values of the synthetic parameters of this constructor ("this$..." and "val$...") to the synthetic fields of the object ("this$..." and "val$...").- Throws:
CompileException
-
initializeInstanceVariablesAndInvokeInstanceInitializers
void initializeInstanceVariablesAndInvokeInstanceInitializers(Java.ConstructorDeclarator cd) throws CompileException Compiles the instance variable initializers and the instance initializers in their lexical order.- Throws:
CompileException
-
leaveStatements
Statements that jump out of blocks (return,break,continue) must call this method to make sure that thefinallyclauses of alltry ... catchandsynchronizedstatements are executed.- Throws:
CompileException
-
compileArithmeticBinaryOperation
private IType compileArithmeticBinaryOperation(Java.Locatable locatable, IType lhsType, String operator, Java.Rvalue rhs) throws CompileException The LHS operand of type lhsType is expected on the stack.The following operators are supported:
| ^ & * / % + - << >> >>>- Throws:
CompileException
-
compileArithmeticOperation
private IType compileArithmeticOperation(Java.Locatable locatable, @Nullable IType firstOperandType, Iterator<Java.Rvalue> operands, String operator) throws CompileException Executes an arithmetic operation on a sequence of operands. If type is non-null, then the first operand with that type is already on the stack.The following operators are supported:
| ^ & * / % + - << >> >>>- Throws:
CompileException
-
compileStringConcatenation
private IClass compileStringConcatenation(Java.Locatable locatable, IType type, Java.Rvalue secondOperand, Iterator<Java.Rvalue> operands) throws CompileException - Parameters:
type- The type of the first operand, which is already on the stacksecondOperand- The second operandoperands- All following operands- Throws:
CompileException
-
stringConversion
Converts object of type "sourceType" to type "String" (JLS7 15.18.1.1).- Throws:
CompileException
-
invokeConstructor
private void invokeConstructor(Java.Locatable locatable, Java.Scope scope, @Nullable Java.Rvalue enclosingInstance, IType targetType, Java.Rvalue[] arguments) throws CompileException Expects the object to initialize on the stack.Notice: This method is used both for explicit constructor invocation (first statement of a constructor body) and implicit constructor invocation (right after NEW).
- Parameters:
enclosingInstance- Used if the target class is an inner class- Throws:
CompileException
-
compileFields
- Returns:
- The
IClass.IFields that are declared by the fieldDeclaration
-
compileField
private IClass.IField compileField(Java.TypeDeclaration declaringType, Java.Annotation[] annotations, Access access, boolean statiC, boolean finaL, Java.Type type, int brackets, String name, @Nullable Java.ArrayInitializerOrRvalue initializer) Compiles one variable declarator into anIClass.IField.Example: "b" in in the variable declaration
class Foo { @Deprecated private int[] a, b[], c; }- Parameters:
declaringType- "class Foo"type- "int[]"
-
getNonConstantFinalInitializer
@Nullable Java.ArrayInitializerOrRvalue getNonConstantFinalInitializer(Java.FieldDeclaration fd, Java.VariableDeclarator vd) throws CompileException Determines the non-constant-final initializer of the givenJava.VariableDeclarator.- Returns:
nullif the variable is declared without an initializer or if the initializer is constant-final- Throws:
CompileException
-
reclassify
- Throws:
CompileException
-
toIAnnotations
- Throws:
CompileException
-
toIAnnotation
- Throws:
CompileException
-
reclassifyName
private Java.Atom reclassifyName(Location location, Java.Scope scope, String[] identifiers, int n) throws CompileException Reclassifies the ambiguous name consisting of the first n of the identifiers (JLS7 6.5.2.2).- Throws:
CompileException
-
findTypeByName
@Nullable private IClass findTypeByName(Location location, String className) throws CompileException Finds the namedIClassin this compilation unit, or through theiClassLoader.- Parameters:
className- Fully qualified class name, e.g. "pkg1.pkg2.Outer$Inner"- Returns:
nulliff anIClasswith that name could not be loaded- Throws:
CompileException- An exception was raised while loading theIClass
-
reclassifyName
private Java.Atom reclassifyName(Location location, Java.Scope scope, String identifier) throws CompileException JLS7 6.5.2.1- Throws:
CompileException
-
importSingleStatic
Imports a member class, member interface, static field or static method via the compilation unit's single static import declarations.- Returns:
- A list of
IClass.IFields,IClass.IMethods and/orIClasses with that simpleName; may be empty - Throws:
CompileException
-
importStatic
private void importStatic(IClass declaringIClass, String simpleName, Collection<Object> result, Location location) throws CompileException Finds all members (member classes, member interfaces, static fields and/or static methods) of the declaringIClass with the given simpleName and adds them to the result.- Parameters:
declaringIClass- The class or interface that declares the membersresult- Results (IClasses,IClass.IFields and/orIClass.IMethods) are added to this collection- Throws:
CompileException
-
determineValue
- Returns:
- Either the
Java.FieldAccessor anJava.ArrayLength - Throws:
CompileException
-
determineValue
private Java.Rvalue determineValue(Java.SuperclassFieldAccessExpression scfae) throws CompileException "super.fld", "Type.super.fld"- Throws:
CompileException
-
findIMethod
Finds methods of the mi.targetnamed 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.IMethodmay be declared in an enclosing type.- Returns:
- The selected
IClass.IMethod - Throws:
CompileException
-
findIMethod
@Nullable private IClass.IMethod findIMethod(IType targetType, Java.Invocation invocation) throws CompileException Finds aIClass.IMethodin 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:
nullif no appropriate method could be found- Throws:
CompileException
-
fakeIMethod
private IClass.IMethod fakeIMethod(IClass targetType, String name, Java.Rvalue[] arguments) throws CompileException - Throws:
CompileException
-
getIMethods
public void getIMethods(IClass type, String methodName, List<IClass.IMethod> v) throws CompileException Adds all methods with the given methodName that are declared by the type, its superclasses and all their superinterfaces to the result list v.- Throws:
CompileException
-
findIMethod
public IClass.IMethod findIMethod(Java.SuperclassMethodInvocation superclassMethodInvocation) throws CompileException - Returns:
- The
IClass.IMethodthat 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.IInvocableornullif noIClass.IInvocableis applicable - Throws:
CompileException
-
assertNonNull
-
isMethodInvocationConvertible
private boolean isMethodInvocationConvertible(IClass sourceType, IClass targetType, boolean boxingPermitted) throws CompileException Checks if "method invocation conversion" (5.3) is possible.- Throws:
CompileException
-
checkThrownExceptions
private void checkThrownExceptions(Java.Invocation in, IClass.IMethod iMethod) throws CompileException - Throws:
CompileException- if theJava.Invocationthrows exceptions that are disallowed in the given scope
-
checkThrownException
private void checkThrownException(Java.Locatable locatable, IType type, Java.Scope scope) throws CompileException - Throws:
CompileException- The exception with the given type must not be thrown in the given scope
-
getTargetIType
- Throws:
CompileException
-
isIntLv
Checks whether the operand is anintlocal variable.- Returns:
nulliff c is not anintlocal variable- Throws:
CompileException
-
resolve
-
referenceThis
private void referenceThis(Java.Locatable locatable, Java.AbstractTypeDeclaration declaringType, Java.TypeBodyDeclaration declaringTypeBodyDeclaration, IType targetIType) throws CompileException - Throws:
CompileException
-
getOuterClasses
Returns a list consisting of the given inner class and all its enclosing (outer) classes.- Returns:
ListofJava.TypeDeclaration; has length one iff inner has no enclosing instance
-
getOuterClass
- Returns:
- The
Java.TypeDeclarationthat immediately encloses the typeDeclaration, ornull
-
getIClass
- Throws:
CompileException
-
getReturnType
- Throws:
CompileException
-
toIConstructor
- Returns:
- the
IClass.IConstructorthat implements the constructorDeclarator
-
toIMethod
- Returns:
- The
IClass.IMethodthat implements the methodDeclarator
-
toIInvocable
-
importSingleType
@Nullable private IClass importSingleType(String simpleTypeName, Location location) throws CompileException If the given name was declared in a simple type import, load that class.- Throws:
CompileException
-
getSingleTypeImport
@Nullable public String[] getSingleTypeImport(String name, Location location) throws CompileException Checks if the given simple name was imported through a single type import.- Parameters:
name- The simple type name, e.g."Inner"- Returns:
- The fully qualified name, e.g.
{ "pkg", "Outer", "Inner" }, ornull - Throws:
CompileException
-
importTypeOnDemand
@Nullable public IClass importTypeOnDemand(String simpleTypeName, Location location) throws CompileException 6.5.2.BL1.B1.B5, 6.5.2.BL1.B1.B6 Type-import-on-demand.
6.5.5.1.6 Type-import-on-demand declaration.- Returns:
nullif the given simpleTypeName cannot be resolved through any of the type-import-on-demand declarations- Throws:
CompileException
-
importTypeOnDemand2
@Nullable private IClass importTypeOnDemand2(String simpleTypeName, Location location) throws CompileException - Returns:
nullif the given simpleTypeName cannot be resolved through any of the type-import-on-demand declarations- Throws:
CompileException
-
getTypeImportOnDemandImportDeclarations
private Collection<Java.AbstractCompilationUnit.TypeImportOnDemandDeclaration> getTypeImportOnDemandImportDeclarations() -
consT
Pushes one value on the operand stack and pushes the respectiveClassFile.StackMapTableAttribute.VerificationTypeInfooperand to the stack map.value Operand stack value Verification type info Character
Byte
Short
Integer
Booleanintinteger_variable_infoFloatfloatfloat_variable_infoLongmsb+lsboflonglong_variable_infoDoublemsb+lsbofdoubledouble_variable_infoStringConstantStringInfoCP indexobject_variable_info(String)IClassConstantClassInfoCP indexobject_variable_info(iClass.descriptor())nullnullnull_variable_info(iClass.descriptor())- Returns:
- The computational type of the value that was pushed, e.g.
IClass.INTforByteorIClass.NULLfornull - Throws:
CompileException
-
makeUtf8Able
-
consT
-
consT
-
consT
-
consT
-
consT
-
consT
-
consT
-
castConversion
private void castConversion(Java.Locatable locatable, IType sourceType, IType targetType, @Nullable Object constantValue) throws CompileException - Throws:
CompileException
-
tryCastConversion
private boolean tryCastConversion(Java.Locatable locatable, IType sourceType, IType targetType, @Nullable Object constantValue) throws CompileException - Throws:
CompileException
-
assignmentConversion
private void assignmentConversion(Java.Locatable locatable, IType sourceType, IType targetType, @Nullable Object constantValue) throws CompileException Implements "assignment conversion" (JLS7 5.2) (more precisely: "assignment contexts".)- Throws:
CompileException
-
tryAssignmentConversion
private boolean tryAssignmentConversion(Java.Locatable locatable, IType sourceType, IType targetType, @Nullable Object constantValue) throws CompileException - Throws:
CompileException
-
constantAssignmentConversion
@Nullable private Object constantAssignmentConversion(Java.Locatable locatable, @Nullable Object value, IType targetType) throws CompileException Implements "assignment conversion" (JLS7 5.2) on a constant value. -
unaryNumericPromotion
Implements "unary numeric promotion" (JLS7 5.6.1).- Returns:
- The promoted type
- Throws:
CompileException
-
reverseUnaryNumericPromotion
private void reverseUnaryNumericPromotion(Java.Locatable locatable, IClass sourceType, IType targetType) -
convertToPrimitiveNumericType
private IClass convertToPrimitiveNumericType(Java.Locatable locatable, IType type) throws CompileException If the given type is a primitive type, return that type. If the given type is a primitive wrapper class, unbox the operand on top of the operand stack and return the primitive type. Otherwise, issue a compile error.- Throws:
CompileException
-
numericPromotion
-
unaryNumericPromotionType
private IClass unaryNumericPromotionType(Java.Locatable locatable, IType type) throws CompileException - Throws:
CompileException
-
binaryNumericPromotionType
private IClass binaryNumericPromotionType(Java.Locatable locatable, IType type1, IType type2) throws CompileException - Throws:
CompileException
-
isIdentityConvertible
-
tryIdentityConversion
-
isWideningPrimitiveConvertible
-
tryWideningPrimitiveConversion
private boolean tryWideningPrimitiveConversion(Java.Locatable locatable, IType sourceType, IType targetType) Implements "widening primitive conversion" (5.1.2).- Returns:
- Whether the conversion succeeded
-
fillConversionMap
-
isWideningReferenceConvertible
private boolean isWideningReferenceConvertible(IType sourceType, IType targetType) throws CompileException Checks if "widening reference conversion" (5.1.4) is possible.- Returns:
- Whether the conversion is possible
- Throws:
CompileException
-
isNarrowingPrimitiveConvertible
-
tryNarrowingPrimitiveConversion
private boolean tryNarrowingPrimitiveConversion(Java.Locatable locatable, IType sourceType, IType targetType) Implements "narrowing primitive conversion" (JLS7 5.1.3).- Returns:
- Whether the conversion succeeded
-
tryConstantAssignmentConversion
private boolean tryConstantAssignmentConversion(Java.Locatable locatable, @Nullable Object constantValue, IType targetType) 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
-
isNarrowingReferenceConvertible
private boolean isNarrowingReferenceConvertible(IType sourceType, IType targetType) throws CompileException Checks whether "narrowing reference conversion" (JLS7 5.1.5) is possible.- Throws:
CompileException
-
tryNarrowingReferenceConversion
private boolean tryNarrowingReferenceConversion(Java.Locatable locatable, IType sourceType, IType targetType) throws CompileException Implements "narrowing reference conversion" (5.1.5).- Returns:
- Whether the conversion succeeded
- Throws:
CompileException
-
isCastReferenceConvertible
private boolean isCastReferenceConvertible(IType sourceType, IType targetType) throws CompileException JLS7 5.5- Throws:
CompileException
-
isBoxingConvertible
-
tryBoxingConversion
-
isNullConvertible
-
tryNullConversion
-
boxingConversion
- Parameters:
sourceType- a primitive type (except VOID)targetType- the corresponding wrapper type
-
isUnboxingConvertible
-
isConvertibleToPrimitiveNumeric
- Returns:
- Whether the sourceType is a primitive numeric type, or a wrapper type of a primitive numeric type
-
unboxingConversion
- Parameters:
sourceType- the corresponding wrapper typetargetType- a primitive type (except VOID)
-
findTypeByFullyQualifiedName
@Nullable private IClass findTypeByFullyQualifiedName(Location location, String[] identifiers) throws CompileException Attempts to load anIClassby fully-qualified name throughiClassLoader.- Parameters:
identifiers- The fully qualified type name, e.g. '{ "pkg", "Outer", "Inner" }'- Returns:
nullif 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,GTorLEorientation-JUMP_IF_TRUEorJUMP_IF_FALSE
-
aconstnull
-
add
-
andOrXor
-
anewarray
-
arraylength
-
arraystore
-
athrow
-
checkcast
-
cmp
-
dup
Duplicates the top operand: ... a => ... a a -
dup2
Duplicates the top two operands: ... a b => ... a b a b. This works iff both the top operand and the top-but-one operand have size 1. -
dupn
Duplicates the top n operands.- n == 0
- (nothing)
- n == 1
- ... a => ... a a
- n == 2
- ... a b => ... a b a b
-
dupx
Copies the top operand one position down: b a => a b a -
dupx2
Copies the top operand two positions down: c b a => a c b a. This works iff the top-but-one and top-but-two operands both have size 1. -
dupxx
Copies the top operand positions down.- n == 0
- ... a => ... a a
- n == 1
- ... b a => ... a b a
- n == 2
- ... c b a => ... a c b a
-
getfield
- Throws:
CompileException
-
getfield
private void getfield(Java.Locatable locatable, IClass declaringIClass, String fieldName, IClass fieldType, boolean statiC) -
gotO
- Parameters:
opcode- One of IF* and GOTO
-
if_acmpxx
-
if_icmpxx
-
ifnonnull
-
ifnull
-
ifxx
-
iinc
- Parameters:
operator- Must be either "++" or "--", as an @linkinternedstring
-
instanceoF
-
invoke
private void invoke(Java.Locatable locatable, int opcode, IClass declaringIClass, String methodName, MethodDescriptor methodDescriptor, boolean useInterfaceMethodRef) Expects the target object and the arguments on the operand stack. -
l2i
-
load
-
load
-
lookupswitch
private void lookupswitch(Java.Locatable locatable, SortedMap<Integer, CodeContext.Offset> caseLabelMap, CodeContext.Offset defaultLabelOffset) -
monitorenter
-
monitorexit
-
mulDivRemAddSub
- Parameters:
operator- One of* / % + -
-
multianewarray
private void multianewarray(Java.Locatable locatable, int dimExprCount, int dims, IType componentType) -
neg
- Parameters:
operandType- One of BYTE, CHAR, INT, SHORT, LONG, BOOLEAN, LONG, FLOAT, DOUBLE
-
neW
-
newarray
-
pop
-
putfield
- Throws:
CompileException
-
returN
-
shift
- Parameters:
operator- One of<< >> >>>
-
store
Assigns the top operand to the given local variable. -
store
- Parameters:
lvIndex- (two slots for LONG and DOUBLE local variables)
-
sub
-
swap
-
tableswitch
private void tableswitch(Java.Locatable locatable, SortedMap<Integer, CodeContext.Offset> caseLabelMap, CodeContext.Offset defaultLabelOffset) -
xaload
-
xor
-
xreturn
-
ilfd
- Parameters:
t- One of BYTE, CHAR, INT, SHORT, LONG, BOOLEAN, LONG, FLOAT, DOUBLE
-
ilfd
-
ilfda
-
il
-
ilfdabcs
-
findIField
@Nullable private IClass.IField findIField(IClass iClass, String name, Location location) throws CompileException Finds a named field in the givenIClass. Honors superclasses and interfaces. See JLS7 8.3.- Returns:
nullif no field is found- Throws:
CompileException
-
findMemberType
@Nullable private IClass findMemberType(IType iType, String name, @Nullable Java.TypeArgument[] typeArguments, Location location) throws CompileException Finds a named type in the givenIClassorIParameterizedType. Honors superclasses, interfaces and enclosing type declarations.- Returns:
nullif no type with the given name is found- Throws:
CompileException
-
findClass
Finds one class or interface declaration in this compilation unit and resolves it into anIClass.- Parameters:
className- Fully qualified class name, e.g. "pkg1.pkg2.Outer$Inner"- Returns:
nullif a class or an interface with that name is not declared in this compilation unit
-
compileError
Equivalent withcompileError(String, Location)with anulllocation argument.- Throws:
CompileException
-
compileError
Issues a compile error with the given message. This is done through theErrorHandlerthat was installed throughsetCompileErrorHandler(ErrorHandler). Such a handler typically throws aCompileException, but it may as well decide to return normally. Consequently, the calling code must be prepared thatcompileError(String, Location)returns normally, and must attempt to continue compiling.- Parameters:
message- The message to reportlocation- The location to report- Throws:
CompileException
-
warning
private void warning(String handle, String message, @Nullable Location location) throws CompileException Issues a warning with the given message an location an returns. This is done through aWarningHandlerthat was installed throughsetWarningHandler(WarningHandler).The handle argument qualifies the warning and is typically used by the
WarningHandlerto suppress individual warnings.- Throws:
CompileException
-
setCompileErrorHandler
By default,CompileExceptions are thrown on compile errors, but an application my install its own (thread-local)ErrorHandler.Be aware that a single problem during compilation often causes a bunch of compile errors, so a good
ErrorHandlercounts errors and throws aCompileExceptionwhen a limit is reached.If the given
ErrorHandlerdoes not throwCompileExceptions, thencompileUnit(boolean, boolean, boolean, ClassFileConsumer)will throw one when the compilation of the unit is finished, and errors had occurred. In other words: TheErrorHandlermay throw aCompileExceptionor not, butcompileUnit(boolean, boolean, boolean, ClassFileConsumer)will definitely throw aCompileExceptionif one or more compile errors have occurred.- Parameters:
compileErrorHandler-nullto restore the default behavior (throwing aCompileException)
-
setWarningHandler
By default, warnings are discarded, but an application my install a customWarningHandler.- Parameters:
warningHandler-nullto indicate that no warnings be issued
-
replaceCodeContext
-
addLineNumberOffset
-
write
private void write(int v) -
writeByte
private void writeByte(int v) -
writeShort
private void writeShort(int v) -
writeUnsignedShort
private void writeUnsignedShort(int v) -
writeInt
private void writeInt(int v) -
writeLdc
private void writeLdc(short constantPoolIndex) -
writeLdc2
private void writeLdc2(short constantPoolIndex) -
invokeMethod
Invokes the iMethod; assumes thatthis(unless iMethod is static) and the correct number and types of arguments are on the operand stack.- Throws:
CompileException
-
invokeConstructor
private void invokeConstructor(Java.Locatable locatable, IClass.IConstructor iConstructor) throws CompileException Invokes the iConstructor; assumes thatthisand the correct number and types of arguments are on the operand stack.- Throws:
CompileException
-
writeOffset
-
addConstantStringInfo
-
addConstantIntegerInfo
private short addConstantIntegerInfo(int value) -
addConstantLongInfo
private short addConstantLongInfo(long value) -
addConstantFloatInfo
private short addConstantFloatInfo(float value) -
addConstantDoubleInfo
private short addConstantDoubleInfo(double value) -
addConstantClassInfo
-
addConstantFieldrefInfo
-
addConstantMethodrefInfo
-
addConstantInterfaceMethodrefInfo
-
writeConstantClassInfo
-
writeConstantFieldrefInfo
-
writeConstantMethodrefInfo
private void writeConstantMethodrefInfo(IClass iClass, String methodName, MethodDescriptor methodMd) -
writeConstantInterfaceMethodrefInfo
private void writeConstantInterfaceMethodrefInfo(IClass iClass, String methodName, MethodDescriptor methodMd) -
getWhereToBreak
-
getDeclaringTypeBodyDeclaration
private Java.TypeBodyDeclaration getDeclaringTypeBodyDeclaration(Java.QualifiedThisReference qtr) throws CompileException - Throws:
CompileException
-
getDeclaringClass
private Java.AbstractClassDeclaration getDeclaringClass(Java.QualifiedThisReference qtr) throws CompileException - Throws:
CompileException
-
referenceThis
-
newArray
Expects dimExprCount values of typeinton the operand stack. Creates an array of dimExprCount+dims dimensions of componentType.- Returns:
- The type of the created array
-
last
-
allButLast
-
concat
-
compileException
-
unescape
Decodes any escape sequences like\n, or\377, but not\uxxxx.- Returns:
- s, with all escape sequences replaced with their literal values
- Throws:
CompileException- s contains an invalid escape sequenceIndexOutOfBoundsException- sends with a backslash
-
accessFlags
- Throws:
CompileException
-
accessModifiers
-
changeAccessibility
private static short changeAccessibility(short accessFlags, short newAccessibility) -
getLocalVariableTypeInfo
private ClassFile.StackMapTableAttribute.VerificationTypeInfo getLocalVariableTypeInfo(short lvIndex) - Parameters:
lvIndex- (two slots for LONG and DOUBLE local variables)
-
updateLocalVariableInCurrentStackMap
private void updateLocalVariableInCurrentStackMap(short lvIndex, ClassFile.StackMapTableAttribute.VerificationTypeInfo vti)
-