org.objectweb.asm

Class Type

public class Type extends Object

A Java type. This class can be used to make it easier to manipulate type and method descriptors.

Author: Eric Bruneton Chris Nokleberg

Field Summary
static intARRAY
The sort of array reference types.
static intBOOLEAN
The sort of the boolean type.
static TypeBOOLEAN_TYPE
The boolean type.
static intBYTE
The sort of the byte type.
static TypeBYTE_TYPE
The byte type.
static intCHAR
The sort of the char type.
static TypeCHAR_TYPE
The char type.
static intDOUBLE
The sort of the double type.
static TypeDOUBLE_TYPE
The double type.
static intFLOAT
The sort of the float type.
static TypeFLOAT_TYPE
The float type.
static intINT
The sort of the int type.
static TypeINT_TYPE
The int type.
static intLONG
The sort of the long type.
static TypeLONG_TYPE
The long type.
static intOBJECT
The sort of object reference type.
static intSHORT
The sort of the short type.
static TypeSHORT_TYPE
The short type.
static intVOID
The sort of the void type.
static TypeVOID_TYPE
The void type.
Method Summary
booleanequals(Object o)
Tests if the given object is equal to this type.
static intgetArgumentsAndReturnSizes(String desc)
Computes the size of the arguments and of the return value of a method.
static Type[]getArgumentTypes(String methodDescriptor)
Returns the Java types corresponding to the argument types of the given method descriptor.
static Type[]getArgumentTypes(Method method)
Returns the Java types corresponding to the argument types of the given method.
StringgetClassName()
Returns the name of the class corresponding to this type.
static StringgetConstructorDescriptor(Constructor c)
Returns the descriptor corresponding to the given constructor.
StringgetDescriptor()
Returns the descriptor corresponding to this Java type.
static StringgetDescriptor(Class c)
Returns the descriptor corresponding to the given Java type.
intgetDimensions()
Returns the number of dimensions of this array type.
TypegetElementType()
Returns the type of the elements of this array type.
StringgetInternalName()
Returns the internal name of the class corresponding to this object or array type.
static StringgetInternalName(Class c)
Returns the internal name of the given class.
static StringgetMethodDescriptor(Type returnType, Type[] argumentTypes)
Returns the descriptor corresponding to the given argument and return types.
static StringgetMethodDescriptor(Method m)
Returns the descriptor corresponding to the given method.
static TypegetObjectType(String internalName)
Returns the Java type corresponding to the given internal name.
intgetOpcode(int opcode)
Returns a JVM instruction opcode adapted to this Java type.
static TypegetReturnType(String methodDescriptor)
Returns the Java type corresponding to the return type of the given method descriptor.
static TypegetReturnType(Method method)
Returns the Java type corresponding to the return type of the given method.
intgetSize()
Returns the size of values of this type.
intgetSort()
Returns the sort of this Java type.
static TypegetType(String typeDescriptor)
Returns the Java type corresponding to the given type descriptor.
static TypegetType(Class c)
Returns the Java type corresponding to the given class.
inthashCode()
Returns a hash code value for this type.
StringtoString()
Returns a string representation of this type.

Field Detail

ARRAY

public static final int ARRAY
The sort of array reference types. See getSort.

BOOLEAN

public static final int BOOLEAN
The sort of the boolean type. See getSort.

BOOLEAN_TYPE

public static final Type BOOLEAN_TYPE
The boolean type.

BYTE

public static final int BYTE
The sort of the byte type. See getSort.

BYTE_TYPE

public static final Type BYTE_TYPE
The byte type.

CHAR

public static final int CHAR
The sort of the char type. See getSort.

CHAR_TYPE

public static final Type CHAR_TYPE
The char type.

DOUBLE

public static final int DOUBLE
The sort of the double type. See getSort.

DOUBLE_TYPE

public static final Type DOUBLE_TYPE
The double type.

FLOAT

public static final int FLOAT
The sort of the float type. See getSort.

FLOAT_TYPE

public static final Type FLOAT_TYPE
The float type.

INT

public static final int INT
The sort of the int type. See getSort.

INT_TYPE

public static final Type INT_TYPE
The int type.

LONG

public static final int LONG
The sort of the long type. See getSort.

LONG_TYPE

public static final Type LONG_TYPE
The long type.

OBJECT

public static final int OBJECT
The sort of object reference type. See getSort.

SHORT

public static final int SHORT
The sort of the short type. See getSort.

SHORT_TYPE

public static final Type SHORT_TYPE
The short type.

VOID

public static final int VOID
The sort of the void type. See getSort.

VOID_TYPE

public static final Type VOID_TYPE
The void type.

Method Detail

equals

public boolean equals(Object o)
Tests if the given object is equal to this type.

Parameters: o the object to be compared to this type.

Returns: true if the given object is equal to this type.

getArgumentsAndReturnSizes

public static int getArgumentsAndReturnSizes(String desc)
Computes the size of the arguments and of the return value of a method.

Parameters: desc the descriptor of a method.

Returns: the size of the arguments of the method (plus one for the implicit this argument), argSize, and the size of its return value, retSize, packed into a single int i = (argSize << 2) | retSize (argSize is therefore equal to i >> 2, and retSize to i & 0x03).

getArgumentTypes

public static Type[] getArgumentTypes(String methodDescriptor)
Returns the Java types corresponding to the argument types of the given method descriptor.

Parameters: methodDescriptor a method descriptor.

Returns: the Java types corresponding to the argument types of the given method descriptor.

getArgumentTypes

public static Type[] getArgumentTypes(Method method)
Returns the Java types corresponding to the argument types of the given method.

Parameters: method a method.

Returns: the Java types corresponding to the argument types of the given method.

getClassName

public String getClassName()
Returns the name of the class corresponding to this type.

Returns: the fully qualified name of the class corresponding to this type.

getConstructorDescriptor

public static String getConstructorDescriptor(Constructor c)
Returns the descriptor corresponding to the given constructor.

Parameters: c a Constructor Constructor object.

Returns: the descriptor of the given constructor.

getDescriptor

public String getDescriptor()
Returns the descriptor corresponding to this Java type.

Returns: the descriptor corresponding to this Java type.

getDescriptor

public static String getDescriptor(Class c)
Returns the descriptor corresponding to the given Java type.

Parameters: c an object class, a primitive class or an array class.

Returns: the descriptor corresponding to the given class.

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.

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.

getInternalName

public 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 String getInternalName(Class c)
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: c an object or array class.

Returns: the internal name of the given class.

getMethodDescriptor

public static 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 String getMethodDescriptor(Method m)
Returns the descriptor corresponding to the given method.

Parameters: m a Method Method object.

Returns: the descriptor of the given method.

getObjectType

public static Type getObjectType(String internalName)
Returns the Java type corresponding to the given internal name.

Parameters: internalName an internal name.

Returns: the Java type corresponding to the given internal name.

getOpcode

public int getOpcode(int opcode)
Returns a JVM instruction opcode adapted to this Java type.

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 Java type. For example, if this type is float and opcode is IRETURN, this method returns FRETURN.

getReturnType

public static Type getReturnType(String methodDescriptor)
Returns the Java type corresponding to the return type of the given method descriptor.

Parameters: methodDescriptor a method descriptor.

Returns: the Java type corresponding to the return type of the given method descriptor.

getReturnType

public static Type getReturnType(Method method)
Returns the Java type corresponding to the return type of the given method.

Parameters: method a method.

Returns: the Java type corresponding to the return type of the given method.

getSize

public int getSize()
Returns the size of values of this type.

Returns: the size of values of this type, i.e., 2 for long and double, and 1 otherwise.

getSort

public int getSort()
Returns the sort of this Java type.

Returns: VOID, BOOLEAN, CHAR, BYTE, SHORT, INT, FLOAT, LONG, DOUBLE, ARRAY or OBJECT.

getType

public static Type getType(String typeDescriptor)
Returns the Java type corresponding to the given type descriptor.

Parameters: typeDescriptor a type descriptor.

Returns: the Java type corresponding to the given type descriptor.

getType

public static Type getType(Class c)
Returns the Java type corresponding to the given class.

Parameters: c a class.

Returns: the Java type corresponding to the given class.

hashCode

public int hashCode()
Returns a hash code value for this type.

Returns: a hash code value for this type.

toString

public String toString()
Returns a string representation of this type.

Returns: the descriptor of this type.