public final class Type
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
ARRAY
The sort of array reference types.
|
static int |
BOOLEAN
The sort of the
boolean type. |
static Type |
BOOLEAN_TYPE
The
boolean type. |
static int |
BYTE
The sort of the
byte type. |
static Type |
BYTE_TYPE
The
byte type. |
static int |
CHAR
The sort of the
char type. |
static Type |
CHAR_TYPE
The
char type. |
static int |
DOUBLE
The sort of the
double type. |
static Type |
DOUBLE_TYPE
The
double type. |
static int |
FLOAT
The sort of the
float type. |
static Type |
FLOAT_TYPE
The
float type. |
static int |
INT
The sort of the
int type. |
static Type |
INT_TYPE
The
int type. |
private static int |
INTERNAL
The (private) sort of object reference types represented with an internal name.
|
static int |
LONG
The sort of the
long type. |
static Type |
LONG_TYPE
The
long type. |
static int |
METHOD
The sort of method types.
|
static int |
OBJECT
The sort of object reference types.
|
private static java.lang.String |
PRIMITIVE_DESCRIPTORS
The descriptors of the primitive types.
|
static int |
SHORT
The sort of the
short type. |
static Type |
SHORT_TYPE
The
short type. |
private int |
sort
The sort of this type.
|
private int |
valueBegin
The beginning index, inclusive, of the value of this Java field or method type in
valueBuffer . |
private java.lang.String |
valueBuffer
A buffer containing the value of this field or method type.
|
private int |
valueEnd
The end index, exclusive, of the value of this Java field or method type in
valueBuffer . |
static int |
VOID
The sort of the
void type. |
static Type |
VOID_TYPE
The
void type. |
Modifier | Constructor and Description |
---|---|
private |
Type(int sort,
java.lang.String valueBuffer,
int valueBegin,
int valueEnd)
Constructs a reference type.
|
Modifier and Type | Method and Description |
---|---|
private static void |
appendDescriptor(java.lang.Class<?> clazz,
java.lang.StringBuilder stringBuilder)
Appends the descriptor of the given class to the given string builder.
|
private void |
appendDescriptor(java.lang.StringBuilder stringBuilder)
Appends the descriptor corresponding to this type to the given string buffer.
|
boolean |
equals(java.lang.Object object)
Tests if the given object is equal to this type.
|
int |
getArgumentsAndReturnSizes()
Returns the size of the arguments and of the return value of methods of this type.
|
static int |
getArgumentsAndReturnSizes(java.lang.String methodDescriptor)
Computes the size of the arguments and of the return value of a method.
|
Type[] |
getArgumentTypes()
Returns the argument types of methods of this type.
|
static Type[] |
getArgumentTypes(java.lang.reflect.Method method)
Returns the
Type values corresponding to the argument types of the given method. |
static Type[] |
getArgumentTypes(java.lang.String methodDescriptor)
Returns the
Type values corresponding to the argument types of the given method
descriptor. |
java.lang.String |
getClassName()
Returns the binary name of the class corresponding to this type.
|
static java.lang.String |
getConstructorDescriptor(java.lang.reflect.Constructor<?> constructor)
Returns the descriptor corresponding to the given constructor.
|
java.lang.String |
getDescriptor()
Returns the descriptor corresponding to this type.
|
static java.lang.String |
getDescriptor(java.lang.Class<?> clazz)
Returns the descriptor corresponding to the given class.
|
int |
getDimensions()
Returns the number of dimensions of this array type.
|
Type |
getElementType()
Returns the type of the elements of this array type.
|
java.lang.String |
getInternalName()
Returns the internal name of the class corresponding to this object or array type.
|
static java.lang.String |
getInternalName(java.lang.Class<?> clazz)
Returns the internal name of the given class.
|
static java.lang.String |
getMethodDescriptor(java.lang.reflect.Method method)
Returns the descriptor corresponding to the given method.
|
static java.lang.String |
getMethodDescriptor(Type returnType,
Type... argumentTypes)
Returns the descriptor corresponding to the given argument and return types.
|
static Type |
getMethodType(java.lang.String methodDescriptor)
Returns the
Type corresponding to the given method descriptor. |
static Type |
getMethodType(Type returnType,
Type... argumentTypes)
Returns the method
Type corresponding to the given argument and return types. |
static Type |
getObjectType(java.lang.String internalName)
Returns the
Type corresponding to the given internal name. |
int |
getOpcode(int opcode)
Returns a JVM instruction opcode adapted to this
Type . |
Type |
getReturnType()
Returns the return type of methods of this type.
|
static Type |
getReturnType(java.lang.reflect.Method method)
Returns the
Type corresponding to the return type of the given method. |
static Type |
getReturnType(java.lang.String methodDescriptor)
Returns the
Type corresponding to the return type of the given method descriptor. |
(package private) static int |
getReturnTypeOffset(java.lang.String methodDescriptor)
Returns the start index of the return type of the given method descriptor.
|
int |
getSize()
Returns the size of values of this type.
|
int |
getSort()
Returns the sort of this type.
|
static Type |
getType(java.lang.Class<?> clazz)
Returns the
Type corresponding to the given class. |
static Type |
getType(java.lang.reflect.Constructor<?> constructor)
Returns the method
Type corresponding to the given constructor. |
static Type |
getType(java.lang.reflect.Method method)
Returns the method
Type corresponding to the given method. |
static Type |
getType(java.lang.String typeDescriptor)
Returns the
Type corresponding to the given type descriptor. |
private static Type |
getTypeInternal(java.lang.String descriptorBuffer,
int descriptorBegin,
int descriptorEnd)
Returns the
Type corresponding to the given field or method descriptor. |
int |
hashCode()
Returns a hash code value for this type.
|
java.lang.String |
toString()
Returns a string representation of this type.
|
public static final int VOID
void
type. See getSort()
.public static final int BOOLEAN
boolean
type. See getSort()
.public static final int CHAR
char
type. See getSort()
.public static final int BYTE
byte
type. See getSort()
.public static final int SHORT
short
type. See getSort()
.public static final int INT
int
type. See getSort()
.public static final int FLOAT
float
type. See getSort()
.public static final int LONG
long
type. See getSort()
.public static final int DOUBLE
double
type. See getSort()
.public static final int ARRAY
getSort()
.public static final int OBJECT
getSort()
.public static final int METHOD
getSort()
.private static final int INTERNAL
private static final java.lang.String PRIMITIVE_DESCRIPTORS
public static final Type VOID_TYPE
void
type.public static final Type BOOLEAN_TYPE
boolean
type.public static final Type CHAR_TYPE
char
type.public static final Type BYTE_TYPE
byte
type.public static final Type SHORT_TYPE
short
type.public static final Type INT_TYPE
int
type.public static final Type FLOAT_TYPE
float
type.public static final Type LONG_TYPE
long
type.public static final Type DOUBLE_TYPE
double
type.private final int sort
private final java.lang.String valueBuffer
OBJECT
and INTERNAL
types, and a field or method descriptor in the other
cases.
For OBJECT
types, this field also contains the descriptor: the characters in
[valueBegin
,valueEnd
) contain the internal name, and those in [valueBegin
- 1, valueEnd
+ 1) contain the descriptor.
private final int valueBegin
valueBuffer
. This value is an internal name for OBJECT
and INTERNAL
types,
and a field or method descriptor in the other cases.private final int valueEnd
valueBuffer
. This value is an internal name for OBJECT
and INTERNAL
types,
and a field or method descriptor in the other cases.private Type(int sort, java.lang.String valueBuffer, int valueBegin, int valueEnd)
sort
- the sort of this type, see sort
.valueBuffer
- a buffer containing the value of this field or method type.valueBegin
- the beginning index, inclusive, of the value of this field or method type in
valueBuffer.valueEnd
- the end index, exclusive, of the value of this field or method type in
valueBuffer.public static Type getType(java.lang.String typeDescriptor)
Type
corresponding to the given type descriptor.typeDescriptor
- a field or method type descriptor.Type
corresponding to the given type descriptor.public static Type getType(java.lang.Class<?> clazz)
Type
corresponding to the given class.clazz
- a class.Type
corresponding to the given class.public static Type getType(java.lang.reflect.Constructor<?> constructor)
Type
corresponding to the given constructor.constructor
- a Constructor
object.Type
corresponding to the given constructor.public static Type getType(java.lang.reflect.Method method)
Type
corresponding to the given method.method
- a Method
object.Type
corresponding to the given method.public Type getElementType()
public static Type getObjectType(java.lang.String internalName)
Type
corresponding to the given internal name.internalName
- an internal name.Type
corresponding to the given internal name.public static Type getMethodType(java.lang.String methodDescriptor)
Type
corresponding to the given method descriptor. Equivalent to
Type.getType(methodDescriptor)
.methodDescriptor
- a method descriptor.Type
corresponding to the given method descriptor.public static Type getMethodType(Type returnType, Type... argumentTypes)
Type
corresponding to the given argument and return types.returnType
- the return type of the method.argumentTypes
- the argument types of the method.Type
corresponding to the given argument and return types.public Type[] getArgumentTypes()
public static Type[] getArgumentTypes(java.lang.String methodDescriptor)
Type
values corresponding to the argument types of the given method
descriptor.methodDescriptor
- a method descriptor.Type
values corresponding to the argument types of the given method
descriptor.public static Type[] getArgumentTypes(java.lang.reflect.Method method)
Type
values corresponding to the argument types of the given method.method
- a method.Type
values corresponding to the argument types of the given method.public Type getReturnType()
public static Type getReturnType(java.lang.String methodDescriptor)
Type
corresponding to the return type of the given method descriptor.methodDescriptor
- a method descriptor.Type
corresponding to the return type of the given method descriptor.public static Type getReturnType(java.lang.reflect.Method method)
Type
corresponding to the return type of the given method.method
- a method.Type
corresponding to the return type of the given method.static int getReturnTypeOffset(java.lang.String methodDescriptor)
methodDescriptor
- a method descriptor.private static Type getTypeInternal(java.lang.String descriptorBuffer, int descriptorBegin, int descriptorEnd)
Type
corresponding to the given field or method descriptor.descriptorBuffer
- a buffer containing the field or method descriptor.descriptorBegin
- the beginning index, inclusive, of the field or method descriptor in
descriptorBuffer.descriptorEnd
- the end index, exclusive, of the field or method descriptor in
descriptorBuffer.Type
corresponding to the given type descriptor.public java.lang.String getClassName()
public java.lang.String getInternalName()
public static java.lang.String getInternalName(java.lang.Class<?> clazz)
clazz
- an object or array class.public java.lang.String getDescriptor()
public static java.lang.String getDescriptor(java.lang.Class<?> clazz)
clazz
- an object class, a primitive class or an array class.public static java.lang.String getConstructorDescriptor(java.lang.reflect.Constructor<?> constructor)
constructor
- a Constructor
object.public static java.lang.String getMethodDescriptor(Type returnType, Type... argumentTypes)
returnType
- the return type of the method.argumentTypes
- the argument types of the method.public static java.lang.String getMethodDescriptor(java.lang.reflect.Method method)
method
- a Method
object.private void appendDescriptor(java.lang.StringBuilder stringBuilder)
stringBuilder
- the string builder to which the descriptor must be appended.private static void appendDescriptor(java.lang.Class<?> clazz, java.lang.StringBuilder stringBuilder)
clazz
- the class whose descriptor must be computed.stringBuilder
- the string builder to which the descriptor must be appended.public int getSort()
public int getDimensions()
public int getSize()
long
and double
, 0 for
void
and 1 otherwise.public int getArgumentsAndReturnSizes()
(argumentsSize << 2) | returnSize
(argumentsSize is therefore equal to i >> 2
, and returnSize to i & 0x03
).public static int getArgumentsAndReturnSizes(java.lang.String methodDescriptor)
methodDescriptor
- a method descriptor.(argumentsSize << 2) | returnSize
(argumentsSize is therefore equal to i >> 2
, and returnSize to i & 0x03
).public int getOpcode(int opcode)
Type
. This method must not be used for
method types.opcode
- a JVM instruction opcode. This opcode must be one of ILOAD, ISTORE, IALOAD,
IASTORE, IADD, ISUB, IMUL, IDIV, IREM, INEG, ISHL, ISHR, IUSHR, IAND, IOR, IXOR and
IRETURN.Type
. For
example, if this type is float
and opcode
is IRETURN, this method returns
FRETURN.public boolean equals(java.lang.Object object)
equals
in class java.lang.Object
object
- the object to be compared to this type.public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object