Class IClass

  • Direct Known Subclasses:
    ClassFileIClass

    public abstract class IClass
    extends java.lang.Object
    A simplified equivalent to "java.lang.reflect".
    • Field Detail

      • NOT_CONSTANT

        public static final java.lang.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.
    • Constructor Detail

      • IClass

        public IClass()
    • 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".

      • getDeclaredIMethods

        public final IClass.IMethod[] getDeclaredIMethods()
        Returns the methods of the class or interface (but not inherited methods).
        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​(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
      • 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"
      • getDeclaredIField

        public final IClass.IField getDeclaredIField​(java.lang.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()
      • 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
      • getDeclaringIClass

        public final IClass getDeclaringIClass()
                                        throws CompileException
        If this class is a member class, return the declaring class, otherwise return 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
        Throws:
        CompileException
      • 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
      • getAccess

        public abstract Access getAccess()
      • 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
      • 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.
      • getDescriptor2

        protected abstract java.lang.String getDescriptor2()
      • getDescriptors

        public static java.lang.String[] getDescriptors​(IClass[] iClasses)
        Convenience method that determines the field descriptors of an array of IClasses.
        See Also:
        getDescriptor()
      • isInterface

        public abstract boolean isInterface()
        Returns "true" if this type represents an interface.
      • isArray

        public abstract boolean isArray()
        Returns "true" if this type represents an array.
      • isPrimitive

        public abstract boolean isPrimitive()
        Returns "true" if this type represents a primitive type or "void".
      • isPrimitiveNumeric

        public abstract boolean isPrimitiveNumeric()
        Returns "true" if this type represents "byte", "short", "int", "long", "char", "float" or "double".
      • getComponentType

        public final IClass getComponentType()
        Returns the component type of the array.
        Returns "null" for classes, interfaces, primitive types and "void".
      • getComponentType2

        protected abstract IClass getComponentType2()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.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" (JLS2 5.1.1), or if "that" is widening-primitive-convertible to "this" (JLS2 5.1.2), or if "that" is widening-reference-convertible to "this" (JLS2 5.1.4).
        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)
        Get 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)
        Get an IClass that represents an array of this type.
        Parameters:
        objectType - Required because the superclass of an array class is Object by definition
      • invalidateMethodCaches

        public void invalidateMethodCaches()