Class Type

java.lang.Object
com.android.dx.rop.type.Type
All Implemented Interfaces:
TypeBearer, ToHuman, Comparable<Type>

public final class Type extends Object implements TypeBearer, Comparable<Type>
Representation of a value type, such as may appear in a field, in a local, on a stack, or in a method descriptor. Instances of this class are generally interned and may be usefully compared with each other using ==.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Type
    non-null; instance representing java.lang.annotation.Annotation
    static final Type
    non-null; instance representing boolean
    static final Type
    non-null; instance representing boolean[]
    static final Type
    non-null; instance representing java.lang.Boolean; the suffix on the name helps disambiguate this from the instance representing a primitive type
    static final int
    basic type constant for a return address
    static final int
    basic type constant for boolean
    static final int
    basic type constant for byte
    static final int
    basic type constant for char
    static final int
    count of basic type constants
    static final int
    basic type constant for double
    static final int
    basic type constant for float
    static final int
    basic type constant for int
    static final int
    basic type constant for long
    static final int
    basic type constant for Object
    static final int
    basic type constant for short
    static final int
    basic type constant for void
    static final Type
    non-null; instance representing byte
    static final Type
    non-null; instance representing byte[]
    static final Type
    non-null; instance representing java.lang.Byte; the suffix on the name helps disambiguate this from the instance representing a primitive type
    static final Type
    non-null; instance representing char
    static final Type
    non-null; instance representing char[]
    static final Type
    non-null; instance representing java.lang.Character; the suffix on the name helps disambiguate this from the instance representing a primitive type
    static final Type
    non-null; instance representing java.lang.Class
    static final Type
    non-null; instance representing java.lang.Cloneable
    static final Type
    non-null; instance representing double
    static final Type
    non-null; instance representing double[]
    static final Type
    non-null; instance representing java.lang.Double; the suffix on the name helps disambiguate this from the instance representing a primitive type
    static final Type
    non-null; instance representing float
    static final Type
    non-null; instance representing float[]
    static final Type
    non-null; instance representing java.lang.Float; the suffix on the name helps disambiguate this from the instance representing a primitive type
    static final Type
    non-null; instance representing int
    static final Type
    non-null; instance representing int[]
    static final Type
    non-null; instance representing java.lang.Integer; the suffix on the name helps disambiguate this from the instance representing a primitive type
    static final Type
    non-null; instance representing a known-null
    static final Type
    non-null; instance representing long
    static final Type
    non-null; instance representing long[]
    static final Type
    non-null; instance representing java.lang.Long; the suffix on the name helps disambiguate this from the instance representing a primitive type
    static final Type
    non-null; instance representing java.lang.invoke.MethodHandle
    static final Type
    non-null; instance representing java.lang.invoke.MethodType
    static final Type
    non-null; instance representing java.lang.Object
    static final Type
    non-null; instance representing Object[]
    static final Type
    non-null; instance representing a subroutine return address
    static final Type
    non-null; instance representing java.io.Serializable
    static final Type
    non-null; instance representing short
    static final Type
    non-null; instance representing short[]
    static final Type
    non-null; instance representing java.lang.Short; the suffix on the name helps disambiguate this from the instance representing a primitive type
    static final Type
    non-null; instance representing java.lang.String
    static final Type
    non-null; instance representing java.lang.Throwable
    static final Type
    non-null; instance representing java.lang.invoke.VarHandle
    static final Type
    non-null; instance representing void
    static final Type
    non-null; instance representing java.lang.Void; the suffix on the name helps disambiguate this from the instance representing a primitive type
  • Method Summary

    Modifier and Type
    Method
    Description
    asUninitialized(int newAt)
    Returns a new interned instance which is identical to this one, except it is indicated as uninitialized and allocated at the given bytecode index.
    static void
     
    int
    compareTo(Type other)
    boolean
    equals(Object other)
    Gets the type corresponding to an array of this type.
    int
    Gets the basic type corresponding to this instance's frame type.
    int
    Gets the basic type corresponding to this instance.
    int
    Gets the category.
    Gets the name of the class this type corresponds to, in internal form.
    Gets the component type of this type.
    Gets the descriptor.
    Gets the frame type corresponding to this type.
    Gets the initialized type corresponding to this instance, but only if this instance is in fact an uninitialized object type.
    int
    Gets the bytecode index at which this uninitialized type was allocated.
    Gets the type associated with this instance.
    int
    static Type
    intern(String descriptor)
    Returns the unique instance corresponding to the type with the given descriptor.
    static Type
    Returns the unique instance corresponding to the type of the class with the given name.
    static Type
    Returns the unique instance corresponding to the type with the given descriptor, allowing "V" to return the type for void.
    boolean
    Gets whether this type is an array type.
    boolean
    Gets whether this type is an array type or is a known-null, and hence is compatible with array types.
    boolean
    Returns whether or not this is a category 1 type.
    boolean
    Returns whether or not this is a category 2 type.
    boolean
    Returns whether this instance represents a constant value.
    boolean
    Gets whether this type is "intlike." An intlike type is one which, when placed on a stack or in a local, is automatically converted to an int.
    boolean
    Gets whether this type is a primitive type.
    boolean
    Gets whether this type is a normal reference type.
    boolean
    Gets whether this type represents an uninitialized instance.
    Return the "human" string form of this instance.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • BT_VOID

      public static final int BT_VOID
      basic type constant for void
      See Also:
    • BT_BOOLEAN

      public static final int BT_BOOLEAN
      basic type constant for boolean
      See Also:
    • BT_BYTE

      public static final int BT_BYTE
      basic type constant for byte
      See Also:
    • BT_CHAR

      public static final int BT_CHAR
      basic type constant for char
      See Also:
    • BT_DOUBLE

      public static final int BT_DOUBLE
      basic type constant for double
      See Also:
    • BT_FLOAT

      public static final int BT_FLOAT
      basic type constant for float
      See Also:
    • BT_INT

      public static final int BT_INT
      basic type constant for int
      See Also:
    • BT_LONG

      public static final int BT_LONG
      basic type constant for long
      See Also:
    • BT_SHORT

      public static final int BT_SHORT
      basic type constant for short
      See Also:
    • BT_OBJECT

      public static final int BT_OBJECT
      basic type constant for Object
      See Also:
    • BT_ADDR

      public static final int BT_ADDR
      basic type constant for a return address
      See Also:
    • BT_COUNT

      public static final int BT_COUNT
      count of basic type constants
      See Also:
    • BOOLEAN

      public static final Type BOOLEAN
      non-null; instance representing boolean
    • BYTE

      public static final Type BYTE
      non-null; instance representing byte
    • CHAR

      public static final Type CHAR
      non-null; instance representing char
    • DOUBLE

      public static final Type DOUBLE
      non-null; instance representing double
    • FLOAT

      public static final Type FLOAT
      non-null; instance representing float
    • INT

      public static final Type INT
      non-null; instance representing int
    • LONG

      public static final Type LONG
      non-null; instance representing long
    • SHORT

      public static final Type SHORT
      non-null; instance representing short
    • VOID

      public static final Type VOID
      non-null; instance representing void
    • KNOWN_NULL

      public static final Type KNOWN_NULL
      non-null; instance representing a known-null
    • RETURN_ADDRESS

      public static final Type RETURN_ADDRESS
      non-null; instance representing a subroutine return address
    • ANNOTATION

      public static final Type ANNOTATION
      non-null; instance representing java.lang.annotation.Annotation
    • CLASS

      public static final Type CLASS
      non-null; instance representing java.lang.Class
    • CLONEABLE

      public static final Type CLONEABLE
      non-null; instance representing java.lang.Cloneable
    • METHOD_HANDLE

      public static final Type METHOD_HANDLE
      non-null; instance representing java.lang.invoke.MethodHandle
    • METHOD_TYPE

      public static final Type METHOD_TYPE
      non-null; instance representing java.lang.invoke.MethodType
    • VAR_HANDLE

      public static final Type VAR_HANDLE
      non-null; instance representing java.lang.invoke.VarHandle
    • OBJECT

      public static final Type OBJECT
      non-null; instance representing java.lang.Object
    • SERIALIZABLE

      public static final Type SERIALIZABLE
      non-null; instance representing java.io.Serializable
    • STRING

      public static final Type STRING
      non-null; instance representing java.lang.String
    • THROWABLE

      public static final Type THROWABLE
      non-null; instance representing java.lang.Throwable
    • BOOLEAN_CLASS

      public static final Type BOOLEAN_CLASS
      non-null; instance representing java.lang.Boolean; the suffix on the name helps disambiguate this from the instance representing a primitive type
    • BYTE_CLASS

      public static final Type BYTE_CLASS
      non-null; instance representing java.lang.Byte; the suffix on the name helps disambiguate this from the instance representing a primitive type
    • CHARACTER_CLASS

      public static final Type CHARACTER_CLASS
      non-null; instance representing java.lang.Character; the suffix on the name helps disambiguate this from the instance representing a primitive type
    • DOUBLE_CLASS

      public static final Type DOUBLE_CLASS
      non-null; instance representing java.lang.Double; the suffix on the name helps disambiguate this from the instance representing a primitive type
    • FLOAT_CLASS

      public static final Type FLOAT_CLASS
      non-null; instance representing java.lang.Float; the suffix on the name helps disambiguate this from the instance representing a primitive type
    • INTEGER_CLASS

      public static final Type INTEGER_CLASS
      non-null; instance representing java.lang.Integer; the suffix on the name helps disambiguate this from the instance representing a primitive type
    • LONG_CLASS

      public static final Type LONG_CLASS
      non-null; instance representing java.lang.Long; the suffix on the name helps disambiguate this from the instance representing a primitive type
    • SHORT_CLASS

      public static final Type SHORT_CLASS
      non-null; instance representing java.lang.Short; the suffix on the name helps disambiguate this from the instance representing a primitive type
    • VOID_CLASS

      public static final Type VOID_CLASS
      non-null; instance representing java.lang.Void; the suffix on the name helps disambiguate this from the instance representing a primitive type
    • BOOLEAN_ARRAY

      public static final Type BOOLEAN_ARRAY
      non-null; instance representing boolean[]
    • BYTE_ARRAY

      public static final Type BYTE_ARRAY
      non-null; instance representing byte[]
    • CHAR_ARRAY

      public static final Type CHAR_ARRAY
      non-null; instance representing char[]
    • DOUBLE_ARRAY

      public static final Type DOUBLE_ARRAY
      non-null; instance representing double[]
    • FLOAT_ARRAY

      public static final Type FLOAT_ARRAY
      non-null; instance representing float[]
    • INT_ARRAY

      public static final Type INT_ARRAY
      non-null; instance representing int[]
    • LONG_ARRAY

      public static final Type LONG_ARRAY
      non-null; instance representing long[]
    • OBJECT_ARRAY

      public static final Type OBJECT_ARRAY
      non-null; instance representing Object[]
    • SHORT_ARRAY

      public static final Type SHORT_ARRAY
      non-null; instance representing short[]
  • Method Details

    • intern

      public static Type intern(String descriptor)
      Returns the unique instance corresponding to the type with the given descriptor. See vmspec-2 sec4.3.2 for details on the field descriptor syntax. This method does not allow "V" (that is, type void) as a valid descriptor.
      Parameters:
      descriptor - non-null; the descriptor
      Returns:
      non-null; the corresponding instance
      Throws:
      IllegalArgumentException - thrown if the descriptor has invalid syntax
    • internReturnType

      public static Type internReturnType(String descriptor)
      Returns the unique instance corresponding to the type with the given descriptor, allowing "V" to return the type for void. Other than that one caveat, this method is identical to intern(java.lang.String).
      Parameters:
      descriptor - non-null; the descriptor
      Returns:
      non-null; the corresponding instance
      Throws:
      IllegalArgumentException - thrown if the descriptor has invalid syntax
    • internClassName

      public static Type internClassName(String name)
      Returns the unique instance corresponding to the type of the class with the given name. Calling this method is equivalent to calling intern(name) if name begins with "[" and calling intern("L" + name + ";") in all other cases.
      Parameters:
      name - non-null; the name of the class whose type is desired
      Returns:
      non-null; the corresponding type
      Throws:
      IllegalArgumentException - thrown if the name has invalid syntax
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(Type other)
      Specified by:
      compareTo in interface Comparable<Type>
    • toString

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

      public String toHuman()
      Return the "human" string form of this instance. This is generally less "debuggy" than toString().
      Specified by:
      toHuman in interface ToHuman
      Returns:
      non-null; the human string form
    • getType

      public Type getType()
      Gets the type associated with this instance.
      Specified by:
      getType in interface TypeBearer
      Returns:
      non-null; the type
    • getFrameType

      public Type getFrameType()
      Gets the frame type corresponding to this type. This method returns this, except if isIntlike() on the underlying type returns true but the underlying type is not in fact INT, in which case this method returns an instance whose underlying type is INT.
      Specified by:
      getFrameType in interface TypeBearer
      Returns:
      non-null; the frame type for this instance
    • getBasicType

      public int getBasicType()
      Gets the basic type corresponding to this instance.
      Specified by:
      getBasicType in interface TypeBearer
      Returns:
      the basic type; one of the BT_* constants defined by Type
    • getBasicFrameType

      public int getBasicFrameType()
      Gets the basic type corresponding to this instance's frame type. This is equivalent to getFrameType().getBasicType(), and is the same as calling getFrameType() unless this instance is an int-like type, in which case this method returns BT_INT.
      Specified by:
      getBasicFrameType in interface TypeBearer
      Returns:
      the basic frame type; one of the BT_* constants defined by Type
      See Also:
    • isConstant

      public boolean isConstant()
      Returns whether this instance represents a constant value.
      Specified by:
      isConstant in interface TypeBearer
      Returns:
      true if this instance represents a constant value and false if not
    • getDescriptor

      public String getDescriptor()
      Gets the descriptor.
      Returns:
      non-null; the descriptor
    • getClassName

      public String getClassName()
      Gets the name of the class this type corresponds to, in internal form. This method is only valid if this instance is for a normal reference type (that is, a reference type and additionally not a return address).
      Returns:
      non-null; the internal-form class name
    • getCategory

      public int getCategory()
      Gets the category. Most instances are category 1. long and double are the only category 2 types.
      Returns:
      the category
      See Also:
    • isCategory1

      public boolean isCategory1()
      Returns whether or not this is a category 1 type.
      Returns:
      whether or not this is a category 1 type
      See Also:
    • isCategory2

      public boolean isCategory2()
      Returns whether or not this is a category 2 type.
      Returns:
      whether or not this is a category 2 type
      See Also:
    • isIntlike

      public boolean isIntlike()
      Gets whether this type is "intlike." An intlike type is one which, when placed on a stack or in a local, is automatically converted to an int.
      Returns:
      whether this type is "intlike"
    • isPrimitive

      public boolean isPrimitive()
      Gets whether this type is a primitive type. All types are either primitive or reference types.
      Returns:
      whether this type is primitive
    • isReference

      public boolean isReference()
      Gets whether this type is a normal reference type. A normal reference type is a reference type that is not a return address. This method is just convenient shorthand for getBasicType() == Type.BT_OBJECT.
      Returns:
      whether this type is a normal reference type
    • isArray

      public boolean isArray()
      Gets whether this type is an array type. If this method returns true, then it is safe to use getComponentType() to determine the component type.
      Returns:
      whether this type is an array type
    • isArrayOrKnownNull

      public boolean isArrayOrKnownNull()
      Gets whether this type is an array type or is a known-null, and hence is compatible with array types.
      Returns:
      whether this type is an array type
    • isUninitialized

      public boolean isUninitialized()
      Gets whether this type represents an uninitialized instance. An uninitialized instance is what one gets back from the new opcode, and remains uninitialized until a valid constructor is invoked on it.
      Returns:
      whether this type is "uninitialized"
    • getNewAt

      public int getNewAt()
      Gets the bytecode index at which this uninitialized type was allocated. This returns Integer.MAX_VALUE if this type is an uninitialized incoming parameter (i.e., the this of an <init> method) or -1 if this type is in fact initialized.
      Returns:
      >= -1; the allocation bytecode index
    • getInitializedType

      public Type getInitializedType()
      Gets the initialized type corresponding to this instance, but only if this instance is in fact an uninitialized object type.
      Returns:
      non-null; the initialized type
    • getArrayType

      public Type getArrayType()
      Gets the type corresponding to an array of this type.
      Returns:
      non-null; the array type
    • getComponentType

      public Type getComponentType()
      Gets the component type of this type. This method is only valid on array types.
      Returns:
      non-null; the component type
    • asUninitialized

      public Type asUninitialized(int newAt)
      Returns a new interned instance which is identical to this one, except it is indicated as uninitialized and allocated at the given bytecode index. This instance must be an initialized object type.
      Parameters:
      newAt - >= 0; the allocation bytecode index
      Returns:
      non-null; an appropriately-constructed instance
    • clearInternTable

      public static void clearInternTable()