Class TypeReference

  • All Implemented Interfaces:
    Serializable

    public final class TypeReference
    extends Object
    implements Serializable
    A class to represent the reference in a class file to some type (class, primitive or array). A type reference is uniquely defined by
    • an initiating class loader
    • a type name
    Resolving a TypeReference to a Type can be an expensive operation. Therefore we canonicalize TypeReference instances and cache the result of resolution.
    See Also:
    Serialized Form
    • Constructor Detail

      • TypeReference

        protected TypeReference​(ClassLoaderReference cl,
                                TypeName tn)
        NB: All type names should use '/' and not '.' as a separator. eg. Ljava/lang/Class
        Parameters:
        cl - the classloader
        tn - the type name
    • Method Detail

      • isPrimitiveType

        public static boolean isPrimitiveType​(TypeName name)
        Could name a represent a primitive type?
      • findOrCreate

        public static TypeReference findOrCreate​(ClassLoaderReference cl,
                                                 TypeName typeName)
        Find or create the canonical TypeReference instance for the given pair.
        Parameters:
        cl - the classloader (defining/initiating depending on usage)
      • findOrCreate

        public static TypeReference findOrCreate​(ClassLoaderReference cl,
                                                 String typeName)
        Find or create the canonical TypeReference instance for the given pair.
        Parameters:
        cl - the classloader (defining/initiating depending on usage)
        typeName - something like "Ljava/util/Arrays"
      • find

        public static TypeReference find​(ClassLoaderReference cl,
                                         TypeName typeName)
        Find the canonical TypeReference instance for the given pair. May return null.
        Parameters:
        cl - the classloader (defining/initiating depending on usage)
      • getClassLoader

        public final ClassLoaderReference getClassLoader()
        Returns:
        the classloader component of this type reference
      • getName

        public final TypeName getName()
        Returns:
        the type name component of this type reference
      • getArrayElementType

        public final TypeReference getArrayElementType()
        TODO: specialized form of TypeReference for arrays, please. Get the element type of for this array type.
      • getArrayTypeForElementType

        public final TypeReference getArrayTypeForElementType()
        Get array type corresponding to "this" array element type.
      • getDerivedMask

        public final int getDerivedMask()
        Return the dimensionality of the type. By convention, class types have dimensionality 0, primitives -1, and arrays the number of [ in their descriptor.
      • getInnermostElementType

        public final TypeReference getInnermostElementType()
        Return the innermost element type reference for an array
      • isClassType

        public final boolean isClassType()
        Does 'this' refer to a class?
      • isArrayType

        public final boolean isArrayType()
        Does 'this' refer to an array?
      • isPrimitiveType

        public final boolean isPrimitiveType()
        Does 'this' refer to a primitive type
      • isReferenceType

        public final boolean isReferenceType()
        Does 'this' refer to a reference type
      • hashCode

        public final int hashCode()
        Overrides:
        hashCode in class Object
      • equals

        public final boolean equals​(Object other)
        TypeReferences are canonical. However, note that two TypeReferences can be non-equal, yet still represent the same IClass. For example, the there can be two TypeReferences and . These two TypeReference are NOT equal(), but they both represent the IClass which is named
        Overrides:
        equals in class Object
      • getDimensionality

        public int getDimensionality()