类 Type

java.lang.Object
cn.taketoday.bytecode.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.
作者:
Eric Bruneton, Chris Nokleberg
  • 字段详细资料

    • VOID

      public static final int VOID
      The sort of the void type. See getSort().
      另请参阅:
    • BOOLEAN

      public static final int BOOLEAN
      The sort of the boolean type. See getSort().
      另请参阅:
    • CHAR

      public static final int CHAR
      The sort of the char type. See getSort().
      另请参阅:
    • BYTE

      public static final int BYTE
      The sort of the byte type. See getSort().
      另请参阅:
    • SHORT

      public static final int SHORT
      The sort of the short type. See getSort().
      另请参阅:
    • INT

      public static final int INT
      The sort of the int type. See getSort().
      另请参阅:
    • FLOAT

      public static final int FLOAT
      The sort of the float type. See getSort().
      另请参阅:
    • LONG

      public static final int LONG
      The sort of the long type. See getSort().
      另请参阅:
    • DOUBLE

      public static final int DOUBLE
      The sort of the double type. See getSort().
      另请参阅:
    • ARRAY

      public static final int ARRAY
      The sort of array reference types. See getSort().
      另请参阅:
    • OBJECT

      public static final int OBJECT
      The sort of object reference types. See getSort().
      另请参阅:
    • METHOD

      public static final int METHOD
      The sort of method types. See getSort().
      另请参阅:
    • INTERNAL

      private static final int INTERNAL
      The (private) sort of object reference types represented with an internal name.
      另请参阅:
    • PRIMITIVE_DESCRIPTORS

      private static final String PRIMITIVE_DESCRIPTORS
      The descriptors of the primitive types.
      另请参阅:
    • 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.
    • PRIMITIVE_TYPE_DESCRIPTORS

      private static final HashMap<String,String> PRIMITIVE_TYPE_DESCRIPTORS
      The descriptors of the primitive Java types (plus void).
    • TYPE_TYPE

      public static final Type TYPE_TYPE
    • TYPE_CONSTANT

      public static final Type TYPE_CONSTANT
    • TYPE_OBJECT_ARRAY

      public static final Type TYPE_OBJECT_ARRAY
    • TYPE_CLASS_ARRAY

      public static final Type TYPE_CLASS_ARRAY
    • TYPE_STRING_ARRAY

      public static final Type TYPE_STRING_ARRAY
    • TYPE_ERROR

      public static final Type TYPE_ERROR
    • TYPE_SYSTEM

      public static final Type TYPE_SYSTEM
    • TYPE_LONG

      public static final Type TYPE_LONG
    • TYPE_BYTE

      public static final Type TYPE_BYTE
    • TYPE_CLASS

      public static final Type TYPE_CLASS
    • TYPE_FLOAT

      public static final Type TYPE_FLOAT
    • TYPE_SHORT

      public static final Type TYPE_SHORT
    • TYPE_DOUBLE

      public static final Type TYPE_DOUBLE
    • TYPE_STRING

      public static final Type TYPE_STRING
    • TYPE_NUMBER

      public static final Type TYPE_NUMBER
    • TYPE_BOOLEAN

      public static final Type TYPE_BOOLEAN
    • TYPE_INTEGER

      public static final Type TYPE_INTEGER
    • TYPE_CHARACTER

      public static final Type TYPE_CHARACTER
    • TYPE_THROWABLE

      public static final Type TYPE_THROWABLE
    • TYPE_CLASS_LOADER

      public static final Type TYPE_CLASS_LOADER
    • TYPE_STRING_BUFFER

      public static final Type TYPE_STRING_BUFFER
    • TYPE_RUNTIME_EXCEPTION

      public static final Type TYPE_RUNTIME_EXCEPTION
    • TYPE_SIGNATURE

      public static final Type TYPE_SIGNATURE
    • TYPE_OBJECT

      public static final Type TYPE_OBJECT
      The type of the java.lang.Object class.
    • EMPTY_ARRAY

      public static final Type[] EMPTY_ARRAY
    • 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.
  • 构造器详细资料

    • Type

      private Type(int sort, String valueBuffer, int valueBegin, int valueEnd)
      Constructs a reference type.
      参数:
      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.
  • 方法详细资料

    • parse

      public static Type parse(String s)
      从以下版本开始:
      4.0
    • resolvePrimitiveTypeDescriptor

      @Nullable public static String resolvePrimitiveTypeDescriptor(String type)
      从以下版本开始:
      4.0
    • fromDescriptor

      public static Type fromDescriptor(String typeDescriptor)
      Returns the Type corresponding to the given type descriptor.
      参数:
      typeDescriptor - a field or method type descriptor.
      返回:
      the Type corresponding to the given type descriptor.
    • fromClass

      public static Type fromClass(Class<?> clazz)
      Returns the Type corresponding to the given class.
      参数:
      clazz - a class.
      返回:
      the Type corresponding to the given class.
    • fromConstructor

      public static Type fromConstructor(Constructor<?> constructor)
      Returns the method Type corresponding to the given constructor.
      参数:
      constructor - a Constructor object.
      返回:
      the method Type corresponding to the given constructor.
    • fromMethod

      public static Type fromMethod(Method method)
      Returns the method Type corresponding to the given method.
      参数:
      method - a Method object.
      返回:
      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 the type of the elements of this array type.
    • fromInternalName

      public static Type fromInternalName(String internalName)
      Returns the Type corresponding to the given internal name.
      参数:
      internalName - an internal name.
      返回:
      the Type corresponding to the given internal name.
    • fromInternalNames

      public static Type[] fromInternalNames(String[] names)
      从以下版本开始:
      4.0
    • getObjectTypes

      public static Type[] getObjectTypes(String[] internalNames)
      Returns the Types corresponding to the given internal name.
      参数:
      internalNames - internal name. if null returns null
      返回:
      the Types corresponding to the given internal name.
    • getExceptionTypes

      public static Type[] getExceptionTypes(Member member)
      参数:
      member - Member
      返回:
      the Types corresponding to the given Executable's ExceptionTypes.
      抛出:
      IllegalArgumentException - not a Executable
      从以下版本开始:
      4.0
      另请参阅:
    • fromMethod

      public static Type fromMethod(String methodDescriptor)
      Returns the Type corresponding to the given method descriptor. Equivalent to Type.getType(methodDescriptor).
      参数:
      methodDescriptor - a method descriptor.
      返回:
      the Type corresponding to the given method descriptor.
    • fromMethod

      public static Type fromMethod(Type returnType, Type... argumentTypes)
      Returns the method Type corresponding to the given argument and return types.
      参数:
      returnType - the return type of the method.
      argumentTypes - the argument types of the method.
      返回:
      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.
      返回:
      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.
      参数:
      methodDescriptor - a method descriptor.
      返回:
      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.
      参数:
      method - a method.
      返回:
      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.
      返回:
      the return type of methods of this type.
    • forReturnType

      public static Type forReturnType(String methodDescriptor)
      Returns the Type corresponding to the return type of the given method descriptor.
      参数:
      methodDescriptor - a method descriptor.
      返回:
      the Type corresponding to the return type of the given method descriptor.
    • forReturnType

      public static Type forReturnType(Method method)
      Returns the Type corresponding to the return type of the given method.
      参数:
      method - a method.
      返回:
      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.
      参数:
      methodDescriptor - a method descriptor.
      返回:
      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.
      参数:
      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.
      返回:
      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.
      返回:
      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.
      返回:
      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 '/'.
      参数:
      clazz - an object or array class.
      返回:
      the internal name of the given class.
    • getDescriptor

      public String getDescriptor()
      Returns the descriptor corresponding to this type.
      返回:
      the descriptor corresponding to this type.
    • getDescriptor

      public static String getDescriptor(Class<?> clazz)
      Returns the descriptor corresponding to the given class.
      参数:
      clazz - an object class, a primitive class or an array class.
      返回:
      the descriptor corresponding to the given class.
    • getConstructorDescriptor

      public static String getConstructorDescriptor(Constructor<?> constructor)
      Returns the descriptor corresponding to the given constructor.
      参数:
      constructor - a Constructor object.
      返回:
      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.
      参数:
      returnType - the return type of the method.
      argumentTypes - the argument types of the method.
      返回:
      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.
      参数:
      method - a Method object.
      返回:
      the descriptor of the given method.
    • getDescriptor

      public static String getDescriptor(String parameterTypes)
        Object -> Ljava/lang/Object;
        Object, Object ,Class -> Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Class;
       
      从以下版本开始:
      4.0
    • getDescriptor

      @NonNull public static String getDescriptor(String parameterTypes, int startIdx, int endIdx, boolean defaultPackage)
        Object -> Ljava/lang/Object;
        Object, Object ,Class -> Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Class;
       
    • getDescriptor

      public static String getDescriptor(String type, boolean defaultPackage)
      Returns the descriptor corresponding to the given type name.
      参数:
      type - a Java type name.
      defaultPackage - true if unqualified class names belong to the default package, or false if they correspond to java.lang classes. For instance "Object" means "Object" if this option is true, or "java.lang.Object" otherwise.
      返回:
      the descriptor corresponding to the given type name.
    • appendDescriptor

      private void appendDescriptor(StringBuilder stringBuilder)
      Appends the descriptor corresponding to this type to the given string buffer.
      参数:
      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.
      参数:
      clazz - the class whose descriptor must be computed.
      stringBuilder - the string builder to which the descriptor must be appended.
    • getComponentType

      public Type getComponentType()
      从以下版本开始:
      4.0
    • emulateClassGetName

      public String emulateClassGetName()
      从以下版本开始:
      4.0
    • toInternalNames

      public static String[] toInternalNames(Type... types)
      从以下版本开始:
      4.0
    • getBoxedType

      public Type getBoxedType()
      get Boxed Type
      返回:
      Boxed Type
      从以下版本开始:
      4.0
    • getUnboxedType

      public Type getUnboxedType()
      从以下版本开始:
      4.0
    • getSort

      public int getSort()
      Returns the sort of this type.
      返回:
      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.
      返回:
      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.
      返回:
      the size of values of this type, i.e., 2 for long and double, 0 for void 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.
      返回:
      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).
    • getArgumentsAndReturnSizes

      public static int getArgumentsAndReturnSizes(String methodDescriptor)
      Computes the size of the arguments and of the return value of a method.
      参数:
      methodDescriptor - a method descriptor.
      返回:
      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).
    • getOpcode

      public int getOpcode(int opcode)
      Returns a JVM instruction opcode adapted to this Type. This method must not be used for method types.
      参数:
      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.
      返回:
      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.
    • array

      public static Type[] array(Type... items)
      To Type array
      参数:
      items - array item
      返回:
      Type array
    • getTypes

      public static Type[] getTypes(@Nullable Class<?>... items)
      从以下版本开始:
      4.0
    • getTypes

      public static Type[] getTypes(String... items)
      从以下版本开始:
      4.0
    • getStackSize

      public static int getStackSize(Type[] types)
      从以下版本开始:
      4.0
    • isArray

      public boolean isArray()
      Determines if this Type object represents an array class.
      返回:
      true if this object represents an array class; false otherwise.
      从以下版本开始:
      4.0
    • isPrimitive

      public boolean isPrimitive()
      Determines if the specified Type object represents a primitive type.

      There are nine predefined Class objects to represent the eight primitive types and void. These are created by the Java Virtual Machine, and have the same names as the primitive types that they represent, namely boolean, byte, char, short, int, long, float, and double.

      These objects may only be accessed via the following public static final variables, and are the only Class objects for which this method returns true.

      返回:
      true if and only if this class represents a primitive type
      从以下版本开始:
      4.0
      另请参阅:
    • equals

      public boolean equals(Object object)
      Tests if the given object is equal to this type.
      覆盖:
      equals 在类中 Object
      参数:
      object - the object to be compared to this type.
      返回:
      true if the given object is equal to this type.
    • hashCode

      public int hashCode()
      Returns a hash code value for this type.
      覆盖:
      hashCode 在类中 Object
      返回:
      a hash code value for this type.
    • toString

      public String toString()
      Returns a string representation of this type.
      覆盖:
      toString 在类中 Object
      返回:
      the descriptor of this type.
    • add

      public static Type[] add(Type[] types, Type extra)
    • add

      public static Type[] add(Type[] types, Type extra, boolean justAdd)
    • add

      public static Type[] add(Type[] t1, Type... t2)