Package org.codehaus.janino
Class IClass
- java.lang.Object
-
- org.codehaus.janino.IClass
-
- Direct Known Subclasses:
ClassFileIClass
,IClass.PrimitiveIClass
,ReflectionIClass
public abstract class IClass extends java.lang.Object
A simplified equivalent to "java.lang.reflect".'JLS7' means a reference to the Java Language Specification, Java SE 7 Edition
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
IClass.IConstructor
Representation of a constructor of anIClass
.class
IClass.IField
Representation of a field of thisIClass
.class
IClass.IInvocable
Base class forIClass.IConstructor
andIClass.IMethod
.static interface
IClass.IMember
Base for the members of anIClass
.class
IClass.IMethod
Representation of a method in anIClass
.private static class
IClass.PrimitiveIClass
-
Field Summary
Fields Modifier and Type Field Description private IClass
arrayIClass
static IClass
BOOLEAN
TheIClass
object for the primitive type BOOLEAN.static IClass
BYTE
TheIClass
object for the primitive type BYTE.static IClass
CHAR
TheIClass
object for the primitive type CHAR.private IClass
componentTypeCache
private boolean
componentTypeIsCached
private static boolean
DEBUG
private IClass[]
declaredIClassesCache
private IClass.IConstructor[]
declaredIConstructorsCache
private java.util.Map<java.lang.String,IClass.IField>
declaredIFieldsCache
private java.util.Map<java.lang.String,java.lang.Object>
declaredIMethodCache
private IClass.IMethod[]
declaredIMethodsCache
private IClass
declaringIClassCache
private boolean
declaringIClassIsCached
private java.lang.String
descriptorCache
static IClass
DOUBLE
TheIClass
object for the primitive type DOUBLE.static IClass
FLOAT
TheIClass
object for the primitive type FLOAT.private IClass.IMethod[]
iMethodCache
static IClass
INT
TheIClass
object for the primitive type INT.private IClass[]
interfacesCache
static IClass
LONG
TheIClass
object for the primitive type LONG.private java.util.Map<java.lang.String,IClass[]>
memberTypeCache
private static IClass.IMethod[]
NO_IMETHODS
static java.lang.Object
NOT_CONSTANT
Special return value forIClass.IField.getConstantValue()
indicating that the field does not have a constant value.private IClass
outerIClassCache
private boolean
outerIClassIsCached
private static java.util.Set<java.lang.String>
PRIMITIVE_WIDENING_CONVERSIONS
static IClass
SHORT
TheIClass
object for the primitive type SHORT.private IClass
superclassCache
private boolean
superclassIsCached
static IClass
VOID
TheIClass
object for the type VOID.private static IClass[]
ZERO_ICLASSES
-
Constructor Summary
Constructors Constructor Description IClass()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
clearIFieldCaches()
Clears the cache of declared fields which this class maintains in order to minimize the invocations ofgetDeclaredIFields2()
.IClass.IConstructor
findIConstructor(IClass[] parameterTypes)
IClass.IMethod
findIMethod(java.lang.String methodName, IClass[] parameterTypes)
(package private) IClass[]
findMemberType(java.lang.String optionalName)
private void
findMemberType(java.lang.String optionalName, java.util.Collection<IClass> result)
abstract Access
getAccess()
IClass
getArrayIClass(int n, IClass objectType)
Get anIClass
that represents an n-dimensional array of this type.IClass
getArrayIClass(IClass objectType)
Get anIClass
that represents an array of this type.private IClass
getArrayIClass2(IClass objectType)
IClass
getComponentType()
protected abstract IClass
getComponentType2()
IClass[]
getDeclaredIClasses()
Returns the classes and interfaces declared as members of the class (but not inherited classes and interfaces).
Returns an empty array for an array, primitive type or "void".protected abstract IClass[]
getDeclaredIClasses2()
IClass.IConstructor[]
getDeclaredIConstructors()
Returns all the constructors declared by the class represented by the type.protected abstract IClass.IConstructor[]
getDeclaredIConstructors2()
The uncached version ofgetDeclaredIConstructors()
which must be implemented by derived classes.IClass.IField
getDeclaredIField(java.lang.String name)
Returns the namedIClass.IField
declared in thisIClass
(does not work for inherited fields).IClass.IField[]
getDeclaredIFields()
Returns theIClass.IField
s declared in thisIClass
(but not inherited fields).protected abstract IClass.IField[]
getDeclaredIFields2()
Uncached version ofgetDeclaredIFields()
.private java.util.Map<java.lang.String,IClass.IField>
getDeclaredIFieldsCache()
IClass.IMethod[]
getDeclaredIMethods()
Returns the methods of the class or interface (but not inherited methods).IClass.IMethod[]
getDeclaredIMethods(java.lang.String methodName)
Returns all methods with the given name declared in the class or interface (but not inherited methods).protected abstract IClass.IMethod[]
getDeclaredIMethods2()
The uncached version ofgetDeclaredIMethods()
which must be implemented by derived classes.IClass
getDeclaringIClass()
protected abstract IClass
getDeclaringIClass2()
java.lang.String
getDescriptor()
Returns the field descriptor for the type as defined by JVMS 4.3.2.protected abstract java.lang.String
getDescriptor2()
static java.lang.String[]
getDescriptors(IClass[] iClasses)
Convenience method that determines the field descriptors of an array ofIClass
es.IClass.IMethod[]
getIMethods()
Returns all methods declared in the class or interface, its superclasses and its superinterfaces.private void
getIMethods(java.util.List<IClass.IMethod> result)
IClass[]
getInterfaces()
Returns the interfaces implemented by the class.
Returns the superinterfaces of the interface.
Returns "Cloneable" and "Serializable" for arrays.
Returns an empty array for primitive types and "void".protected abstract IClass[]
getInterfaces2()
IClass
getOuterIClass()
The following types have an "outer class": Anonymous classes declared in a non-static method of a class Local classes declared in a non-static method of a class Non-static member classesprotected abstract IClass
getOuterIClass2()
IClass
getSuperclass()
Returns the superclass of the class.
Returns "null" for class "Object", interfaces, arrays, primitive types and "void".protected abstract IClass
getSuperclass2()
IClass.IField[]
getSyntheticIFields()
Returns the synthetic fields of an anonymous or local class, in the order in which they are passed to all constructors.boolean
hasIMethod(java.lang.String methodName, IClass[] parameterTypes)
boolean
implementsInterface(IClass that)
Ifthis
represents a class: Returntrue
if this class directly or indirectly implementsthat
interface.void
invalidateMethodCaches()
This class caches the declared methods in order to minimize the invocations ofgetDeclaredIMethods2()
.abstract boolean
isAbstract()
Whether the class may be instantiated (JVMS 4.1 access_flags)abstract boolean
isArray()
boolean
isAssignableFrom(IClass that)
Determine if "this" is assignable from "that".abstract boolean
isFinal()
Whether subclassing is allowed (JVMS 4.1 access_flags)abstract boolean
isInterface()
abstract boolean
isPrimitive()
abstract boolean
isPrimitiveNumeric()
boolean
isSubclassOf(IClass that)
Returnstrue
if this class is an immediate or non-immediate subclass ofthat
class.java.lang.String
toString()
-
-
-
Field Detail
-
DEBUG
private static final boolean DEBUG
- See Also:
- Constant Field Values
-
NOT_CONSTANT
public static final java.lang.Object NOT_CONSTANT
Special return value forIClass.IField.getConstantValue()
indicating that the field does not have a constant value.
-
declaredIConstructorsCache
private IClass.IConstructor[] declaredIConstructorsCache
-
declaredIMethodsCache
private IClass.IMethod[] declaredIMethodsCache
-
declaredIMethodCache
private java.util.Map<java.lang.String,java.lang.Object> declaredIMethodCache
-
iMethodCache
private IClass.IMethod[] iMethodCache
-
NO_IMETHODS
private static final IClass.IMethod[] NO_IMETHODS
-
declaredIFieldsCache
private java.util.Map<java.lang.String,IClass.IField> declaredIFieldsCache
-
declaredIClassesCache
private IClass[] declaredIClassesCache
-
declaringIClassIsCached
private boolean declaringIClassIsCached
-
declaringIClassCache
private IClass declaringIClassCache
-
outerIClassIsCached
private boolean outerIClassIsCached
-
outerIClassCache
private IClass outerIClassCache
-
superclassIsCached
private boolean superclassIsCached
-
superclassCache
private IClass superclassCache
-
interfacesCache
private IClass[] interfacesCache
-
descriptorCache
private java.lang.String descriptorCache
-
componentTypeIsCached
private boolean componentTypeIsCached
-
componentTypeCache
private IClass componentTypeCache
-
PRIMITIVE_WIDENING_CONVERSIONS
private static final java.util.Set<java.lang.String> PRIMITIVE_WIDENING_CONVERSIONS
-
arrayIClass
private IClass arrayIClass
-
memberTypeCache
private final java.util.Map<java.lang.String,IClass[]> memberTypeCache
-
ZERO_ICLASSES
private static final IClass[] ZERO_ICLASSES
-
-
Method Detail
-
getDeclaredIConstructors
public final IClass.IConstructor[] getDeclaredIConstructors()
Returns all the constructors declared by the class represented by the type. If the class has a default constructor, it is included.Returns an array with zero elements for an interface, array, primitive type or "void".
-
getDeclaredIConstructors2
protected abstract IClass.IConstructor[] getDeclaredIConstructors2()
The uncached version ofgetDeclaredIConstructors()
which must be implemented by derived classes.
-
getDeclaredIMethods
public final IClass.IMethod[] getDeclaredIMethods()
Returns the methods of the class or interface (but not inherited methods). For covariant methods, only the method with the most derived return type is included.
Returns an empty array for an array, primitive type or "void".
-
getDeclaredIMethods2
protected abstract IClass.IMethod[] getDeclaredIMethods2()
The uncached version ofgetDeclaredIMethods()
which must be implemented by derived classes.
-
getDeclaredIMethods
public final IClass.IMethod[] getDeclaredIMethods(java.lang.String methodName)
Returns all methods with the given name declared in the class or interface (but not inherited methods).
Returns an empty array if no methods with that name are declared.- Returns:
- an array of
IClass.IMethod
s that must not be modified
-
getIMethods
public final IClass.IMethod[] getIMethods() throws CompileException
Returns all methods declared in the class or interface, its superclasses and its superinterfaces.- Returns:
- an array of
IClass.IMethod
s that must not be modified - Throws:
CompileException
-
getIMethods
private void getIMethods(java.util.List<IClass.IMethod> result) throws CompileException
- Throws:
CompileException
-
hasIMethod
public final boolean hasIMethod(java.lang.String methodName, IClass[] parameterTypes) throws CompileException
- Returns:
- Whether this
IClass
(or its superclass or the interfaces it implements) has anIClass.IMethod
with the given name and parameter types - Throws:
CompileException
-
findIMethod
public final IClass.IMethod findIMethod(java.lang.String methodName, IClass[] parameterTypes) throws CompileException
- Returns:
- The
IClass.IMethod
declared in thisIClass
(or its superclass or the interfaces it implements) with the given name and parameter types, ornull
if an applicable method could not be found - Throws:
CompileException
-
findIConstructor
public final IClass.IConstructor findIConstructor(IClass[] parameterTypes) throws CompileException
- Returns:
- The
IClass.IConstructor
declared in thisIClass
with the given parameter types, ornull
if an applicable constrcutor could not be found - Throws:
CompileException
-
getDeclaredIFields
public final IClass.IField[] getDeclaredIFields()
Returns theIClass.IField
s declared in thisIClass
(but not inherited fields).- Returns:
- An empty array for an array, primitive type or "void"
-
getDeclaredIFieldsCache
private java.util.Map<java.lang.String,IClass.IField> getDeclaredIFieldsCache()
- Returns:
- String fieldName => IField
-
getDeclaredIField
public final IClass.IField getDeclaredIField(java.lang.String name)
Returns the namedIClass.IField
declared in thisIClass
(does not work for inherited fields).- Returns:
null
iff thisIClass
does not declare anIClass.IField
with that name
-
clearIFieldCaches
protected void clearIFieldCaches()
Clears the cache of declared fields which this class maintains in order to minimize the invocations ofgetDeclaredIFields2()
.
-
getDeclaredIFields2
protected abstract IClass.IField[] getDeclaredIFields2()
Uncached version ofgetDeclaredIFields()
.
-
getSyntheticIFields
public IClass.IField[] getSyntheticIFields()
Returns the synthetic fields of an anonymous or local class, in the order in which they are passed to all constructors.
-
getDeclaredIClasses
public final IClass[] getDeclaredIClasses() throws CompileException
Returns the classes and interfaces declared as members of the class (but not inherited classes and interfaces).
Returns an empty array for an array, primitive type or "void".- Throws:
CompileException
-
getDeclaredIClasses2
protected abstract IClass[] getDeclaredIClasses2() throws CompileException
- Returns:
- The member types of this type
- Throws:
CompileException
-
getDeclaringIClass
public final IClass getDeclaringIClass() throws CompileException
- Returns:
- If this class is a member class, the declaring class, otherwise
null
- Throws:
CompileException
-
getDeclaringIClass2
protected abstract IClass getDeclaringIClass2() throws CompileException
- Returns:
- If this class is a member class, the declaring class, otherwise
null
- Throws:
CompileException
-
getOuterIClass
public final IClass getOuterIClass() throws CompileException
The following types have an "outer class":- Anonymous classes declared in a non-static method of a class
- Local classes declared in a non-static method of a class
- Non-static member classes
- Returns:
- The outer class of this type, or
null
- Throws:
CompileException
-
getOuterIClass2
protected abstract IClass getOuterIClass2() throws CompileException
- Throws:
CompileException
- See Also:
getOuterIClass()
-
getSuperclass
public final IClass getSuperclass() throws CompileException
Returns the superclass of the class.
Returns "null" for class "Object", interfaces, arrays, primitive types and "void".- Throws:
CompileException
-
getSuperclass2
protected abstract IClass getSuperclass2() throws CompileException
- Throws:
CompileException
- See Also:
getSuperclass()
-
getAccess
public abstract Access getAccess()
- Returns:
- The accessibility of this type
-
isFinal
public abstract boolean isFinal()
Whether subclassing is allowed (JVMS 4.1 access_flags)- Returns:
true
if subclassing is prohibited
-
getInterfaces
public final IClass[] getInterfaces() throws CompileException
Returns the interfaces implemented by the class.
Returns the superinterfaces of the interface.
Returns "Cloneable" and "Serializable" for arrays.
Returns an empty array for primitive types and "void".- Throws:
CompileException
-
getInterfaces2
protected abstract IClass[] getInterfaces2() throws CompileException
- Throws:
CompileException
- See Also:
getInterfaces()
-
isAbstract
public abstract boolean isAbstract()
Whether the class may be instantiated (JVMS 4.1 access_flags)- Returns:
true
if instantiation is prohibited
-
getDescriptor
public final java.lang.String getDescriptor()
Returns the field descriptor for the type as defined by JVMS 4.3.2. This method is fast.
-
getDescriptor2
protected abstract java.lang.String getDescriptor2()
- Returns:
- The field descriptor for the type as defined by JVMS 4.3.2.
-
getDescriptors
public static java.lang.String[] getDescriptors(IClass[] iClasses)
Convenience method that determines the field descriptors of an array ofIClass
es.- See Also:
getDescriptor()
-
isInterface
public abstract boolean isInterface()
- Returns:
- Whether this type represents an interface
-
isArray
public abstract boolean isArray()
- Returns:
- Whether this type represents an array
-
isPrimitive
public abstract boolean isPrimitive()
- Returns:
- Whether this type represents a primitive type or "void"
-
isPrimitiveNumeric
public abstract boolean isPrimitiveNumeric()
- Returns:
- Whether this type represents "byte", "short", "int", "long", "char", "float" or "double"
-
getComponentType
public final IClass getComponentType()
- Returns:
- The component type of the array, or
null
for classes, interfaces, primitive types andvoid
-
getComponentType2
protected abstract IClass getComponentType2()
- See Also:
getComponentType()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
isAssignableFrom
public boolean isAssignableFrom(IClass that) throws CompileException
Determine if "this" is assignable from "that". This is true if "this" is identical with "that" (JLS7 5.1.1), or if "that" is widening-primitive-convertible to "this" (JLS7 5.1.2), or if "that" is widening-reference-convertible to "this" (JLS7 5.1.5).- Throws:
CompileException
-
isSubclassOf
public boolean isSubclassOf(IClass that) throws CompileException
Returnstrue
if this class is an immediate or non-immediate subclass ofthat
class.- Throws:
CompileException
-
implementsInterface
public boolean implementsInterface(IClass that) throws CompileException
Ifthis
represents a class: Returntrue
if this class directly or indirectly implementsthat
interface.If
this
represents an interface: Returntrue
if this interface directly or indirectly extendsthat
interface.- Throws:
CompileException
-
getArrayIClass
public IClass getArrayIClass(int n, IClass objectType)
Get anIClass
that represents an n-dimensional array of this type.- Parameters:
n
- dimension countobjectType
- Required because the superclass of an array class isObject
by definition
-
getArrayIClass
public IClass getArrayIClass(IClass objectType)
Get anIClass
that represents an array of this type.- Parameters:
objectType
- Required because the superclass of an array class isObject
by definition
-
findMemberType
IClass[] findMemberType(java.lang.String optionalName) throws CompileException
IfoptionalName
isnull
, find allIClass
es visible in the scope of the current class.If
optionalName
is notnull
, find the memberIClass
es that has the given name. If the name is ambiguous (i.e. if more than one superclass, interface of enclosing type declares a type with that name), then the size of the returned array is greater than one.Examines superclasses, interfaces and enclosing type declarations.
- Returns:
- an array of
IClass
es in unspecified order, possibly of length zero - Throws:
CompileException
-
findMemberType
private void findMemberType(java.lang.String optionalName, java.util.Collection<IClass> result) throws CompileException
- Throws:
CompileException
-
invalidateMethodCaches
public void invalidateMethodCaches()
This class caches the declared methods in order to minimize the invocations ofgetDeclaredIMethods2()
.
-
-