Package org.eclipse.sisu.space.asm
Class Type
- java.lang.Object
-
- org.eclipse.sisu.space.asm.Type
-
public final class Type extends java.lang.ObjectA Java field or method type. This class can be used to make it easier to manipulate type and method descriptors.- Author:
- Eric Bruneton, Chris Nokleberg
-
-
Field Summary
Fields Modifier and Type Field Description static intARRAYThe sort of array reference types.static intBOOLEANThe sort of thebooleantype.static TypeBOOLEAN_TYPEThebooleantype.static intBYTEThe sort of thebytetype.static TypeBYTE_TYPEThebytetype.static intCHARThe sort of thechartype.static TypeCHAR_TYPEThechartype.static intDOUBLEThe sort of thedoubletype.static TypeDOUBLE_TYPEThedoubletype.static intFLOATThe sort of thefloattype.static TypeFLOAT_TYPEThefloattype.static intINTThe sort of theinttype.static TypeINT_TYPETheinttype.static intLONGThe sort of thelongtype.static TypeLONG_TYPEThelongtype.static intMETHODThe sort of method types.static intOBJECTThe sort of object reference types.static intSHORTThe sort of theshorttype.static TypeSHORT_TYPETheshorttype.static intVOIDThe sort of thevoidtype.static TypeVOID_TYPEThevoidtype.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object object)Tests if the given object is equal to this type.intgetArgumentCount()Returns the number of arguments of this method type.static intgetArgumentCount(java.lang.String methodDescriptor)Returns the number of arguments in the given method descriptor.intgetArgumentsAndReturnSizes()Returns the size of the arguments and of the return value of methods of this type.static intgetArgumentsAndReturnSizes(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 theTypevalues corresponding to the argument types of the given method.static Type[]getArgumentTypes(java.lang.String methodDescriptor)Returns theTypevalues corresponding to the argument types of the given method descriptor.java.lang.StringgetClassName()Returns the binary name of the class corresponding to this type.static java.lang.StringgetConstructorDescriptor(java.lang.reflect.Constructor<?> constructor)Returns the descriptor corresponding to the given constructor.java.lang.StringgetDescriptor()Returns the descriptor corresponding to this type.static java.lang.StringgetDescriptor(java.lang.Class<?> clazz)Returns the descriptor corresponding to the given class.intgetDimensions()Returns the number of dimensions of this array type.TypegetElementType()Returns the type of the elements of this array type.java.lang.StringgetInternalName()Returns the internal name of the class corresponding to this object or array type.static java.lang.StringgetInternalName(java.lang.Class<?> clazz)Returns the internal name of the given class.static java.lang.StringgetMethodDescriptor(java.lang.reflect.Method method)Returns the descriptor corresponding to the given method.static java.lang.StringgetMethodDescriptor(Type returnType, Type... argumentTypes)Returns the descriptor corresponding to the given argument and return types.static TypegetMethodType(java.lang.String methodDescriptor)Returns theTypecorresponding to the given method descriptor.static TypegetMethodType(Type returnType, Type... argumentTypes)Returns the methodTypecorresponding to the given argument and return types.static TypegetObjectType(java.lang.String internalName)Returns theTypecorresponding to the given internal name.intgetOpcode(int opcode)Returns a JVM instruction opcode adapted to thisType.TypegetReturnType()Returns the return type of methods of this type.static TypegetReturnType(java.lang.reflect.Method method)Returns theTypecorresponding to the return type of the given method.static TypegetReturnType(java.lang.String methodDescriptor)Returns theTypecorresponding to the return type of the given method descriptor.intgetSize()Returns the size of values of this type.intgetSort()Returns the sort of this type.static TypegetType(java.lang.Class<?> clazz)Returns theTypecorresponding to the given class.static TypegetType(java.lang.reflect.Constructor<?> constructor)Returns the methodTypecorresponding to the given constructor.static TypegetType(java.lang.reflect.Method method)Returns the methodTypecorresponding to the given method.static TypegetType(java.lang.String typeDescriptor)Returns theTypecorresponding to the given type descriptor.inthashCode()Returns a hash code value for this type.java.lang.StringtoString()Returns a string representation of this type.
-
-
-
Field Detail
-
VOID
public static final int VOID
The sort of thevoidtype. SeegetSort().- See Also:
- Constant Field Values
-
BOOLEAN
public static final int BOOLEAN
The sort of thebooleantype. SeegetSort().- See Also:
- Constant Field Values
-
CHAR
public static final int CHAR
The sort of thechartype. SeegetSort().- See Also:
- Constant Field Values
-
BYTE
public static final int BYTE
The sort of thebytetype. SeegetSort().- See Also:
- Constant Field Values
-
SHORT
public static final int SHORT
The sort of theshorttype. SeegetSort().- See Also:
- Constant Field Values
-
INT
public static final int INT
The sort of theinttype. SeegetSort().- See Also:
- Constant Field Values
-
FLOAT
public static final int FLOAT
The sort of thefloattype. SeegetSort().- See Also:
- Constant Field Values
-
LONG
public static final int LONG
The sort of thelongtype. SeegetSort().- See Also:
- Constant Field Values
-
DOUBLE
public static final int DOUBLE
The sort of thedoubletype. 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
Thevoidtype.
-
BOOLEAN_TYPE
public static final Type BOOLEAN_TYPE
Thebooleantype.
-
CHAR_TYPE
public static final Type CHAR_TYPE
Thechartype.
-
BYTE_TYPE
public static final Type BYTE_TYPE
Thebytetype.
-
SHORT_TYPE
public static final Type SHORT_TYPE
Theshorttype.
-
INT_TYPE
public static final Type INT_TYPE
Theinttype.
-
FLOAT_TYPE
public static final Type FLOAT_TYPE
Thefloattype.
-
LONG_TYPE
public static final Type LONG_TYPE
Thelongtype.
-
DOUBLE_TYPE
public static final Type DOUBLE_TYPE
Thedoubletype.
-
-
Method Detail
-
getType
public static Type getType(java.lang.String typeDescriptor)
Returns theTypecorresponding to the given type descriptor.- Parameters:
typeDescriptor- a field or method type descriptor.- Returns:
- the
Typecorresponding to the given type descriptor.
-
getType
public static Type getType(java.lang.Class<?> clazz)
Returns theTypecorresponding to the given class.- Parameters:
clazz- a class.- Returns:
- the
Typecorresponding to the given class.
-
getType
public static Type getType(java.lang.reflect.Constructor<?> constructor)
Returns the methodTypecorresponding to the given constructor.- Parameters:
constructor- aConstructorobject.- Returns:
- the method
Typecorresponding to the given constructor.
-
getType
public static Type getType(java.lang.reflect.Method method)
Returns the methodTypecorresponding to the given method.- Parameters:
method- aMethodobject.- Returns:
- the method
Typecorresponding 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 theTypecorresponding to the given internal name.- Parameters:
internalName- an internal name (seegetInternalName()).- Returns:
- the
Typecorresponding to the given internal name.
-
getMethodType
public static Type getMethodType(java.lang.String methodDescriptor)
Returns theTypecorresponding to the given method descriptor. Equivalent toType.getType(methodDescriptor).- Parameters:
methodDescriptor- a method descriptor.- Returns:
- the
Typecorresponding to the given method descriptor.
-
getMethodType
public static Type getMethodType(Type returnType, Type... argumentTypes)
Returns the methodTypecorresponding 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
Typecorresponding 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 theTypevalues corresponding to the argument types of the given method descriptor.- Parameters:
methodDescriptor- a method descriptor.- Returns:
- the
Typevalues corresponding to the argument types of the given method descriptor.
-
getArgumentTypes
public static Type[] getArgumentTypes(java.lang.reflect.Method method)
Returns theTypevalues corresponding to the argument types of the given method.- Parameters:
method- a method.- Returns:
- the
Typevalues 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 theTypecorresponding to the return type of the given method descriptor.- Parameters:
methodDescriptor- a method descriptor.- Returns:
- the
Typecorresponding to the return type of the given method descriptor.
-
getReturnType
public static Type getReturnType(java.lang.reflect.Method method)
Returns theTypecorresponding to the return type of the given method.- Parameters:
method- a method.- Returns:
- the
Typecorresponding 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- aConstructorobject.- 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- aMethodobject.- 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
longanddouble, 0 forvoidand 1 otherwise.
-
getArgumentCount
public int getArgumentCount()
Returns the number of arguments of this method type. This method should only be used for method types.- Returns:
- the number of arguments of this method type. Each argument counts for 1, even long and double ones. The implicit @literal{this} argument is not counted.
-
getArgumentCount
public static int getArgumentCount(java.lang.String methodDescriptor)
Returns the number of arguments in the given method descriptor.- Parameters:
methodDescriptor- a method descriptor.- Returns:
- the number of arguments in the given method descriptor. Each argument counts for 1, even long and double ones. The implicit @literal{this} argument is not counted.
-
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). Long and double values have size 2, the others have size 1.
-
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). Long and double values have size 2, the others have size 1.
-
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 isfloatandopcodeis IRETURN, this method returns FRETURN.
-
equals
public boolean equals(java.lang.Object object)
Tests if the given object is equal to this type.- Overrides:
equalsin 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:
hashCodein 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:
toStringin classjava.lang.Object- Returns:
- the descriptor of this type.
-
-