Package org.eclipse.sisu.space.asm
Class Type
java.lang.Object
org.eclipse.sisu.space.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 the boolean type.static final Type
The boolean type.private final char[]
A buffer containing the internal name of this Java type.static final int
The sort of the byte type.static final Type
The byte type.static final int
The sort of the char type.static final Type
The char type.static final int
The sort of the double type.static final Type
The double type.static final int
The sort of the float type.static final Type
The float type.static final int
The sort of the int type.static final Type
The int type.private final int
The length of the internal name of this Java type.static final int
The sort of the long type.static final Type
The long type.static final int
The sort of method types.static final int
The sort of object reference types.private final int
The offset of the internal name of this Java type inbuf
or, for primitive types, the size, descriptor and getOpcode offsets for this type (byte 0 contains the size, byte 1 the descriptor, byte 2 the offset for IALOAD or IASTORE, byte 3 the offset for all other instructions).static final int
The sort of the short type.static final Type
The short type.private final int
The sort of this Java type.static final int
The sort of the void type.static final Type
The void type. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Type
(int sort, char[] buf, int off, int len) Constructs a reference type. -
Method Summary
Modifier and TypeMethodDescriptionboolean
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
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 the Java types corresponding to the argument types of the given method.static Type[]
getArgumentTypes
(String methodDescriptor) Returns the Java types corresponding to the argument types of the given method descriptor.Returns the binary name of the class corresponding to this type.static String
Returns the descriptor corresponding to the given constructor.Returns the descriptor corresponding to this Java type.static String
getDescriptor
(Class<?> c) Returns the descriptor corresponding to the given Java type.private void
Appends the descriptor corresponding to this Java type to the given string buffer.private static void
getDescriptor
(StringBuilder buf, Class<?> c) Appends the descriptor of the given class to the given string buffer.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<?> c) Returns the internal name of the given class.static String
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 the Java type corresponding to the given method descriptor.static Type
getMethodType
(Type returnType, Type... argumentTypes) Returns the Java method type corresponding to the given argument and return types.static Type
getObjectType
(String internalName) Returns the Java type corresponding to the given internal name.int
getOpcode
(int opcode) Returns a JVM instruction opcode adapted to this Java type.Returns the return type of methods of this type.static Type
getReturnType
(Method method) Returns the Java type corresponding to the return type of the given method.static Type
getReturnType
(String methodDescriptor) Returns the Java type 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 Java type.private static Type
getType
(char[] buf, int off) Returns the Java type corresponding to the given type descriptor.static Type
Returns the Java type corresponding to the given class.static Type
getType
(Constructor<?> c) Returns the Java method type corresponding to the given constructor.static Type
Returns the Java method type corresponding to the given method.static Type
Returns the Java type corresponding to the given type 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 the void type. SeegetSort
.- See Also:
-
BOOLEAN
public static final int BOOLEANThe sort of the boolean type. SeegetSort
.- See Also:
-
CHAR
public static final int CHARThe sort of the char type. SeegetSort
.- See Also:
-
BYTE
public static final int BYTEThe sort of the byte type. SeegetSort
.- See Also:
-
SHORT
public static final int SHORTThe sort of the short type. SeegetSort
.- See Also:
-
INT
public static final int INTThe sort of the int type. SeegetSort
.- See Also:
-
FLOAT
public static final int FLOATThe sort of the float type. SeegetSort
.- See Also:
-
LONG
public static final int LONGThe sort of the long type. SeegetSort
.- See Also:
-
DOUBLE
public static final int DOUBLEThe sort of the double 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:
-
VOID_TYPE
The void type. -
BOOLEAN_TYPE
The boolean type. -
CHAR_TYPE
The char type. -
BYTE_TYPE
The byte type. -
SHORT_TYPE
The short type. -
INT_TYPE
The int type. -
FLOAT_TYPE
The float type. -
LONG_TYPE
The long type. -
DOUBLE_TYPE
The double type. -
sort
private final int sortThe sort of this Java type. -
buf
private final char[] bufA buffer containing the internal name of this Java type. This field is only used for reference types. -
off
private final int offThe offset of the internal name of this Java type inbuf
or, for primitive types, the size, descriptor and getOpcode offsets for this type (byte 0 contains the size, byte 1 the descriptor, byte 2 the offset for IALOAD or IASTORE, byte 3 the offset for all other instructions). -
len
private final int lenThe length of the internal name of this Java type.
-
-
Constructor Details
-
Type
private Type(int sort, char[] buf, int off, int len) Constructs a reference type.- Parameters:
sort
- the sort of the reference type to be constructed.buf
- a buffer containing the descriptor of the previous type.off
- the offset of this descriptor in the previous buffer.len
- the length of this descriptor.
-
-
Method Details
-
getType
Returns the Java type corresponding to the given type descriptor.- Parameters:
typeDescriptor
- a field or method type descriptor.- Returns:
- the Java type corresponding to the given type descriptor.
-
getObjectType
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.
-
getMethodType
Returns the Java type corresponding to the given method descriptor. Equivalent toType.getType(methodDescriptor)
.- Parameters:
methodDescriptor
- a method descriptor.- Returns:
- the Java type corresponding to the given method descriptor.
-
getMethodType
Returns the Java method type 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 Java type corresponding to the given argument and return types.
-
getType
Returns the Java type corresponding to the given class.- Parameters:
c
- a class.- Returns:
- the Java type corresponding to the given class.
-
getType
Returns the Java method type corresponding to the given constructor.- Parameters:
c
- aConstructor
object.- Returns:
- the Java method type corresponding to the given constructor.
-
getType
Returns the Java method type corresponding to the given method.- Parameters:
m
- aMethod
object.- Returns:
- the Java method type corresponding to the given method.
-
getArgumentTypes
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
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.
-
getReturnType
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
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.
-
getArgumentsAndReturnSizes
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).
-
getType
Returns the Java type corresponding to the given type descriptor. For method descriptors, buf is supposed to contain nothing more than the descriptor itself.- Parameters:
buf
- a buffer containing a type descriptor.off
- the offset of this descriptor in the previous buffer.- Returns:
- the Java type corresponding to the given type descriptor.
-
getSort
public int getSort()Returns the sort of this Java 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.
-
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.
-
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.
-
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.
-
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.
-
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 (plus one for the implicit this argument), argSize, and the size of the return value, retSize, packed into a single int i = (argSize << 2) | retSize (argSize is therefore equal to i >> 2, and retSize to i & 0x03).
-
getDescriptor
Returns the descriptor corresponding to this Java type.- Returns:
- the descriptor corresponding to this Java type.
-
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.
-
getDescriptor
Appends the descriptor corresponding to this Java type to the given string buffer.- Parameters:
buf
- the string buffer to which the descriptor must be appended.
-
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:
c
- an object or array class.- Returns:
- the internal name of the given class.
-
getDescriptor
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.
-
getConstructorDescriptor
Returns the descriptor corresponding to the given constructor.- Parameters:
c
- aConstructor
object.- Returns:
- the descriptor of the given constructor.
-
getMethodDescriptor
Returns the descriptor corresponding to the given method.- Parameters:
m
- aMethod
object.- Returns:
- the descriptor of the given method.
-
getDescriptor
Appends the descriptor of the given class to the given string buffer.- Parameters:
buf
- the string buffer to which the descriptor must be appended.c
- the class whose descriptor must be computed.
-
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 and double, 0 for void and 1 otherwise.
-
getOpcode
public int getOpcode(int opcode) Returns a JVM instruction opcode adapted to this Java type. 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 Java type. For example, if this type is float and opcode 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.
-