Class IClass

java.lang.Object
org.codehaus.janino.IClass
All Implemented Interfaces:
IType, ITypeVariableOrIClass
Direct Known Subclasses:
ClassFileIClass, IClass.PrimitiveIClass, ReflectionIClass

public abstract class IClass extends Object implements ITypeVariableOrIClass
A simplified equivalent to "java.lang.reflect".

'JLS7' means a reference to the Java Language Specification, Java SE 7 Edition.

  • Field Details

    • LOGGER

      private static final Logger LOGGER
    • NOT_CONSTANT

      public static final Object NOT_CONSTANT
      Special return value for IClass.IField.getConstantValue() indicating that the field does not have a constant value.
    • VOID

      public static final IClass VOID
      The IClass object for the type VOID.
    • BYTE

      public static final IClass BYTE
      The IClass object for the primitive type BYTE.
    • CHAR

      public static final IClass CHAR
      The IClass object for the primitive type CHAR.
    • DOUBLE

      public static final IClass DOUBLE
      The IClass object for the primitive type DOUBLE.
    • FLOAT

      public static final IClass FLOAT
      The IClass object for the primitive type FLOAT.
    • INT

      public static final IClass INT
      The IClass object for the primitive type INT.
    • LONG

      public static final IClass LONG
      The IClass object for the primitive type LONG.
    • SHORT

      public static final IClass SHORT
      The IClass object for the primitive type SHORT.
    • BOOLEAN

      public static final IClass BOOLEAN
      The IClass object for the primitive type BOOLEAN.
    • iTypeVariablesCache

      @Nullable private ITypeVariable[] iTypeVariablesCache
    • declaredIConstructorsCache

      @Nullable private IClass.IConstructor[] declaredIConstructorsCache
    • declaredIMethodsCache

      @Nullable private IClass.IMethod[] declaredIMethodsCache
    • declaredIMethodCache

      @Nullable private Map<String,Object> declaredIMethodCache
    • iMethodCache

      @Nullable private IClass.IMethod[] iMethodCache
    • NO_IMETHODS

      private static final IClass.IMethod[] NO_IMETHODS
    • declaredIFieldsCache

      @Nullable private Map<String,IClass.IField> declaredIFieldsCache
    • declaredIClassesCache

      @Nullable private IClass[] declaredIClassesCache
    • declaringIClassIsCached

      private boolean declaringIClassIsCached
    • declaringIClassCache

      @Nullable private IClass declaringIClassCache
    • outerIClassIsCached

      private boolean outerIClassIsCached
    • outerIClassCache

      @Nullable private IClass outerIClassCache
    • superclassIsCached

      private boolean superclassIsCached
    • superclassCache

      @Nullable private IClass superclassCache
    • interfacesCache

      @Nullable private IClass[] interfacesCache
    • descriptorCache

      @Nullable private String descriptorCache
    • componentTypeIsCached

      private boolean componentTypeIsCached
    • componentTypeCache

      @Nullable private IClass componentTypeCache
    • PRIMITIVE_WIDENING_CONVERSIONS

      private static final Set<String> PRIMITIVE_WIDENING_CONVERSIONS
    • arrayIClass

      @Nullable private IClass arrayIClass
    • memberTypeCache

      private final Map<String,IClass[]> memberTypeCache
    • ZERO_ICLASSES

      private static final IClass[] ZERO_ICLASSES
    • iAnnotationsCache

      @Nullable private IClass.IAnnotation[] iAnnotationsCache
    • NO_ANNOTATIONS

      public static final IClass.IAnnotation[] NO_ANNOTATIONS
      Array of zero IClass.IAnnotations.
  • Constructor Details

    • IClass

      public IClass()
  • Method Details

    • getITypeVariables

      public final ITypeVariable[] getITypeVariables() throws CompileException
      Returns:
      Zero-length array if this IClass declares no type variables
      Throws:
      CompileException
    • getITypeVariables2

      protected abstract ITypeVariable[] getITypeVariables2() throws CompileException
      The uncached version of getDeclaredIConstructors() 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 of getDeclaredIConstructors() 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 of getDeclaredIMethods() which must be implemented by derived classes.
    • getDeclaredIMethods

      public final IClass.IMethod[] getDeclaredIMethods(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
    • getIMethods

      private void getIMethods(List<IClass.IMethod> result) throws CompileException
      Throws:
      CompileException
    • hasIMethod

      public final boolean hasIMethod(String methodName, IClass[] parameterTypes) throws CompileException
      Returns:
      Whether this IClass (or its superclass or the interfaces it implements) has an IClass.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 this IClass (or its superclass or the interfaces it implements) with the given name and parameter types, or null 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 this IClass with the given parameter types, or null if an applicable constructor could not be found
      Throws:
      CompileException
    • getDeclaredIFields

      public final IClass.IField[] getDeclaredIFields()
      Returns the IClass.IFields declared in this IClass (but not inherited fields).
      Returns:
      An empty array for an array, primitive type or void
    • getDeclaredIFieldsCache

      private Map<String,IClass.IField> getDeclaredIFieldsCache()
      Returns:
      String fieldName => IField
    • getDeclaredIField

      @Nullable public final IClass.IField getDeclaredIField(String name)
      Returns the named IClass.IField declared in this IClass (does not work for inherited fields).
      Returns:
      null iff this IClass does not declare an IClass.IField with that name
    • clearIFieldCaches

      protected void clearIFieldCaches()
      Clears the cache of declared fields which this class maintains in order to minimize the invocations of getDeclaredIFields2().
    • getDeclaredIFields2

      protected abstract IClass.IField[] getDeclaredIFields2()
      Uncached version of getDeclaredIFields().
    • 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:
    • getSuperclass

      @Nullable 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

      @Nullable protected abstract IClass getSuperclass2() throws CompileException
      Throws:
      CompileException
      See Also:
    • 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, 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:
    • 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 String getDescriptor()
      Returns the field descriptor for the type as defined by JVMS 4.3.2. This method is fast.
    • getDescriptor2

      protected abstract String getDescriptor2()
      Returns:
      The field descriptor for the type as defined by JVMS 4.3.2.
    • getDescriptors

      public static String[] getDescriptors(IClass[] iClasses)
      Convenience method that determines the field descriptors of an array of IClasses.
      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 or double
    • getComponentType

      @Nullable public final IClass getComponentType()
      Returns:
      The component type of the array, or null for classes, interfaces, primitive types and void
    • getComponentType2

      @Nullable protected abstract IClass getComponentType2()
      See Also:
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isAssignableFrom

      public boolean isAssignableFrom(IClass that) throws CompileException
      Determines 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
      Returns true if this class is an immediate or non-immediate subclass of that class.
      Throws:
      CompileException
    • implementsInterface

      public boolean implementsInterface(IClass that) throws CompileException
      If this represents a class: Return true if this class directly or indirectly implements that interface.

      If this represents an interface: Return true if this interface directly or indirectly extends that interface.

      Throws:
      CompileException
    • getArrayIClass

      public IClass getArrayIClass(int n, IClass objectType)
      Gets an IClass that represents an n-dimensional array of this type.
      Parameters:
      n - dimension count
      objectType - Required because the superclass of an array class is Object by definition
    • getArrayIClass

      public IClass getArrayIClass(IClass objectType)
      Gets an IClass that represents an array of this type.
      Parameters:
      objectType - Required because the superclass of an array class is Object by definition
    • getArrayIClass2

      private IClass getArrayIClass2(IClass objectType)
      Parameters:
      objectType - Must pass IClassLoader.TYPE_java_lang_Object here
    • findMemberType

      IClass[] findMemberType(@Nullable String name) throws CompileException
      If name is null, finds all IClasses visible in the scope of the current class.

      If name is not null, finds the member IClasses 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 IClasses in unspecified order, possibly of length zero
      Throws:
      CompileException
    • findMemberType

      private void findMemberType(@Nullable String name, Collection<IClass> result) throws CompileException
      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 of getDeclaredIMethods2().
    • rawTypeOf

      public static IClass rawTypeOf(IType type)