Package org.objectweb.asm
Class Type
java.lang.Object
org.objectweb.asm.Type
A Java field or method type. This class can be used to make it easier to manipulate type and
method descriptors.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The sort of array reference types.static final int
The sort of theboolean
type.static final Type
Theboolean
type.static final int
The sort of thebyte
type.static final Type
Thebyte
type.static final int
The sort of thechar
type.static final Type
Thechar
type.static final int
The sort of thedouble
type.static final Type
Thedouble
type.static final int
The sort of thefloat
type.static final Type
Thefloat
type.static final int
The sort of theint
type.static final Type
Theint
type.private static final int
The (private) sort of object reference types represented with an internal name.static final int
The sort of thelong
type.static final Type
Thelong
type.static final int
The sort of method types.static final int
The sort of object reference types.private static final String
The descriptors of the primitive types.static final int
The sort of theshort
type.static final Type
Theshort
type.private final int
The sort of this type.private final int
The beginning index, inclusive, of the value of this Java field or method type invalueBuffer
.private final String
A buffer containing the value of this field or method type.private final int
The end index, exclusive, of the value of this Java field or method type invalueBuffer
.static final int
The sort of thevoid
type.static final Type
Thevoid
type. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
appendDescriptor
(Class<?> clazz, StringBuilder stringBuilder) Appends the descriptor of the given class to the given string builder.private void
appendDescriptor
(StringBuilder stringBuilder) Appends the descriptor corresponding to this type to the given string buffer.boolean
Tests if the given object is equal to this type.int
Returns the size of the arguments and of the return value of methods of this type.static int
getArgumentsAndReturnSizes
(String methodDescriptor) Computes the size of the arguments and of the return value of a method.Type[]
Returns the argument types of methods of this type.static Type[]
getArgumentTypes
(Method method) Returns theType
values corresponding to the argument types of the given method.static Type[]
getArgumentTypes
(String methodDescriptor) Returns theType
values corresponding to the argument types of the given method descriptor.Returns the binary name of the class corresponding to this type.static String
getConstructorDescriptor
(Constructor<?> constructor) Returns the descriptor corresponding to the given constructor.Returns the descriptor corresponding to this type.static String
getDescriptor
(Class<?> clazz) Returns the descriptor corresponding to the given class.int
Returns the number of dimensions of this array type.Returns the type of the elements of this array type.Returns the internal name of the class corresponding to this object or array type.static String
getInternalName
(Class<?> clazz) Returns the internal name of the given class.static String
getMethodDescriptor
(Method method) Returns the descriptor corresponding to the given method.static String
getMethodDescriptor
(Type returnType, Type... argumentTypes) Returns the descriptor corresponding to the given argument and return types.static Type
getMethodType
(String methodDescriptor) Returns theType
corresponding to the given method descriptor.static Type
getMethodType
(Type returnType, Type... argumentTypes) Returns the methodType
corresponding to the given argument and return types.static Type
getObjectType
(String internalName) Returns theType
corresponding to the given internal name.int
getOpcode
(int opcode) Returns a JVM instruction opcode adapted to thisType
.Returns the return type of methods of this type.static Type
getReturnType
(Method method) Returns theType
corresponding to the return type of the given method.static Type
getReturnType
(String methodDescriptor) Returns theType
corresponding to the return type of the given method descriptor.(package private) static int
getReturnTypeOffset
(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
Returns theType
corresponding to the given class.static Type
getType
(Constructor<?> constructor) Returns the methodType
corresponding to the given constructor.static Type
Returns the methodType
corresponding to the given method.static Type
Returns theType
corresponding to the given type descriptor.private static Type
getTypeInternal
(String descriptorBuffer, int descriptorBegin, int descriptorEnd) Returns theType
corresponding to the given field or method descriptor.int
hashCode()
Returns a hash code value for this type.toString()
Returns a string representation of this type.
-
Field Details
-
VOID
public static final int VOIDThe sort of thevoid
type. SeegetSort()
.- See Also:
-
BOOLEAN
public static final int BOOLEANThe sort of theboolean
type. SeegetSort()
.- See Also:
-
CHAR
public static final int CHARThe sort of thechar
type. SeegetSort()
.- See Also:
-
BYTE
public static final int BYTEThe sort of thebyte
type. SeegetSort()
.- See Also:
-
SHORT
public static final int SHORTThe sort of theshort
type. SeegetSort()
.- See Also:
-
INT
public static final int INTThe sort of theint
type. SeegetSort()
.- See Also:
-
FLOAT
public static final int FLOATThe sort of thefloat
type. SeegetSort()
.- See Also:
-
LONG
public static final int LONGThe sort of thelong
type. SeegetSort()
.- See Also:
-
DOUBLE
public static final int DOUBLEThe sort of thedouble
type. SeegetSort()
.- See Also:
-
ARRAY
public static final int ARRAYThe sort of array reference types. SeegetSort()
.- See Also:
-
OBJECT
public static final int OBJECTThe sort of object reference types. SeegetSort()
.- See Also:
-
METHOD
public static final int METHODThe sort of method types. SeegetSort()
.- See Also:
-
INTERNAL
private static final int INTERNALThe (private) sort of object reference types represented with an internal name.- See Also:
-
PRIMITIVE_DESCRIPTORS
The descriptors of the primitive types.- See Also:
-
VOID_TYPE
Thevoid
type. -
BOOLEAN_TYPE
Theboolean
type. -
CHAR_TYPE
Thechar
type. -
BYTE_TYPE
Thebyte
type. -
SHORT_TYPE
Theshort
type. -
INT_TYPE
Theint
type. -
FLOAT_TYPE
Thefloat
type. -
LONG_TYPE
Thelong
type. -
DOUBLE_TYPE
Thedouble
type. -
sort
private final int sort -
valueBuffer
A buffer containing the value of this field or method type. This value is an internal name forOBJECT
andINTERNAL
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. -
valueBegin
private final int valueBeginThe beginning index, inclusive, of the value of this Java field or method type invalueBuffer
. This value is an internal name forOBJECT
andINTERNAL
types, and a field or method descriptor in the other cases. -
valueEnd
private final int valueEndThe end index, exclusive, of the value of this Java field or method type invalueBuffer
. This value is an internal name forOBJECT
andINTERNAL
types, and a field or method descriptor in the other cases.
-
-
Constructor Details
-
Type
Constructs a reference type.- Parameters:
sort
- the sort of this type, seesort
.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.
-
-
Method Details
-
getType
Returns theType
corresponding to the given type descriptor.- Parameters:
typeDescriptor
- a field or method type descriptor.- Returns:
- the
Type
corresponding to the given type descriptor.
-
getType
Returns theType
corresponding to the given class.- Parameters:
clazz
- a class.- Returns:
- the
Type
corresponding to the given class.
-
getType
Returns the methodType
corresponding to the given constructor.- Parameters:
constructor
- aConstructor
object.- Returns:
- the method
Type
corresponding to the given constructor.
-
getType
Returns the methodType
corresponding to the given method. -
getElementType
Returns the type of the elements of this array type. This method should only be used for an array type.- Returns:
- Returns the type of the elements of this array type.
-
getObjectType
Returns theType
corresponding to the given internal name.- Parameters:
internalName
- an internal name (seegetInternalName()
).- Returns:
- the
Type
corresponding to the given internal name.
-
getMethodType
Returns theType
corresponding to the given method descriptor. Equivalent toType.getType(methodDescriptor)
.- Parameters:
methodDescriptor
- a method descriptor.- Returns:
- the
Type
corresponding to the given method descriptor.
-
getMethodType
Returns the methodType
corresponding to the given argument and return types.- Parameters:
returnType
- the return type of the method.argumentTypes
- the argument types of the method.- Returns:
- the method
Type
corresponding to the given argument and return types.
-
getArgumentTypes
Returns the argument types of methods of this type. This method should only be used for method types.- Returns:
- the argument types of methods of this type.
-
getArgumentTypes
Returns theType
values corresponding to the argument types of the given method descriptor.- Parameters:
methodDescriptor
- a method descriptor.- Returns:
- the
Type
values corresponding to the argument types of the given method descriptor.
-
getArgumentTypes
Returns theType
values corresponding to the argument types of the given method.- Parameters:
method
- a method.- Returns:
- the
Type
values corresponding to the argument types of the given method.
-
getReturnType
Returns the return type of methods of this type. This method should only be used for method types.- Returns:
- the return type of methods of this type.
-
getReturnType
Returns theType
corresponding to the return type of the given method descriptor.- Parameters:
methodDescriptor
- a method descriptor.- Returns:
- the
Type
corresponding to the return type of the given method descriptor.
-
getReturnType
Returns theType
corresponding to the return type of the given method.- Parameters:
method
- a method.- Returns:
- the
Type
corresponding to the return type of the given method.
-
getReturnTypeOffset
Returns the start index of the return type of the given method descriptor.- Parameters:
methodDescriptor
- a method descriptor.- Returns:
- the start index of the return type of the given method descriptor.
-
getTypeInternal
private static Type getTypeInternal(String descriptorBuffer, int descriptorBegin, int descriptorEnd) Returns theType
corresponding to the given field or method descriptor.- Parameters:
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.- Returns:
- the
Type
corresponding to the given type descriptor.
-
getClassName
Returns the binary name of the class corresponding to this type. This method must not be used on method types.- Returns:
- the binary name of the class corresponding to this type.
-
getInternalName
Returns the internal name of the class corresponding to this object or array type. The internal name of a class is its fully qualified name (as returned by Class.getName(), where '.' are replaced by '/'). This method should only be used for an object or array type.- Returns:
- the internal name of the class corresponding to this object type.
-
getInternalName
Returns the internal name of the given class. The internal name of a class is its fully qualified name, as returned by Class.getName(), where '.' are replaced by '/'.- Parameters:
clazz
- an object or array class.- Returns:
- the internal name of the given class.
-
getDescriptor
Returns the descriptor corresponding to this type.- Returns:
- the descriptor corresponding to this type.
-
getDescriptor
Returns the descriptor corresponding to the given class.- Parameters:
clazz
- an object class, a primitive class or an array class.- Returns:
- the descriptor corresponding to the given class.
-
getConstructorDescriptor
Returns the descriptor corresponding to the given constructor.- Parameters:
constructor
- aConstructor
object.- Returns:
- the descriptor of the given constructor.
-
getMethodDescriptor
Returns the descriptor corresponding to the given argument and return types.- Parameters:
returnType
- the return type of the method.argumentTypes
- the argument types of the method.- Returns:
- the descriptor corresponding to the given argument and return types.
-
getMethodDescriptor
Returns the descriptor corresponding to the given method.- Parameters:
method
- aMethod
object.- Returns:
- the descriptor of the given method.
-
appendDescriptor
Appends the descriptor corresponding to this type to the given string buffer.- Parameters:
stringBuilder
- the string builder to which the descriptor must be appended.
-
appendDescriptor
Appends the descriptor of the given class to the given string builder.- Parameters:
clazz
- the class whose descriptor must be computed.stringBuilder
- the string builder to which the descriptor must be appended.
-
getSort
public int getSort()Returns the sort of this type. -
getDimensions
public int getDimensions()Returns the number of dimensions of this array type. This method should only be used for an array type.- Returns:
- the number of dimensions of this array type.
-
getSize
public int getSize()Returns the size of values of this type. This method must not be used for method types.- Returns:
- the size of values of this type, i.e., 2 for
long
anddouble
, 0 forvoid
and 1 otherwise.
-
getArgumentsAndReturnSizes
public int getArgumentsAndReturnSizes()Returns the size of the arguments and of the return value of methods of this type. This method should only be used for method types.- Returns:
- the size of the arguments of the method (plus one for the implicit this argument),
argumentsSize, and the size of its return value, returnSize, packed into a single int i =
(argumentsSize << 2) | returnSize
(argumentsSize is therefore equal toi >> 2
, and returnSize toi & 0x03
).
-
getArgumentsAndReturnSizes
Computes the size of the arguments and of the return value of a method.- Parameters:
methodDescriptor
- a method descriptor.- Returns:
- the size of the arguments of the method (plus one for the implicit this argument),
argumentsSize, and the size of its return value, returnSize, packed into a single int i =
(argumentsSize << 2) | returnSize
(argumentsSize is therefore equal toi >> 2
, and returnSize toi & 0x03
).
-
getOpcode
public int getOpcode(int opcode) Returns a JVM instruction opcode adapted to thisType
. This method must not be used for method types.- Parameters:
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.- Returns:
- an opcode that is similar to the given opcode, but adapted to this
Type
. For example, if this type isfloat
andopcode
is IRETURN, this method returns FRETURN.
-
equals
Tests if the given object is equal to this type. -
hashCode
public int hashCode()Returns a hash code value for this type. -
toString
Returns a string representation of this type.
-