Top Description Inners Fields Constructors Methods
org.codehaus.janino

public Class UnitCompiler

extends Object
Class Inheritance
Imports
java.io.BufferedReader, .File, .IOException, .StringReader, java.util.ArrayList, .Arrays, .Collection, .Collections, .EnumSet, .HashMap, .HashSet, .Iterator, .List, .Map, .Map.Entry, .Set, .SortedMap, .StringTokenizer, .TreeMap, java.util.logging.Level, .Logger, java.util.regex.Pattern, org.codehaus.commons.compiler.CompileException, .ErrorHandler, .InternalCompilerException, .Location, .WarningHandler, org.codehaus.commons.compiler.util.Numbers, .SystemProperties, org.codehaus.commons.compiler.util.iterator.Iterables, org.codehaus.commons.nullanalysis.Nullable, org.codehaus.janino.CodeContext.BasicBlock, .CodeContext.Inserter, .CodeContext.Offset, .IClass.IAnnotation, .IClass.IConstructor, .IClass.IField, .IClass.IInvocable, .IClass.IMethod, .Java.AbstractClassDeclaration, .Java.AbstractCompilationUnit, .Java.AbstractCompilationUnit.ImportDeclaration, .Java.AbstractCompilationUnit.SingleStaticImportDeclaration, .Java.AbstractCompilationUnit.SingleTypeImportDeclaration, .Java.AbstractCompilationUnit.StaticImportOnDemandDeclaration, .Java.AbstractCompilationUnit.TypeImportOnDemandDeclaration, .Java.AbstractTypeDeclaration, .Java.AccessModifier, .Java.AlternateConstructorInvocation, .Java.AmbiguousName, .Java.Annotation, .Java.AnnotationTypeDeclaration, .Java.AnonymousClassDeclaration, .Java.ArrayAccessExpression, .Java.ArrayCreationReference, .Java.ArrayInitializer, .Java.ArrayInitializerOrRvalue, .Java.ArrayLength, .Java.ArrayType, .Java.AssertStatement, .Java.Assignment, .Java.Atom, .Java.BinaryOperation, .Java.Block, .Java.BlockStatement, .Java.BooleanLiteral, .Java.BooleanRvalue, .Java.BreakStatement, .Java.BreakableStatement, .Java.Cast, .Java.CatchClause, .Java.CatchParameter, .Java.CharacterLiteral, .Java.ClassInstanceCreationReference, .Java.ClassLiteral, .Java.CompilationUnit, .Java.ConditionalExpression, .Java.ConstructorDeclarator, .Java.ConstructorInvocation, .Java.ContinuableStatement, .Java.ContinueStatement, .Java.Crement, .Java.DoStatement, .Java.DocCommentable, .Java.ElementValue, .Java.ElementValueArrayInitializer, .Java.ElementValuePair, .Java.EmptyStatement, .Java.EnclosingScopeOfTypeDeclaration, .Java.EnumConstant, .Java.EnumDeclaration, .Java.ExpressionStatement, .Java.FieldAccess, .Java.FieldAccessExpression, .Java.FieldDeclaration, .Java.FieldDeclarationOrInitializer, .Java.FloatingPointLiteral, .Java.ForEachStatement, .Java.ForStatement, .Java.FunctionDeclarator, .Java.FunctionDeclarator.FormalParameter, .Java.FunctionDeclarator.FormalParameters, .Java.IfStatement, .Java.Initializer, .Java.InnerClassDeclaration, .Java.Instanceof, .Java.IntegerLiteral, .Java.InterfaceDeclaration, .Java.Invocation, .Java.LabeledStatement, .Java.LambdaExpression, .Java.Literal, .Java.LocalClassDeclaration, .Java.LocalClassDeclarationStatement, .Java.LocalVariable, .Java.LocalVariableAccess, .Java.LocalVariableDeclarationStatement, .Java.LocalVariableSlot, .Java.Locatable, .Java.Located, .Java.Lvalue, .Java.MarkerAnnotation, .Java.MemberAnnotationTypeDeclaration, .Java.MemberClassDeclaration, .Java.MemberEnumDeclaration, .Java.MemberInterfaceDeclaration, .Java.MemberTypeDeclaration, .Java.MethodDeclarator, .Java.MethodInvocation, .Java.MethodReference, .Java.Modifier, .Java.ModularCompilationUnit, .Java.NamedClassDeclaration, .Java.NamedTypeDeclaration, .Java.NewAnonymousClassInstance, .Java.NewArray, .Java.NewClassInstance, .Java.NewInitializedArray, .Java.NormalAnnotation, .Java.NullLiteral, .Java.Package, .Java.PackageDeclaration, .Java.PackageMemberAnnotationTypeDeclaration, .Java.PackageMemberClassDeclaration, .Java.PackageMemberEnumDeclaration, .Java.PackageMemberInterfaceDeclaration, .Java.PackageMemberTypeDeclaration, .Java.Padder, .Java.ParameterAccess, .Java.ParenthesizedExpression, .Java.Primitive, .Java.PrimitiveType, .Java.QualifiedThisReference, .Java.ReferenceType, .Java.ReturnStatement, .Java.Rvalue, .Java.RvalueMemberType, .Java.Scope, .Java.SimpleConstant, .Java.SimpleType, .Java.SingleElementAnnotation, .Java.Statement, .Java.StringLiteral, .Java.SuperConstructorInvocation, .Java.SuperclassFieldAccessExpression, .Java.SuperclassMethodInvocation, .Java.SwitchStatement, .Java.SwitchStatement.SwitchBlockStatementGroup, .Java.SynchronizedStatement, .Java.TextBlock, .Java.ThisReference, .Java.ThrowStatement, .Java.TryStatement, .Java.TryStatement.LocalVariableDeclaratorResource, .Java.TryStatement.VariableAccessResource, .Java.Type, .Java.TypeArgument, .Java.TypeBodyDeclaration, .Java.TypeDeclaration, .Java.TypeParameter, .Java.UnaryOperation, .Java.VariableDeclarator, .Java.WhileStatement, .Java.Wildcard, .Visitor.AbstractCompilationUnitVisitor, .Visitor.AnnotationVisitor, .Visitor.ArrayInitializerOrRvalueVisitor, .Visitor.AtomVisitor, .Visitor.BlockStatementVisitor, .Visitor.ElementValueVisitor, .Visitor.FunctionDeclaratorVisitor, .Visitor.ImportVisitor, .Visitor.LvalueVisitor, .Visitor.RvalueVisitor, .Visitor.TryStatementResourceVisitor, .Visitor.TypeDeclarationVisitor, .Visitor.TypeVisitor, org.codehaus.janino.util.Annotatable, .ClassFile, .ClassFile.ClassFileException, .ClassFile.MethodInfo, .ClassFile.StackMapTableAttribute, .ClassFile.StackMapTableAttribute.ObjectVariableInfo, .ClassFile.StackMapTableAttribute.VerificationTypeInfo

This class actually implements the Java compiler. It is associated with exactly one compilation unit which it compiles.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
pack-priv static interface
UnitCompiler.Compilable

Helper interface for string conversion.

pack-priv static interface
UnitCompiler.Compilable2

Interface for delayed code generation.

public static class
UnitCompiler.SimpleIField

Short-hand implementation of IClass.IField that implements a non-constant, non-static, package-accessible field.

private static enum

Field Summary

Modifier and TypeField and Description
private final Java.AbstractCompilationUnit
private CodeContext
private int
private ErrorHandler
private boolean
private boolean
private boolean
private static final int
private static final int
private static final int
private static final int
private final IClassLoader
public static final boolean
JUMP_IF_FALSE

Special value for the orientation parameter of the compileBoolean(Java.Rvalue, CodeContext.Offset, boolean) methods, indicating that the code should be generated such that execution branches if the value on top of the operand stack is FALSE.

public static final boolean
JUMP_IF_TRUE

Special value for the orientation parameter of the compileBoolean(Java.Rvalue, CodeContext.Offset, boolean) methods, indicating that the code should be generated such that execution branches if the value on top of the operand stack is TRUE.

private static final int
private static final Logger
private static final Pattern
private static final int
private static final Visitor.ArrayInitializerOrRvalueVisitor<Boolean, RuntimeException>
private static final int
public static final Object
NOT_CONSTANT

Special return value for the getConstantValue(Java.Rvalue) method family indicating that the given Java.Rvalue does not evaluate to a constant value.

private final Map<String, IClass>
private EnumSet<JaninoOption>
private static final Map<String, int[]>
private static final Map<String, int[]>
private Map<String, String[]>
singleTypeImports

To be used only by getSingleTypeImport(String, Location); null means "not yet initialized"

private UnitCompiler.ClassFileConsumer
private static final int
STRING_CONCAT_LIMIT

This constant determines the number of operands up to which the

     a.concat(b).concat(c)
private int
targetVersion

Java version to compile for.

private static final 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 final 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

Constructor Summary

AccessConstructor and Description
public
UnitCompiler(Java.AbstractCompilationUnit abstractCompilationUnit, IClassLoader iClassLoader)

Method Summary

Modifier and TypeMethod and Description
private short
accessFlags(Java.Modifier[] modifiers)

private static Java.Modifier[]
accessModifiers(Location location, String... keywords)

private void
private void
add(Java.Locatable locatable)

private void
addClassFile(ClassFile cf)

Adds the given ClassFile to the result set.

private short
private short
addConstantDoubleInfo(double value)

private short
addConstantFieldrefInfo(IClass iClass, String fieldName, IClass fieldType)

private short
addConstantFloatInfo(float value)

private short
private short
addConstantInterfaceMethodrefInfo(IClass iClass, String methodName, String methodFd)

private short
addConstantLongInfo(long value)

private short
addConstantMethodrefInfo(IClass iClass, String methodName, String methodFd)

private short
private void
addFields(Java.FieldDeclaration fd, ClassFile cf)

Creates and adds ClassFile.FieldInfos to the cf for all fields declared by the fd.

private void
private static ClassFile.MethodInfo
addMethodInfo(Java.Locatable locatable, ClassFile classFile, short accessFlags, String methodName, MethodDescriptor methodMd)

private static String[]
private Java.LocalVariable
allocateLocalVariable(boolean finaL, IType localVariableType)

private Java.LocalVariable
allocateLocalVariableAndMarkAsInitialized(boolean finaL, IType localVariableType)

private Java.LocalVariableSlot
allocateLocalVariableSlot(IType localVariableType, String localVariableName)

private Java.LocalVariableSlot
allocateLocalVariableSlotAndMarkAsInitialized(IType localVariableType, String localVariableName)

private void
andOrXor(Java.Locatable locatable, String operator)

private void
anewarray(Java.Locatable locatable, IClass componentType)

private void
private void
arraystore(Java.Locatable locatable, IType lhsComponentType)

private static <T> T
assertNonNull(T subject)

private void
assignmentConversion(Java.Locatable locatable, IType sourceType, IType targetType, Object constantValue)

Implements "assignment conversion" (JLS7 5.2) (more precisely: "assignment contexts".)

pack-priv 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
private void
boxingConversion(Java.Locatable locatable, IType
a primitive type (except VOID)
sourceType
,
IType
the corresponding wrapper type
targetType
)

private void
private Map<String, Java.LocalVariable>
buildLocalVariableMap(Java.BlockStatement blockStatement, final Map<String, Java.LocalVariable> localVars)

Computes and fills in the 'local variable map' for the given blockStatement.

private static Map<String, Java.LocalVariable>
private static Map<String, Java.LocalVariable>
private void
private void
private void
private void
private void
private void
private void
private void
private void
private void
private Map<String, Java.LocalVariable>
private Map<String, Java.LocalVariable>
protected void
buildLocalVariableMap(Java.CatchClause catchClause, Map<String, Java.LocalVariable> localVars)

Adds the given localVars to the 'local variable map' of the given catchClause.

private void
castConversion(Java.Locatable locatable, IType sourceType, IType targetType, Object constantValue)

private static short
changeAccessibility(short accessFlags, short newAccessibility)

private void
checkAccessible(IClass.IMember member, Java.Scope contextScope, Location location)

Checks whether the given IClass.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 given IClass is accessible in the given context, according to JLS7 6.6.1.2 and 6.6.1.4.

private void
checkcast(Java.Locatable locatable, IType targetType)

private void
private void
private void
checkMemberAccessible(IClass iClassDeclaringMember, IClass.IMember member, Java.Scope contextScope, Location location)

Verifies that a member (class, interface, field or method) declared in a given class is accessible from a given block statement context, according to JLS7 6.6.1.4.

private void
private void
private void
cmp(Java.Locatable locatable, int
One of EQ, NE, LT, GE, GT or LE
opIdx
)

private IType
private IType
private void
private boolean

Returns:

Whether this statement can complete normally (JLS7 14.1)
compile
(Java.BlockStatement bs)

private void
compile(final Java.ArrayInitializerOrRvalue aiorv, final IType arrayType)

private void
private void
compile(Java.Rvalue rv)

Some Rvalues compile more efficiently when their value is not needed, e.g. "i++".

private void
compile2(Java.CompilationUnit cu)

Compiles an (ordinary, not modular) compilation unit

private void
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
private void
private void
private void
private void
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private void
private void
private void
private void
private void
private boolean
private boolean
private void
compileAnnotations(Java.Annotation[] annotations, Annotatable target, final ClassFile cf)

Converts and adds the annotations to the target.

private IType
compileArithmeticBinaryOperation(Java.Locatable locatable, IType lhsType, String operator, Java.Rvalue rhs)

The LHS operand of type lhsType is expected on the stack.

private IType
compileArithmeticOperation(final Java.Locatable locatable, IType firstOperandType, Iterator<Java.Rvalue> operands, String operator)

Executes an arithmetic operation on a sequence of operands.

private void
compileBoolean(Java.Rvalue
The value that determines whether to branch or not
rv
,
final CodeContext.Offset
Where to jump
dst
,
final boolean orientation)

Compiles an Rvalue and branches, depending on the value.

private void
compileBoolean2(Java.Rvalue rv, CodeContext.Offset
Where to jump
dst
,
boolean orientation)

private void
compileBoolean2(Java.UnaryOperation ue, CodeContext.Offset
Where to jump
dst
,
boolean orientation)

private void
compileBoolean2(Java.BinaryOperation bo, CodeContext.Offset
Where to jump
dst
,
boolean orientation)

private void
private int

Returns:

The number of operands that is pushed on the operand stack (0, 1 or 2)
compileContext
(Java.Rvalue rv)

Generates code that determines the context of the Rvalue and puts it on the operand stack.

private int
private int
private int
private int
private int
compileContext2(Java.ArrayAccessExpression aae)

Array access expression; see JLS7 15.13 / JLS8+ 15.10.3.

private int
private int
private int
private void
compileDeclaredMemberTypes(Java.TypeDeclaration decl, ClassFile cf)

Compiles all of the types for this declaration

NB: as a side effect this will fill in the synthetic field map

private void
compileDeclaredMethods(Java.TypeDeclaration typeDeclaration, ClassFile cf)

Compiles all of the methods for this declaration

NB: as a side effect this will fill in the synthetic field map

private void
compileDeclaredMethods(Java.TypeDeclaration typeDeclaration, ClassFile cf, int
Starting parameter to fill in
startPos
)

Compiles methods for this declaration starting at startPos.

private ClassFile.ElementValue
compileElementValue(Java.ElementValue elementValue, final ClassFile cf, boolean compileAsArray)

private void
compileError(String message)

Equivalent with compileError(String, Location) with a null location argument.

private void
compileError(String
The message to report
message
,
Location
The location to report
location
)

Issues a compile error with the given message.

private static CompileException
compileException(Java.Locatable locatable, String message)

private IClass.IField
compileField(final Java.TypeDeclaration
"class Foo"
declaringType
,
final Java.Annotation[] annotations, final Access access, final boolean statiC, final boolean finaL, final Java.Type
"int[]"
type
,
final int brackets, final String name, final Java.ArrayInitializerOrRvalue initializer)

Compiles one variable declarator into an IField.

private IClass.IField[]

Returns:

The IFields that are declared by the fieldDeclaration
compileFields
(final Java.FieldDeclaration fieldDeclaration)

private IType

Returns:

The type of the Rvalue
compileGet
(Java.Rvalue rv)

Generates code that determines the value of the Rvalue and puts it on the operand stack.

private IClass
private IType
private IType
private IType
private IClass
private IClass
private IClass
private IClass
private IClass
private IClass
private IType
private IClass
private IType
private IType
private IType
private IType
private IType
private IType
private IClass
private IClass
private IType
private IType
private IType
private IClass
private IClass
private IType
private IClass
private IType
private IClass
private IType
private IClass
private IClass
private void
private IType

Returns:

The type of the Rvalue
compileGetValue
(Java.Rvalue rv)

Convenience function that calls compileContext(Rvalue) and compileGet(Rvalue).

private void
compileSet(Java.Lvalue lv)

Generates code that stores a value in the Lvalue.

private void
private void
private void
private void
private void
private void
private void
private boolean
compileStatements(List<? extends Java.BlockStatement> statements)

private IClass
compileStringConcatenation(final Java.Locatable locatable, IType
The type of the first operand, which is already on the stack
type
,
final Java.Rvalue
The second operand
secondOperand
,
Iterator<Java.Rvalue>
All following operands
operands
)

private boolean

Returns:

Whether the code can complete normally
compileTryCatch
(Java.TryStatement tryStatement, UnitCompiler.Compilable2 compileBody, final CodeContext.Offset beginningOfBody, final CodeContext.Offset afterStatement)

Generates code for a TRY statement without resources and without a FINALLY clause.

private boolean

Returns:

Whether the code can complete normally
compileTryCatchFinally
(final Java.TryStatement ts, final UnitCompiler.Compilable2 compileBody, final Java.BlockStatement finallY)

Generates code for a TRY statement without resources, but with an (optional) FINALLY clause.

private boolean

Returns:

Whether the code can complete normally
compileTryCatchFinallyWithResources
(final Java.TryStatement ts, List<Java.TryStatement.Resource> resources, final UnitCompiler.Compilable2 compileBody, final Java.Block finallY)

Generates code for a TRY statement with (possibly zero) resources and an (optional) FINALLY clause.

private boolean
private boolean
public void
compileUnit(boolean debugSource, boolean debugLines, boolean debugVars, final Collection<ClassFile>
Adds generated ClassFiles to this Collection
generatedClassFiles
)

Generates a set of ClassFile objects which represent the classes and interfaces declared in the compilation unit.

public void
compileUnit(boolean debugSource, boolean debugLines, boolean debugVars, UnitCompiler.ClassFileConsumer
Consumes each generated ClassFile
storesClassFiles
)

Generates a set of ClassFile objects which represent the classes and interfaces declared in the compilation unit.

private static String[]
concat(String[] sa, String s)

private IClass

Returns:

The computational type of the value that was pushed, e.g. IClass#INT for Byte or IClass#NULL for null
consT
(Java.Locatable locatable, Object value)

Pushes one value on the operand stack and pushes the respective VerificationTypeInfo operand to the stack map.

private void
consT(Java.Locatable locatable, IClass t, int value)

private void
consT(Java.Locatable locatable, int value)

private void
consT(Java.Locatable locatable, long value)

private void
consT(Java.Locatable locatable, float value)

private void
consT(Java.Locatable locatable, double value)

private void
consT(Java.Locatable locatable, final String s)

private void
consT(Java.Locatable locatable, IClass iClass)

private Object

Returns:

A Boolean, String, Byte, Short, Integer, Character, Long, Float, Double or null (representing the null literal)
constantAssignmentConversion
(Java.Locatable locatable, Object value, IType targetType)

Implements "assignment conversion" (JLS7 5.2) on a constant value.

private IClass
convertToPrimitiveNumericType(Java.Locatable locatable, IType type)

If the given type is a primitive type, return that type.

private Java.Rvalue
private Java.Rvalue
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 a

private 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

Returns:

Whether the block statement can complete normally
fakeCompile
(Java.BlockStatement bs)

Called to check whether the given BlockStatement compiles or not.

private void
fakeCompile(Java.Rvalue rv)

Called to check whether the given Rvalue compiles or not.

private void
private IClass.IMethod
fakeIMethod(IClass targetType, final String name, Java.Rvalue[] arguments)

private static void
fillConversionMap(Object[] array, Map<String, int[]> map)

public IClass

Returns:

null if a class or an interface with that name is not declared in this compilation unit
findClass
(String
Fully qualified class name, e.g. "pkg1.pkg2.Outer$Inner"
className
)

Finds one class or interface declaration in this compilation unit and resolves it into an IClass.

private IClass.IField

Returns:

null if no field is found
findIField
(IClass iClass, String name, Location location)

Finds a named field in the given IClass.

public IClass.IMethod

Returns:

The selected IClass.IMethod
findIMethod
(Java.MethodInvocation mi)

Finds methods of the mi.

private IClass.IMethod

Returns:

null if no appropriate method could be found
findIMethod
(IType targetType, Java.Invocation invocation)

Finds a IClass.IMethod in the given targetType, its superclasses or superinterfaces which is applicable with the given invocation.

public IClass.IMethod

Returns:

The IClass.IMethod that implements the superclassMethodInvocation
findIMethod
(Java.SuperclassMethodInvocation superclassMethodInvocation)

private static Java.LocalClassDeclaration
findLocalClassDeclaration(Java.Scope s, String name)

Finds a local class declared in any block enclosing the given block statement.

private IClass

Returns:

null if no type with the given name is found
findMemberType
(IType iType, String name, Java.TypeArgument[] typeArguments, Location location)

Finds a named type in the given IClass or IParameterizedType.

private IClass.IInvocable

Returns:

The selected IClass.IInvocable
findMostSpecificIInvocable
(Java.Locatable locatable, final IClass.IInvocable[]
Length must be greater than zero
iInvocables
,
final 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).

public IClass.IInvocable

Returns:

The maximally specific IClass.IInvocable or null if no IClass.IInvocable is applicable
findMostSpecificIInvocable
(Java.Locatable locatable, final IClass.IInvocable[] iInvocables, IClass[] argumentTypes, boolean boxingPermitted, Java.Scope contextScope)

Determines the applicable invocables and choose the most specific invocable.

private IClass

Returns:

null if a class with the given name could not be loaded
findTypeByFullyQualifiedName
(Location location, String[]
The fully qualified type name, e.g. '{ "pkg", "Outer", "Inner" }'
identifiers
)

Attempts to load an IClass by fully-qualified name through iClassLoader.

private IClass

Returns:

null iff an IClass with that name could not be loaded
findTypeByName
(Location location, String
Fully qualified class name, e.g. "pkg1.pkg2.Outer$Inner"
className
)

Finds the named IClass in this compilation unit, or through the iClassLoader.

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 of compile(BlockStatement) would generate more than zero code bytes.

private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
private boolean
public Java.AbstractCompilationUnit
private CodeContext
private static IType
getComponentType(IType expressionType)

public final Object

Returns:

NOT_CONSTANT iff the rvalue is not a constant value
getConstantValue
(Java.ArrayInitializerOrRvalue rv)

Attempts to evaluate as a constant expression.

public final Object

Returns:

NOT_CONSTANT iff the rvalue is not a constant value
getConstantValue
(Java.Rvalue rv)

Attempts to evaluate as a constant expression.

private Object
private Object
private Object
private Object
private Object
private Object
private Object
private Object
private Object
private Object
private Object
private boolean
private char
private String
private String
private Object
private Object
private Java.AbstractClassDeclaration
private Java.TypeBodyDeclaration
public static int

Returns:

The target version that applies iff no target version is actively configured with setTargetVersion(int)
getDefaultTargetVersion
()

private void
getfield(Java.Locatable locatable, IClass.IField iField)

private void
getfield(Java.Locatable locatable, IClass declaringIClass, String fieldName, IClass fieldType, boolean statiC)

private IClass
public void
getIMethods(IClass type, String methodName, List<IClass.IMethod> v)

Adds all methods with the given methodName that are declared by the type, its superclasses and all their superinterfaces to the result list v.

private static IType[]
public Java.LocalVariable

Returns:

The LocalVariable corresponding with the local variable declaration/declarator
getLocalVariable
(Java.LocalVariableDeclarationStatement lvds, Java.VariableDeclarator vd)

public Java.LocalVariable

Returns:

The LocalVariable corresponding with the parameter
getLocalVariable
(Java.FunctionDeclarator.FormalParameter parameter)

public Java.LocalVariable

Returns:

The LocalVariable corresponding with the parameter
getLocalVariable
(Java.FunctionDeclarator.FormalParameter parameter, boolean
Whether the parameter is the last parameter of a 'variable arity' (a.k.a. 'varargs') method declaration
isVariableArityParameter
)

public Java.LocalVariable

Returns:

The LocalVariable corresponding with the parameter
getLocalVariable
(Java.CatchParameter parameter)

private ClassFile.StackMapTableAttribute.VerificationTypeInfo
getLocalVariableTypeInfo(short
(two slots for LONG and DOUBLE local variables)
lvIndex
)

pack-priv Java.ArrayInitializerOrRvalue

Returns:

null if the variable is declared without an initializer or if the initializer is constant-final
getNonConstantFinalInitializer
(Java.FieldDeclaration fd, Java.VariableDeclarator vd)

Determines the non-constant-final initializer of the given VariableDeclarator.

pack-priv static Java.TypeDeclaration

Returns:

The TypeDeclaration that immediately encloses the typeDeclaration, or null
getOuterClass
(Java.TypeDeclaration typeDeclaration)

private static List<Java.TypeDeclaration>

Returns:

List of TypeDeclaration; has length one iff inner has no enclosing instance
getOuterClasses
(Java.TypeDeclaration inner)

Returns a list consisting of the given inner class and all its enclosing (outer) classes.

private IClass
getRawReferenceType(Location location, String simpleTypeName, Java.Scope scope)

private IClass
private IType

Returns:

The resolved IClass, or IParameterizedType, or null
getReferenceType
(Location location, Java.Scope scope, String[] identifiers, int n, Java.TypeArgument[]
Zero-length array if type has no type variables
typeArguments
)

private IType

Returns:

The resolved IClass or IParameterizedType
getReferenceType
(Location location, String simpleTypeName, Java.TypeArgument[]
Zero-length array if type is not parameterized
typeArguments
,
Java.Scope scope)

JLS7 6.5.5.1 Simple type name (single identifier)

private IType
public String[]

Returns:

The fully qualified name, e.g. { "pkg", "Outer", "Inner" }, or null
getSingleTypeImport
(String
The simple type name, e.g. "Inner"
name
,
Location location)

Checks if the given simple name was imported through a single type import.

private static IType
private IType
public int
private IType

Returns:

For a Type, the resolved IClass, for an Rvalue, the resolved IClass of the rvalue's type
getType
(Java.Atom a)

private IType
private IType
private IType
private IClass
private IType
private IClass
private IType
private IClass
private IClass
private IType
private IClass
private IType
private IType
private IClass
private IClass
private IClass
private IClass
private IClass
private IClass
private IType
private IClass
private IType
private IType
private IType
private IType
private IType
private IType
private IClass
private IClass
private IType
private IType
private IType
private IClass
private IClass
private IType
private IClass
private IType
private IClass
private IType
private IClass
private IClass
private IClass
private IClass
private IClass
private IClass
private IClass
private IClass
private Collection<Java.AbstractCompilationUnit.TypeImportOnDemandDeclaration>
private IType[]
getTypes(final Java.Type[] types)

private IType

Returns:

The type, or, iff type is a primitive wrapper type, the unwrapped type
getUnboxedType
(IType type)

private CodeContext.Offset
private void
gotO(Java.Locatable
One of IF* and GOTO
locatable
,
CodeContext.Offset dst)

private boolean
private void
if_acmpxx(Java.Locatable locatable, int
EQ or NE
opIdx
,
CodeContext.Offset dst)

private void
if_icmpxx(Java.Locatable locatable, int
One of EQ, NE, LT, GE, GT or LE
opIdx
,
CodeContext.Offset dst)

private void
private void
private void
ifNumeric(Java.Locatable locatable, int
One of EQ, NE, LT, GE, GT or LE
opIdx
,
CodeContext.Offset dst, boolean orientation)

private void
ifxx(Java.Locatable locatable, int
One of EQ, NE, LT, GE, GT or LE
opIdx
,
CodeContext.Offset dst)

private void
iinc(Java.Locatable locatable, Java.LocalVariable lv, String
Must be either "++" or "--", as an @link interned string
operator
)

private static int
private static int
ilfd(final IType
One of BYTE, CHAR, INT, SHORT, LONG, BOOLEAN, LONG, FLOAT, DOUBLE
t
)

private static int
private static int
private static int
private List<Object>

Returns:

A list of IFields, IMethods and/or IClasses with that simpleName; may be empty
importSingleStatic
(String simpleName)

Imports a member class, member interface, static field or static method via the compilation unit's single static import declarations.

private IClass
importSingleType(String simpleTypeName, Location location)

If the given name was declared in a simple type import, load that class.

private void
importStatic(IClass
The class or interface that declares the members
declaringIClass
,
String simpleName, Collection<Object>
Results (IClasses, IFields and/or IMethods) are added to this collection
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 List<Object>

Returns:

A list of IFields, IMethods and/or IClasses with that simpleName; may be empty
importStaticOnDemand
(String simpleName)

Imports a member class or interface, static field or static method via the compilation unit's static import on-demand declarations.

public IClass

Returns:

null if the given simpleTypeName cannot be resolved through any of the type-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.

private IClass

Returns:

null if the given simpleTypeName cannot be resolved through any of the type-import-on-demand declarations
importTypeOnDemand2
(String simpleTypeName, Location location)

pack-priv void
initializeInstanceVariablesAndInvokeInstanceInitializers(Java.ConstructorDeclarator cd)

Compiles the instance variable initializers and the instance initializers in their lexical order.

private void
instanceoF(Java.Locatable locatable, IType rhsType)

private String

Returns:

a descriptive text iff a member declared in that IClass with that Access is inaccessible
internalCheckAccessible
(IClass iClassDeclaringMember, Access memberAccess, Java.Scope contextScope)

private String

Returns:

An error message, or null
internalCheckAccessible
(IClass type, Java.Scope contextScope)

private void
invoke(Java.Locatable locatable, int opcode, IClass declaringIClass, String methodName, MethodDescriptor methodDescriptor, boolean useInterfaceMethodRef)

Expects the target object and the arguments on the operand stack.

private void
invokeConstructor(Java.Locatable locatable, Java.Scope scope, Java.Rvalue
Used if the target class is an inner class
enclosingInstance
,
IType targetType, Java.Rvalue[] arguments)

Expects the object to initialize on the stack.

private void
invokeConstructor(Java.Locatable locatable, IClass.IConstructor iConstructor)

Invokes the iConstructor; assumes that this and the correct number and types of arguments are on the operand stack.

private void
invokeMethod(Java.Locatable locatable, IClass.IMethod iMethod)

Invokes the iMethod; assumes that this (unless iMethod is static) and the correct number and types of arguments are on the operand stack.

private boolean
isAccessible(IClass.IMember member, Java.Scope contextScope)

Determines whether the given IClass.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 given IClass is accessible in the given context, according to JLS7 6.6.1.2 and 6.6.1.4.

private static boolean
isArray(IType type)

private static boolean
isAssignableFrom(IType targetType, IType sourceType)

private IClass

Returns:

The boxed type or null
isBoxingConvertible
(IType sourceType)

private static Byte
private boolean
isCastReferenceConvertible(IType sourceType, IType targetType)

JLS7 5.5

private boolean

Returns:

Whether the sourceType is a primitive numeric type, or a wrapper type of a primitive numeric type
isConvertibleToPrimitiveNumeric
(IType sourceType)

private boolean

Returns:

Whether the conversion is possible
isIdentityConvertible
(IType sourceType, IType targetType)

Checks whether "identity conversion" (5.1.1) is possible.

private static boolean
pack-priv Java.LocalVariable

Returns:

null iff c is not an int local variable
isIntLv
(Java.Crement c)

Checks whether the operand is an int local variable.

private boolean
isMethodInvocationConvertible(IClass sourceType, IClass targetType, boolean boxingPermitted)

Checks if "method invocation conversion" (5.3) is possible.

private boolean
isNarrowingPrimitiveConvertible(IType sourceType, IType targetType)

Checks whether "narrowing primitive conversion" (JLS7 5.1.3) is possible.

private boolean
isNarrowingReferenceConvertible(IType sourceType, IType targetType)

Checks whether "narrowing reference conversion" (JLS7 5.1.5) is possible.

private boolean
isNullConvertible(IType sourceType, IType targetType)

private static boolean
private static boolean
private boolean
private boolean
private boolean
private IClass

Returns:

Iff sourceType is a primitive wrapper type, the unboxed type, otherwise null
isUnboxingConvertible
(IType sourceType)

private boolean
private boolean

Returns:

Whether the conversion is possible
isWideningReferenceConvertible
(IType sourceType, IType targetType)

Checks if "widening reference conversion" (5.1.4) is possible.

private void
l2i(Java.Locatable locatable)

private static String
last(String[] sa)

private void
leave(Java.BlockStatement bs)

Cleans up the statement context.

private void
private void
private void
private void
leaveStatements(Java.Scope from, Java.Scope to)

Statements that jump out of blocks (return, break, continue) must call this method to make sure that the finally clauses of all try ...

private IType
load(Java.Locatable locatable, Java.LocalVariable localVariable)

private void
load(Java.Locatable locatable, IType localVariableType, int localVariableIndex)

private void
lookupswitch(Java.Locatable locatable, SortedMap<Integer, CodeContext.Offset> caseLabelMap, CodeContext.Offset defaultLabelOffset)

private static void
makeLocalVariableNames(final CodeContext cc, final ClassFile.MethodInfo mi)

Makes the variable name and class name Constant Pool names used by local variables.

private static String[]

Returns:

Strings that can be UTF8-encoded into 65535 bytes
makeUtf8Able
(String
The string to split into suitable chunks
s
)

Only strings that can be UTF8-encoded into 65535 bytes can be stored as a constant string info.

private void
maybeCreateInitMethod(Java.TypeDeclaration
The type declaration
td
,
ClassFile
The class file into which to put the method
cf
,
List<Java.BlockStatement>
The statements for the method (possibly empty)
statements
)

Creates class/interface initialization method iff there is any initialization code.

private static boolean
mayHaveSideEffects(Java.ArrayInitializerOrRvalue... arrayInitializersOrRvalues)

private static boolean
private void
private void
private void
mulDivRemAddSub(Java.Locatable locatable, String
One of * / % + -
operator
)

private void
multianewarray(Java.Locatable locatable, int dimExprCount, int dims, IType componentType)

private void
neg(Java.Locatable locatable, IClass
One of BYTE, CHAR, INT, SHORT, LONG, BOOLEAN, LONG, FLOAT, DOUBLE
operandType
)

private void
neW(Java.Locatable locatable, IType iType)

private void
newarray(Java.Locatable locatable, IType componentType)

private IClass

Returns:

The type of the created array
newArray
(Java.Locatable locatable, int dimExprCount, int dims, IType componentType)

Expects dimExprCount values of type int on the operand stack.

private ClassFile
newClassFile(short accessFlags, IClass iClass, IClass
null for Object, Object for interfaces
superclass
,
IClass[] interfaces)

private void
numericPromotion(Java.Locatable locatable, IType sourceType, IClass targetType)

public EnumSet<JaninoOption>

Returns:

A reference to the currently effective compilation options; changes to it take effect immediately
options
()

public UnitCompiler
options(EnumSet<JaninoOption> options)

Sets the options for all future compilations.

private boolean

Returns:

Whether method overrides a method of type or any of its supertypes
overridesMethod
(IClass.IMethod method, IClass type)

private boolean
private void
pop(Java.Locatable locatable, IType type)

private void
putfield(Java.Locatable locatable, IClass.IField iField)

private static IClass
private static IClass[]
rawTypesOf(IType[] iTypes)

private Java.Atom
private Java.Atom
reclassifyName(Location location, Java.Scope scope, final String[] identifiers, int n)

Reclassifies the ambiguous name consisting of the first n of the identifiers (JLS7 6.5.2.2).

private Java.Atom
reclassifyName(Location location, Java.Scope scope, final String identifier)

JLS7 6.5.2.1

private void
referenceThis(Java.Locatable locatable, Java.AbstractTypeDeclaration declaringType, Java.TypeBodyDeclaration declaringTypeBodyDeclaration, IType targetIType)

private void
referenceThis(Java.Locatable locatable, IClass currentIClass)

private CodeContext
private IClass
private void
returN(Java.Locatable locatable)

private void
reverseUnaryNumericPromotion(Java.Locatable locatable, IClass sourceType, IType targetType)

public void
setCompileErrorHandler(ErrorHandler
null to restore the default behavior (throwing a CompileException)
compileErrorHandler
)

By default, CompileExceptions are thrown on compile errors, but an application my install its own (thread-local) ErrorHandler.

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.

public void
setWarningHandler(WarningHandler
null to indicate that no warnings be issued
warningHandler
)

By default, warnings are discarded, but an application my install a custom WarningHandler.

private void
shift(Java.Locatable locatable, String
One of << >> >>>
operator
)

private void
store(Java.Locatable locatable, Java.LocalVariable localVariable)

Assigns the top operand to the given local variable.

private void
store(Java.Locatable locatable, IType lvType, short
(two slots for LONG and DOUBLE local variables)
lvIndex
)

private void
stringConversion(Java.Locatable locatable, IType sourceType)

Converts object of type "sourceType" to type "String" (JLS7 15.18.1.1).

private void
sub(Java.Locatable locatable)

private void
swap(Java.Locatable locatable)

private void
tableswitch(Java.Locatable locatable, SortedMap<Integer, CodeContext.Offset> caseLabelMap, CodeContext.Offset defaultLabelOffset)

private IClass.IAnnotation
private IClass.IAnnotation[]
pack-priv IClass.IConstructor

Returns:

the IConstructor that implements the constructorDeclarator
toIConstructor
(final Java.ConstructorDeclarator constructorDeclarator)

private IClass.IInvocable
public IClass.IMethod

Returns:

The IMethod that implements the methodDeclarator
toIMethod
(final Java.MethodDeclarator methodDeclarator)

private Java.Lvalue
private Java.Rvalue
private Java.Type
private boolean
tryAssignmentConversion(Java.Locatable locatable, IType sourceType, IType targetType, Object constantValue)

private boolean
tryBoxingConversion(Java.Locatable locatable, IType sourceType, IType targetType)

private boolean
tryCastConversion(Java.Locatable locatable, IType sourceType, IType targetType, Object constantValue)

private boolean
tryConstantAssignmentConversion(Java.Locatable locatable, Object
The constant value that is to be converted
constantValue
,
IType
The type to convert to
targetType
)

Checks if "constant assignment conversion" (JLS7 5.2, paragraph 1) is possible.

private boolean

Returns:

Whether the conversion was possible
tryIdentityConversion
(IType sourceType, IType targetType)

Implements "identity conversion" (5.1.1).

private boolean

Returns:

Whether the conversion succeeded
tryNarrowingPrimitiveConversion
(Java.Locatable locatable, IType sourceType, IType targetType)

Implements "narrowing primitive conversion" (JLS7 5.1.3).

private boolean

Returns:

Whether the conversion succeeded
tryNarrowingReferenceConversion
(Java.Locatable locatable, IType sourceType, IType targetType)

Implements "narrowing reference conversion" (5.1.5).

private boolean
tryNullConversion(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 boolean

Returns:

Whether the conversion succeeded
tryWideningPrimitiveConversion
(Java.Locatable locatable, IType sourceType, IType targetType)

Implements "widening primitive conversion" (5.1.2).

private IType
private IClass

Returns:

The promoted type
unaryNumericPromotion
(Java.Locatable locatable, IType type)

Implements "unary numeric promotion" (JLS7 5.6.1).

private IClass
private void
unboxingConversion(Java.Locatable locatable, IType
the corresponding wrapper type
sourceType
,
IClass
a primitive type (except VOID)
targetType
)

private static String

Returns:

s, with all escape sequences replaced with their literal values
unescape
(String s, Location location)

Decodes any escape sequences like \n, or \377, but not \uxxxx.

private void
private ClassFile.StackMapTableAttribute.VerificationTypeInfo
private void
warning(String handle, 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
private void
writeConstantFieldrefInfo(IClass iClass, String fieldName, IClass fieldType)

private void
private void
private void
writeInt(int v)

private void
writeLdc(short constantPoolIndex)

private void
writeLdc2(short constantPoolIndex)

private void
private void
writeShort(int v)

private void
private void
xaload(Java.Locatable locatable, IType componentType)

private void
xor(Java.Locatable locatable, int opcode)

private void
xreturn(Java.Locatable locatable, IType returnType)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait