Class IClass
- All Implemented Interfaces:
IType
,ITypeVariableOrIClass
- Direct Known Subclasses:
ClassFileIClass
,IClass.PrimitiveIClass
,ReflectionIClass
'JLS7' means a reference to the Java Language Specification, Java SE 7 Edition.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Representation of a Java "annotation".class
Representation of a constructor of anIClass
.class
Representation of a field of thisIClass
.class
Base class forIClass.IConstructor
andIClass.IMethod
.static interface
Base for the members of anIClass
.class
Representation of a method in anIClass
.private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate IClass
static final IClass
TheIClass
object for the primitive type BOOLEAN.static final IClass
TheIClass
object for the primitive type BYTE.static final IClass
TheIClass
object for the primitive type CHAR.private IClass
private boolean
private IClass[]
private IClass.IConstructor[]
private Map<String,
IClass.IField> private IClass.IMethod[]
private IClass
private boolean
private String
static final IClass
TheIClass
object for the primitive type DOUBLE.static final IClass
TheIClass
object for the primitive type FLOAT.private IClass.IAnnotation[]
private IClass.IMethod[]
static final IClass
TheIClass
object for the primitive type INT.private IClass[]
private ITypeVariable[]
private static final Logger
static final IClass
TheIClass
object for the primitive type LONG.static final IClass.IAnnotation[]
Array of zeroIClass.IAnnotation
s.private static final IClass.IMethod[]
static final Object
Special return value forIClass.IField.getConstantValue()
indicating that the field does not have a constant value.private IClass
private boolean
static final IClass
TheIClass
object for the primitive type SHORT.private IClass
private boolean
static final IClass
TheIClass
object for the type VOID.private static final IClass[]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Clears the cache of declared fields which this class maintains in order to minimize the invocations ofgetDeclaredIFields2()
.final IClass.IConstructor
findIConstructor
(IClass[] parameterTypes) final IClass.IMethod
findIMethod
(String methodName, IClass[] parameterTypes) (package private) IClass[]
findMemberType
(String name) If name isnull
, finds allIClass
es visible in the scope of the current class.private void
findMemberType
(String name, Collection<IClass> result) abstract Access
getArrayIClass
(int n, IClass objectType) Gets anIClass
that represents an n-dimensional array of this type.getArrayIClass
(IClass objectType) Gets anIClass
that represents an array of this type.private IClass
getArrayIClass2
(IClass objectType) final IClass
protected abstract IClass
final IClass[]
Returns the classes and interfaces declared as members of the class (but not inherited classes and interfaces).protected abstract IClass[]
final IClass.IConstructor[]
Returns all the constructors declared by the class represented by the type.protected abstract IClass.IConstructor[]
The uncached version ofgetDeclaredIConstructors()
which must be implemented by derived classes.final IClass.IField
getDeclaredIField
(String name) Returns the namedIClass.IField
declared in thisIClass
(does not work for inherited fields).final IClass.IField[]
Returns theIClass.IField
s declared in thisIClass
(but not inherited fields).protected abstract IClass.IField[]
Uncached version ofgetDeclaredIFields()
.private Map<String,
IClass.IField> final IClass.IMethod[]
Returns the methods of the class or interface (but not inherited methods).final IClass.IMethod[]
getDeclaredIMethods
(String methodName) Returns all methods with the given name declared in the class or interface (but not inherited methods).protected abstract IClass.IMethod[]
The uncached version ofgetDeclaredIMethods()
which must be implemented by derived classes.final IClass
protected abstract IClass
final String
Returns the field descriptor for the type as defined by JVMS 4.3.2.protected abstract String
static String[]
getDescriptors
(IClass[] iClasses) Convenience method that determines the field descriptors of an array ofIClass
es.final IClass.IAnnotation[]
protected IClass.IAnnotation[]
final IClass.IMethod[]
Returns all methods declared in the class or interface, its superclasses and its superinterfaces.private void
getIMethods
(List<IClass.IMethod> result) final IClass[]
Returns the interfaces implemented by the class, respectively the superinterfaces of the interface, respectively{
Cloneable
,
Serializable
}
for arrays.protected abstract IClass[]
final ITypeVariable[]
protected abstract ITypeVariable[]
The uncached version ofgetDeclaredIConstructors()
which must be implemented by derived classes.final IClass
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
final IClass
Returns the superclass of the class.protected abstract IClass
final boolean
hasIMethod
(String methodName, IClass[] parameterTypes) boolean
implementsInterface
(IClass that) Ifthis
represents a class: Returntrue
if this class directly or indirectly implementsthat
interface.void
This class caches the declared methods in order to minimize the invocations ofgetDeclaredIMethods2()
.abstract boolean
Whether the class may be instantiated (JVMS 4.1 access_flags).abstract boolean
isArray()
boolean
isAssignableFrom
(IClass that) Determines ifthis
is assignable from that.abstract boolean
isEnum()
abstract boolean
isFinal()
Whether subclassing is allowed (JVMS 4.1 access_flags)abstract boolean
abstract boolean
abstract boolean
boolean
isSubclassOf
(IClass that) Returnstrue
if this class is an immediate or non-immediate subclass ofthat
class.static IClass
toString()
-
Field Details
-
LOGGER
-
NOT_CONSTANT
Special return value forIClass.IField.getConstantValue()
indicating that the field does not have a constant value. -
VOID
TheIClass
object for the type VOID. -
BYTE
TheIClass
object for the primitive type BYTE. -
CHAR
TheIClass
object for the primitive type CHAR. -
DOUBLE
TheIClass
object for the primitive type DOUBLE. -
FLOAT
TheIClass
object for the primitive type FLOAT. -
INT
TheIClass
object for the primitive type INT. -
LONG
TheIClass
object for the primitive type LONG. -
SHORT
TheIClass
object for the primitive type SHORT. -
BOOLEAN
TheIClass
object for the primitive type BOOLEAN. -
iTypeVariablesCache
-
declaredIConstructorsCache
-
declaredIMethodsCache
-
declaredIMethodCache
-
iMethodCache
-
NO_IMETHODS
-
declaredIFieldsCache
-
declaredIClassesCache
-
declaringIClassIsCached
private boolean declaringIClassIsCached -
declaringIClassCache
-
outerIClassIsCached
private boolean outerIClassIsCached -
outerIClassCache
-
superclassIsCached
private boolean superclassIsCached -
superclassCache
-
interfacesCache
-
descriptorCache
-
componentTypeIsCached
private boolean componentTypeIsCached -
componentTypeCache
-
PRIMITIVE_WIDENING_CONVERSIONS
-
arrayIClass
-
memberTypeCache
-
ZERO_ICLASSES
-
iAnnotationsCache
-
NO_ANNOTATIONS
Array of zeroIClass.IAnnotation
s.
-
-
Constructor Details
-
IClass
public IClass()
-
-
Method Details
-
getITypeVariables
- Returns:
- Zero-length array if this
IClass
declares no type variables - Throws:
CompileException
-
getITypeVariables2
The uncached version ofgetDeclaredIConstructors()
which must be implemented by derived classes.- Throws:
CompileException
-
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
The uncached version ofgetDeclaredIConstructors()
which must be implemented by derived classes. -
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
The uncached version ofgetDeclaredIMethods()
which must be implemented by derived classes. -
getDeclaredIMethods
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
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
- Throws:
CompileException
-
hasIMethod
- 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
@Nullable public final IClass.IMethod findIMethod(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
@Nullable 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 constructor could not be found - Throws:
CompileException
-
getDeclaredIFields
Returns theIClass.IField
s declared in thisIClass
(but not inherited fields).- Returns:
- An empty array for an array, primitive type or
void
-
getDeclaredIFieldsCache
- Returns:
String fieldName => IField
-
getDeclaredIField
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
Uncached version ofgetDeclaredIFields()
. -
getSyntheticIFields
- Returns:
- The synthetic fields of an anonymous or local class, in the order in which they are passed to all constructors
-
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
.- Throws:
CompileException
-
getDeclaredIClasses2
- Returns:
- The member types of this type
- Throws:
CompileException
-
getDeclaringIClass
- Returns:
- If this class is a member class, the declaring class, otherwise
null
- Throws:
CompileException
-
getDeclaringIClass2
- Returns:
- If this class is a member class, the declaring class, otherwise
null
- Throws:
CompileException
-
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 classes
- Returns:
- The outer class of this type, or
null
- Throws:
CompileException
-
getOuterIClass2
- Throws:
CompileException
- See Also:
-
getSuperclass
Returns the superclass of the class.Returns
null
for classObject
, interfaces, arrays, primitive types andvoid
.- Throws:
CompileException
-
getSuperclass2
- Throws:
CompileException
- See Also:
-
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
Returns the interfaces implemented by the class, respectively the superinterfaces of the interface, respectively{
Cloneable
,
Serializable
}
for arrays.Returns an empty array for primitive types and
void
.- Throws:
CompileException
-
getInterfaces2
- Throws:
CompileException
- See Also:
-
isAbstract
public abstract boolean isAbstract()Whether the class may be instantiated (JVMS 4.1 access_flags).- Returns:
true
if instantiation is prohibited
-
getDescriptor
Returns the field descriptor for the type as defined by JVMS 4.3.2. This method is fast. -
getDescriptor2
- Returns:
- The field descriptor for the type as defined by JVMS 4.3.2.
-
getDescriptors
Convenience method that determines the field descriptors of an array ofIClass
es.- See Also:
-
isEnum
public abstract boolean isEnum()- Returns:
- Whether this type represents an enum
-
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
ordouble
-
getComponentType
- Returns:
- The component type of the array, or
null
for classes, interfaces, primitive types andvoid
-
getComponentType2
- See Also:
-
toString
-
isAssignableFrom
Determines ifthis
is assignable from that. This is true ifthis
is identical with that (JLS7 5.1.1), or if that is widening-primitive-convertible tothis
(JLS7 5.1.2), or if that is widening-reference-convertible tothis
(JLS7 5.1.5).- Throws:
CompileException
-
isSubclassOf
Returnstrue
if this class is an immediate or non-immediate subclass ofthat
class.- Throws:
CompileException
-
implementsInterface
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
Gets 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
Gets anIClass
that represents an array of this type.- Parameters:
objectType
- Required because the superclass of an array class isObject
by definition
-
getArrayIClass2
- Parameters:
objectType
- Must passIClassLoader.TYPE_java_lang_Object
here
-
findMemberType
If name isnull
, finds allIClass
es visible in the scope of the current class.If name is not
null
, finds 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(@Nullable String name, Collection<IClass> result) throws CompileException - Throws:
CompileException
-
getIAnnotations
- Returns:
- The annotations of this type (possibly the empty array)
- Throws:
CompileException
-
getIAnnotations2
- Throws:
CompileException
-
invalidateMethodCaches
public void invalidateMethodCaches()This class caches the declared methods in order to minimize the invocations ofgetDeclaredIMethods2()
. -
rawTypeOf
-