Package org.codehaus.janino
Class IClass
- java.lang.Object
-
- org.codehaus.janino.IClass
-
- All Implemented Interfaces:
IType,ITypeVariableOrIClass
- Direct Known Subclasses:
ClassFileIClass
public abstract class IClass extends java.lang.Object implements ITypeVariableOrIClass
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 static interfaceIClass.IAnnotationRepresentation of a Java "annotation".classIClass.IConstructorRepresentation of a constructor of anIClass.classIClass.IFieldRepresentation of a field of thisIClass.classIClass.IInvocableBase class forIClass.IConstructorandIClass.IMethod.static interfaceIClass.IMemberBase for the members of anIClass.classIClass.IMethodRepresentation of a method in anIClass.
-
Field Summary
Fields Modifier and Type Field Description static IClassBOOLEANTheIClassobject for the primitive type BOOLEAN.static IClassBYTETheIClassobject for the primitive type BYTE.static IClassCHARTheIClassobject for the primitive type CHAR.static IClassDOUBLETheIClassobject for the primitive type DOUBLE.static IClassFLOATTheIClassobject for the primitive type FLOAT.static IClassINTTheIClassobject for the primitive type INT.static IClassLONGTheIClassobject for the primitive type LONG.static IClass.IAnnotation[]NO_ANNOTATIONSArray of zeroIClass.IAnnotations.static java.lang.ObjectNOT_CONSTANTSpecial return value forIClass.IField.getConstantValue()indicating that the field does not have a constant value.static IClassNULLTheIClassof thenullliteral.static IClassSHORTTheIClassobject for the primitive type SHORT.static IClassVOIDTheIClassobject for the type VOID.
-
Constructor Summary
Constructors Constructor Description IClass()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidclearIFieldCaches()Clears the cache of declared fields which this class maintains in order to minimize the invocations ofgetDeclaredIFields2().IClass.IConstructorfindIConstructor(IClass[] parameterTypes)IClass.IMethodfindIMethod(java.lang.String methodName, IClass[] parameterTypes)abstract AccessgetAccess()IClassgetComponentType()protected abstract IClassgetComponentType2()IClass[]getDeclaredIClasses()Returns the classes and interfaces declared as members of the class (but not inherited classes and interfaces).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.IFieldgetDeclaredIField(java.lang.String name)Returns the namedIClass.IFielddeclared in thisIClass(does not work for inherited fields).IClass.IField[]getDeclaredIFields()Returns theIClass.IFields declared in thisIClass(but not inherited fields).protected abstract IClass.IField[]getDeclaredIFields2()Uncached version ofgetDeclaredIFields().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.IClassgetDeclaringIClass()protected abstract IClassgetDeclaringIClass2()java.lang.StringgetDescriptor()Returns the field descriptor for the type as defined by JVMS 4.3.2.protected abstract java.lang.StringgetDescriptor2()static java.lang.String[]getDescriptors(IClass[] iClasses)Convenience method that determines the field descriptors of an array ofIClasses.IClass.IAnnotation[]getIAnnotations()protected IClass.IAnnotation[]getIAnnotations2()IClass.IMethod[]getIMethods()Returns all methods declared in the class or interface, its superclasses and its superinterfaces.IClass[]getInterfaces()Returns the interfaces implemented by the class, respectively the superinterfaces of the interface, respectively{Cloneable,Serializable}for arrays.protected abstract IClass[]getInterfaces2()ITypeVariable[]getITypeVariables()protected abstract ITypeVariable[]getITypeVariables2()The uncached version ofgetDeclaredIConstructors()which must be implemented by derived classes.IClassgetOuterIClass()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 IClassgetOuterIClass2()IClassgetSuperclass()Returns the superclass of the class.protected abstract IClassgetSuperclass2()IClass.IField[]getSyntheticIFields()booleanhasIMethod(java.lang.String methodName, IClass[] parameterTypes)booleanimplementsInterface(IClass that)Ifthisrepresents a class: Returntrueif this class directly or indirectly implementsthatinterface.voidinvalidateMethodCaches()This class caches the declared methods in order to minimize the invocations ofgetDeclaredIMethods2().abstract booleanisAbstract()Whether the class may be instantiated (JVMS 4.1 access_flags).abstract booleanisArray()booleanisAssignableFrom(IClass that)Determines ifthisis assignable from that.abstract booleanisEnum()abstract booleanisFinal()Whether subclassing is allowed (JVMS 4.1 access_flags)abstract booleanisInterface()abstract booleanisPrimitive()abstract booleanisPrimitiveNumeric()booleanisSubclassOf(IClass that)Returnstrueif this class is an immediate or non-immediate subclass ofthatclass.static IClassrawTypeOf(IType type)java.lang.StringtoString()
-
-
-
Field Detail
-
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.
-
NO_ANNOTATIONS
public static final IClass.IAnnotation[] NO_ANNOTATIONS
Array of zeroIClass.IAnnotations.
-
-
Method Detail
-
getITypeVariables
public final ITypeVariable[] getITypeVariables() throws CompileException
- Returns:
- Zero-length array if this
IClassdeclares no type variables - Throws:
CompileException
-
getITypeVariables2
protected abstract ITypeVariable[] getITypeVariables2() throws CompileException
The uncached version ofgetDeclaredIConstructors()which must be implemented by derived classes.- Throws:
CompileException
-
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.IMethods 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.IMethods that must not be modified - 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.IMethodwith the given name and parameter types - Throws:
CompileException
-
findIMethod
@Nullable public final IClass.IMethod findIMethod(java.lang.String methodName, IClass[] parameterTypes) throws CompileException
- Returns:
- The
IClass.IMethoddeclared in thisIClass(or its superclass or the interfaces it implements) with the given name and parameter types, ornullif an applicable method could not be found - Throws:
CompileException
-
findIConstructor
@Nullable public final IClass.IConstructor findIConstructor(IClass[] parameterTypes) throws CompileException
- Returns:
- The
IClass.IConstructordeclared in thisIClasswith the given parameter types, ornullif an applicable constructor could not be found - Throws:
CompileException
-
getDeclaredIFields
public final IClass.IField[] getDeclaredIFields()
Returns theIClass.IFields declared in thisIClass(but not inherited fields).- Returns:
- An empty array for an array, primitive type or
void
-
getDeclaredIField
@Nullable public final IClass.IField getDeclaredIField(java.lang.String name)
Returns the namedIClass.IFielddeclared in thisIClass(does not work for inherited fields).- Returns:
nulliff thisIClassdoes not declare anIClass.IFieldwith 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
@Nullable public final IClass getDeclaringIClass() throws CompileException
- Returns:
- If this class is a member class, the declaring class, otherwise
null - Throws:
CompileException
-
getDeclaringIClass2
@Nullable protected abstract IClass getDeclaringIClass2() throws CompileException
- Returns:
- If this class is a member class, the declaring class, otherwise
null - Throws:
CompileException
-
getOuterIClass
@Nullable 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
@Nullable protected abstract IClass getOuterIClass2() throws CompileException
- Throws:
CompileException- See Also:
getOuterIClass()
-
getSuperclass
@Nullable public final IClass getSuperclass() throws CompileException
Returns the superclass of the class.Returns
nullfor classObject, interfaces, arrays, primitive types andvoid.- Throws:
CompileException
-
getSuperclass2
@Nullable 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:
trueif subclassing is prohibited
-
getInterfaces
public final IClass[] getInterfaces() throws CompileException
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
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:
trueif 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 ofIClasses.- See Also:
getDescriptor()
-
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,floatordouble
-
getComponentType
@Nullable public final IClass getComponentType()
- Returns:
- The component type of the array, or
nullfor classes, interfaces, primitive types andvoid
-
getComponentType2
@Nullable protected abstract IClass getComponentType2()
- See Also:
getComponentType()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
isAssignableFrom
public boolean isAssignableFrom(IClass that) throws CompileException
Determines ifthisis assignable from that. This is true ifthisis 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
public boolean isSubclassOf(IClass that) throws CompileException
Returnstrueif this class is an immediate or non-immediate subclass ofthatclass.- Throws:
CompileException
-
implementsInterface
public boolean implementsInterface(IClass that) throws CompileException
Ifthisrepresents a class: Returntrueif this class directly or indirectly implementsthatinterface.If
thisrepresents an interface: Returntrueif this interface directly or indirectly extendsthatinterface.- Throws:
CompileException
-
getIAnnotations
public final IClass.IAnnotation[] getIAnnotations() throws CompileException
- Returns:
- The annotations of this type (possibly the empty array)
- Throws:
CompileException
-
getIAnnotations2
protected IClass.IAnnotation[] getIAnnotations2() throws CompileException
- Throws:
CompileException
-
invalidateMethodCaches
public void invalidateMethodCaches()
This class caches the declared methods in order to minimize the invocations ofgetDeclaredIMethods2().
-
-