Package org.objectweb.asm
Class Type
- java.lang.Object
-
- org.objectweb.asm.Type
-
public final class Type extends java.lang.Object
A Java field or method type. This class can be used to make it easier to manipulate type and method descriptors.
-
-
Field Summary
Fields Modifier and Type Field Description static int
ARRAY
The sort of array reference types.static int
BOOLEAN
The sort of theboolean
type.static Type
BOOLEAN_TYPE
Theboolean
type.static int
BYTE
The sort of thebyte
type.static Type
BYTE_TYPE
Thebyte
type.static int
CHAR
The sort of thechar
type.static Type
CHAR_TYPE
Thechar
type.static int
DOUBLE
The sort of thedouble
type.static Type
DOUBLE_TYPE
Thedouble
type.static int
FLOAT
The sort of thefloat
type.static Type
FLOAT_TYPE
Thefloat
type.static int
INT
The sort of theint
type.static Type
INT_TYPE
Theint
type.static int
LONG
The sort of thelong
type.static Type
LONG_TYPE
Thelong
type.static int
METHOD
The sort of method types.static int
OBJECT
The sort of object reference types.static int
SHORT
The sort of theshort
type.static Type
SHORT_TYPE
Theshort
type.static int
VOID
The sort of thevoid
type.static Type
VOID_TYPE
Thevoid
type.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 theType
values corresponding to the argument types of the given method.static Type[]
getArgumentTypes(java.lang.String methodDescriptor)
Returns theType
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 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(java.lang.String internalName)
Returns theType
corresponding to the given internal name.int
getOpcode(int opcode)
Returns a JVM instruction opcode adapted to thisType
.Type
getReturnType()
Returns the return type of methods of this type.static Type
getReturnType(java.lang.reflect.Method method)
Returns theType
corresponding to the return type of the given method.static Type
getReturnType(java.lang.String methodDescriptor)
Returns theType
corresponding to 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 theType
corresponding to the given class.static Type
getType(java.lang.reflect.Constructor<?> constructor)
Returns the methodType
corresponding to the given constructor.static Type
getType(java.lang.reflect.Method method)
Returns the methodType
corresponding to the given method.static Type
getType(java.lang.String typeDescriptor)
Returns theType
corresponding to the given type descriptor.int
hashCode()
Returns a hash code value for this type.java.lang.String
toString()
Returns a string representation of this type.
-
-
-
Field Detail
-
VOID
public static final int VOID
The sort of thevoid
type. SeegetSort()
.- See Also:
- Constant Field Values
-
BOOLEAN
public static final int BOOLEAN
The sort of theboolean
type. SeegetSort()
.- See Also:
- Constant Field Values
-
CHAR
public static final int CHAR
The sort of thechar
type. SeegetSort()
.- See Also:
- Constant Field Values
-
BYTE
public static final int BYTE
The sort of thebyte
type. SeegetSort()
.- See Also:
- Constant Field Values
-
SHORT
public static final int SHORT
The sort of theshort
type. SeegetSort()
.- See Also:
- Constant Field Values
-
INT
public static final int INT
The sort of theint
type. SeegetSort()
.- See Also:
- Constant Field Values
-
FLOAT
public static final int FLOAT
The sort of thefloat
type. SeegetSort()
.- See Also:
- Constant Field Values
-
LONG
public static final int LONG
The sort of thelong
type. SeegetSort()
.- See Also:
- Constant Field Values
-
DOUBLE
public static final int DOUBLE
The sort of thedouble
type. SeegetSort()
.- See Also:
- Constant Field Values
-
ARRAY
public static final int ARRAY
The sort of array reference types. SeegetSort()
.- See Also:
- Constant Field Values
-
OBJECT
public static final int OBJECT
The sort of object reference types. SeegetSort()
.- See Also:
- Constant Field Values
-
METHOD
public static final int METHOD
The sort of method types. SeegetSort()
.- See Also:
- Constant Field Values
-
VOID_TYPE
public static final Type VOID_TYPE
Thevoid
type.
-
BOOLEAN_TYPE
public static final Type BOOLEAN_TYPE
Theboolean
type.
-
CHAR_TYPE
public static final Type CHAR_TYPE
Thechar
type.
-
BYTE_TYPE
public static final Type BYTE_TYPE
Thebyte
type.
-
SHORT_TYPE
public static final Type SHORT_TYPE
Theshort
type.
-
INT_TYPE
public static final Type INT_TYPE
Theint
type.
-
FLOAT_TYPE
public static final Type FLOAT_TYPE
Thefloat
type.
-
LONG_TYPE
public static final Type LONG_TYPE
Thelong
type.
-
DOUBLE_TYPE
public static final Type DOUBLE_TYPE
Thedouble
type.
-
-
Method Detail
-
getType
public static Type getType(java.lang.String typeDescriptor)
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
public static Type getType(java.lang.Class<?> clazz)
Returns theType
corresponding to the given class.- Parameters:
clazz
- a class.- Returns:
- the
Type
corresponding to the given class.
-
getType
public static Type getType(java.lang.reflect.Constructor<?> constructor)
Returns the methodType
corresponding to the given constructor.- Parameters:
constructor
- aConstructor
object.- Returns:
- the method
Type
corresponding to the given constructor.
-
getType
public static Type getType(java.lang.reflect.Method method)
Returns the methodType
corresponding to the given method.- Parameters:
method
- aMethod
object.- Returns:
- the method
Type
corresponding to the given method.
-
getElementType
public Type 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
public static Type getObjectType(java.lang.String internalName)
Returns theType
corresponding to the given internal name.- Parameters:
internalName
- an internal name.- Returns:
- the
Type
corresponding to the given internal name.
-
getMethodType
public static Type getMethodType(java.lang.String methodDescriptor)
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
public static Type getMethodType(Type returnType, Type... argumentTypes)
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
public Type[] 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
public static Type[] getArgumentTypes(java.lang.String methodDescriptor)
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
public static Type[] getArgumentTypes(java.lang.reflect.Method method)
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
public Type 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
public static Type getReturnType(java.lang.String methodDescriptor)
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
public static Type getReturnType(java.lang.reflect.Method method)
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.
-
getClassName
public java.lang.String 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
public java.lang.String 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
public static java.lang.String getInternalName(java.lang.Class<?> clazz)
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
public java.lang.String getDescriptor()
Returns the descriptor corresponding to this type.- Returns:
- the descriptor corresponding to this type.
-
getDescriptor
public static java.lang.String getDescriptor(java.lang.Class<?> clazz)
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
public static java.lang.String getConstructorDescriptor(java.lang.reflect.Constructor<?> constructor)
Returns the descriptor corresponding to the given constructor.- Parameters:
constructor
- aConstructor
object.- Returns:
- the descriptor of the given constructor.
-
getMethodDescriptor
public static java.lang.String getMethodDescriptor(Type returnType, Type... argumentTypes)
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
public static java.lang.String getMethodDescriptor(java.lang.reflect.Method method)
Returns the descriptor corresponding to the given method.- Parameters:
method
- aMethod
object.- Returns:
- the descriptor of the given method.
-
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
public static int getArgumentsAndReturnSizes(java.lang.String methodDescriptor)
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
public boolean equals(java.lang.Object object)
Tests if the given object is equal to this type.- Overrides:
equals
in classjava.lang.Object
- Parameters:
object
- the object to be compared to this type.- Returns:
- true if the given object is equal to this type.
-
hashCode
public int hashCode()
Returns a hash code value for this type.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- a hash code value for this type.
-
toString
public java.lang.String toString()
Returns a string representation of this type.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the descriptor of this type.
-
-