Class Type

java.lang.Object
org.objectweb.asm.Type

public final class Type extends 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 final int
    The sort of array reference types.
    static final int
    The sort of the boolean type.
    static final Type
    The boolean 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 static final int
    The (private) sort of object reference types represented with an internal name.
    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 static final String
    The descriptors of the primitive types.
    static final int
    The sort of the short type.
    static final Type
    The short 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 in valueBuffer.
    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 in valueBuffer.
    static final int
    The sort of the void type.
    static final Type
    The void type.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Type(int sort, String valueBuffer, int valueBegin, int valueEnd)
    Constructs a reference type.
  • Method Summary

    Modifier and Type
    Method
    Description
    private static void
    appendDescriptor(Class<?> clazz, StringBuilder stringBuilder)
    Appends the descriptor of the given class to the given string builder.
    private void
    Appends the descriptor corresponding to this type to the given string buffer.
    boolean
    equals(Object object)
    Tests if the given object is equal to this type.
    int
    Returns the number of arguments of this method type.
    static int
    getArgumentCount(String methodDescriptor)
    Returns the number of arguments in the given method descriptor.
    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.
    Returns the argument types of methods of this type.
    static Type[]
    Returns the Type values corresponding to the argument types of the given method.
    static Type[]
    getArgumentTypes(String methodDescriptor)
    Returns the Type values 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 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
    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 Type corresponding to the given method descriptor.
    static Type
    getMethodType(Type returnType, Type... argumentTypes)
    Returns the method Type corresponding to the given argument and return types.
    static Type
    getObjectType(String internalName)
    Returns the Type corresponding to the given internal name.
    int
    getOpcode(int opcode)
    Returns a JVM instruction opcode adapted to this Type.
    Returns the return type of methods of this type.
    static Type
    Returns the Type corresponding to the return type of the given method.
    static Type
    getReturnType(String methodDescriptor)
    Returns the Type 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
    Returns the size of values of this type.
    int
    Returns the sort of this type.
    static Type
    getType(Class<?> clazz)
    Returns the Type corresponding to the given class.
    static Type
    getType(Constructor<?> constructor)
    Returns the method Type corresponding to the given constructor.
    static Type
    getType(Method method)
    Returns the method Type corresponding to the given method.
    static Type
    getType(String typeDescriptor)
    Returns the Type corresponding to the given type descriptor.
    private static Type
    getTypeInternal(String descriptorBuffer, int descriptorBegin, int descriptorEnd)
    Returns the Type corresponding to the given field or method descriptor.
    int
    Returns a hash code value for this type.
    Returns a string representation of this type.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • VOID

      public static final int VOID
      The sort of the void type. See getSort().
      See Also:
    • BOOLEAN

      public static final int BOOLEAN
      The sort of the boolean type. See getSort().
      See Also:
    • CHAR

      public static final int CHAR
      The sort of the char type. See getSort().
      See Also:
    • BYTE

      public static final int BYTE
      The sort of the byte type. See getSort().
      See Also:
    • SHORT

      public static final int SHORT
      The sort of the short type. See getSort().
      See Also:
    • INT

      public static final int INT
      The sort of the int type. See getSort().
      See Also:
    • FLOAT

      public static final int FLOAT
      The sort of the float type. See getSort().
      See Also:
    • LONG

      public static final int LONG
      The sort of the long type. See getSort().
      See Also:
    • DOUBLE

      public static final int DOUBLE
      The sort of the double type. See getSort().
      See Also:
    • ARRAY

      public static final int ARRAY
      The sort of array reference types. See getSort().
      See Also:
    • OBJECT

      public static final int OBJECT
      The sort of object reference types. See getSort().
      See Also:
    • METHOD

      public static final int METHOD
      The sort of method types. See getSort().
      See Also:
    • INTERNAL

      private static final int INTERNAL
      The (private) sort of object reference types represented with an internal name.
      See Also:
    • PRIMITIVE_DESCRIPTORS

      private static final String PRIMITIVE_DESCRIPTORS
      The descriptors of the primitive types.
      See Also:
    • VOID_TYPE

      public static final Type VOID_TYPE
      The void type.
    • BOOLEAN_TYPE

      public static final Type BOOLEAN_TYPE
      The boolean type.
    • CHAR_TYPE

      public static final Type CHAR_TYPE
      The char type.
    • BYTE_TYPE

      public static final Type BYTE_TYPE
      The byte type.
    • SHORT_TYPE

      public static final Type SHORT_TYPE
      The short type.
    • INT_TYPE

      public static final Type INT_TYPE
      The int type.
    • FLOAT_TYPE

      public static final Type FLOAT_TYPE
      The float type.
    • LONG_TYPE

      public static final Type LONG_TYPE
      The long type.
    • DOUBLE_TYPE

      public static final Type DOUBLE_TYPE
      The double type.
    • sort

      private final int sort
      The sort of this type. Either VOID, BOOLEAN, CHAR, BYTE, SHORT, INT, FLOAT, LONG, DOUBLE, ARRAY, OBJECT, METHOD or INTERNAL.
    • valueBuffer

      private final String valueBuffer
      A buffer containing the value of this field or method type. This value is an internal name for OBJECT and INTERNAL 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 valueBegin
      The beginning index, inclusive, of the value of this Java field or method type in valueBuffer. This value is an internal name for OBJECT and INTERNAL types, and a field or method descriptor in the other cases.
    • valueEnd

      private final int valueEnd
      The end index, exclusive, of the value of this Java field or method type in valueBuffer. This value is an internal name for OBJECT and INTERNAL types, and a field or method descriptor in the other cases.
  • Constructor Details

    • Type

      private Type(int sort, String valueBuffer, int valueBegin, int valueEnd)
      Constructs a reference type.
      Parameters:
      sort - the sort of this type, see sort.
      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

      public static Type getType(String typeDescriptor)
      Returns the Type 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(Class<?> clazz)
      Returns the Type corresponding to the given class.
      Parameters:
      clazz - a class.
      Returns:
      the Type corresponding to the given class.
    • getType

      public static Type getType(Constructor<?> constructor)
      Returns the method Type corresponding to the given constructor.
      Parameters:
      constructor - a Constructor object.
      Returns:
      the method Type corresponding to the given constructor.
    • getType

      public static Type getType(Method method)
      Returns the method Type corresponding to the given method.
      Parameters:
      method - a Method 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(String internalName)
      Returns the Type corresponding to the given internal name.
      Parameters:
      internalName - an internal name (see getInternalName()).
      Returns:
      the Type corresponding to the given internal name.
    • getMethodType

      public static Type getMethodType(String methodDescriptor)
      Returns the Type corresponding to the given method descriptor. Equivalent to Type.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 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 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(String methodDescriptor)
      Returns the Type 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(Method method)
      Returns the Type 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(String methodDescriptor)
      Returns the Type 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(Method method)
      Returns the Type 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

      static int getReturnTypeOffset(String methodDescriptor)
      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 the Type 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

      public 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 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<?> 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 String getDescriptor()
      Returns the descriptor corresponding to this type.
      Returns:
      the descriptor corresponding to this type.
    • getDescriptor

      public static String getDescriptor(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 String getConstructorDescriptor(Constructor<?> constructor)
      Returns the descriptor corresponding to the given constructor.
      Parameters:
      constructor - a Constructor object.
      Returns:
      the descriptor of the given constructor.
    • 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 method)
      Returns the descriptor corresponding to the given method.
      Parameters:
      method - a Method object.
      Returns:
      the descriptor of the given method.
    • appendDescriptor

      private void appendDescriptor(StringBuilder stringBuilder)
      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

      private static void appendDescriptor(Class<?> clazz, StringBuilder stringBuilder)
      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.
      Returns:
      VOID, BOOLEAN, CHAR, BYTE, SHORT, INT, FLOAT, LONG, DOUBLE, ARRAY, OBJECT or METHOD.
    • 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 and double, 0 for void and 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(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 &lt;&lt; 2) | returnSize (argumentsSize is therefore equal to i &gt;&gt; 2, and returnSize to i &amp; 0x03). Long and double values have size 2, the others have size 1.
    • getArgumentsAndReturnSizes

      public static int getArgumentsAndReturnSizes(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 &lt;&lt; 2) | returnSize (argumentsSize is therefore equal to i &gt;&gt; 2, and returnSize to i &amp; 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 this 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 Type. For example, if this type is float and opcode is IRETURN, this method returns FRETURN.
    • equals

      public boolean equals(Object object)
      Tests if the given object is equal to this type.
      Overrides:
      equals in class 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 class Object
      Returns:
      a hash code value for this type.
    • toString

      public String toString()
      Returns a string representation of this type.
      Overrides:
      toString in class Object
      Returns:
      the descriptor of this type.