com.android.dx.rop.type
Class Type

java.lang.Object
  extended by 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
static Type ANNOTATION
          non-null; instance representing java.lang.annotation.Annotation
static Type BOOLEAN
          non-null; instance representing boolean
static Type BOOLEAN_ARRAY
          non-null; instance representing boolean[]
static 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
static int BT_ADDR
          basic type constant for a return address
static int BT_BOOLEAN
          basic type constant for boolean
static int BT_BYTE
          basic type constant for byte
static int BT_CHAR
          basic type constant for char
static int BT_COUNT
          count of basic type constants
static int BT_DOUBLE
          basic type constant for double
static int BT_FLOAT
          basic type constant for float
static int BT_INT
          basic type constant for int
static int BT_LONG
          basic type constant for long
static int BT_OBJECT
          basic type constant for Object
static int BT_SHORT
          basic type constant for short
static int BT_VOID
          basic type constant for void
static Type BYTE
          non-null; instance representing byte
static Type BYTE_ARRAY
          non-null; instance representing byte[]
static 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
static Type CHAR
          non-null; instance representing char
static Type CHAR_ARRAY
          non-null; instance representing char[]
static 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
static Type CLASS
          non-null; instance representing java.lang.Class
static Type CLONEABLE
          non-null; instance representing java.lang.Cloneable
static Type DOUBLE
          non-null; instance representing double
static Type DOUBLE_ARRAY
          non-null; instance representing double[]
static 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
static Type FLOAT
          non-null; instance representing float
static Type FLOAT_ARRAY
          non-null; instance representing float[]
static 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
static Type INT
          non-null; instance representing int
static Type INT_ARRAY
          non-null; instance representing int[]
static 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
static Type KNOWN_NULL
          non-null; instance representing a known-null
static Type LONG
          non-null; instance representing long
static Type LONG_ARRAY
          non-null; instance representing long[]
static 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
static Type OBJECT
          non-null; instance representing java.lang.Object
static Type OBJECT_ARRAY
          non-null; instance representing Object[]
static Type RETURN_ADDRESS
          non-null; instance representing a subroutine return address
static Type SERIALIZABLE
          non-null; instance representing java.io.Serializable
static Type SHORT
          non-null; instance representing short
static Type SHORT_ARRAY
          non-null; instance representing short[]
static 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
static Type STRING
          non-null; instance representing java.lang.String
static Type THROWABLE
          non-null; instance representing java.lang.Throwable
static Type VOID
          non-null; instance representing void
static 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
 
Method Summary
 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.
 int compareTo(Type other)
          
 boolean equals(Object other)
          
 Type getArrayType()
          Gets the type corresponding to an array of this type.
 int getBasicFrameType()
          Gets the basic type corresponding to this instance's frame type.
 int getBasicType()
          Gets the basic type corresponding to this instance.
 int getCategory()
          Gets the category.
 String getClassName()
          Gets the name of the class this type corresponds to, in internal form.
 Type getComponentType()
          Gets the component type of this type.
 String getDescriptor()
          Gets the descriptor.
 Type getFrameType()
          Gets the frame type corresponding to this type.
 Type getInitializedType()
          Gets the initialized type corresponding to this instance, but only if this instance is in fact an uninitialized object type.
 int getNewAt()
          Gets the bytecode index at which this uninitialized type was allocated.
 Type getType()
          Gets the type associated with this instance.
 int hashCode()
          
static Type intern(String descriptor)
          Returns the unique instance corresponding to the type with the given descriptor.
static Type internClassName(String name)
          Returns the unique instance corresponding to the type of the class with the given name.
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.
 boolean isArray()
          Gets whether this type is an array type.
 boolean isArrayOrKnownNull()
          Gets whether this type is an array type or is a known-null, and hence is compatible with array types.
 boolean isCategory1()
          Returns whether or not this is a category 1 type.
 boolean isCategory2()
          Returns whether or not this is a category 2 type.
 boolean isConstant()
          Returns whether this instance represents a constant value.
 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.
 boolean isPrimitive()
          Gets whether this type is a primitive type.
 boolean isReference()
          Gets whether this type is a normal reference type.
 boolean isUninitialized()
          Gets whether this type represents an uninitialized instance.
 String toHuman()
          Return the "human" string form of this instance.
 String toString()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

BT_VOID

public static final int BT_VOID
basic type constant for void

See Also:
Constant Field Values

BT_BOOLEAN

public static final int BT_BOOLEAN
basic type constant for boolean

See Also:
Constant Field Values

BT_BYTE

public static final int BT_BYTE
basic type constant for byte

See Also:
Constant Field Values

BT_CHAR

public static final int BT_CHAR
basic type constant for char

See Also:
Constant Field Values

BT_DOUBLE

public static final int BT_DOUBLE
basic type constant for double

See Also:
Constant Field Values

BT_FLOAT

public static final int BT_FLOAT
basic type constant for float

See Also:
Constant Field Values

BT_INT

public static final int BT_INT
basic type constant for int

See Also:
Constant Field Values

BT_LONG

public static final int BT_LONG
basic type constant for long

See Also:
Constant Field Values

BT_SHORT

public static final int BT_SHORT
basic type constant for short

See Also:
Constant Field Values

BT_OBJECT

public static final int BT_OBJECT
basic type constant for Object

See Also:
Constant Field Values

BT_ADDR

public static final int BT_ADDR
basic type constant for a return address

See Also:
Constant Field Values

BT_COUNT

public static final int BT_COUNT
count of basic type constants

See Also:
Constant Field Values

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


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 Detail

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:
TypeBearer.getBasicType(), TypeBearer.getFrameType()

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(), isCategory2()

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:
getCategory(), isCategory2()

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:
getCategory(), isCategory1()

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


Copyright © 2015. All rights reserved.