Class Type

java.lang.Object
org.apache.bcel.generic.Type
Direct Known Subclasses:
BasicType, DOUBLE_Upper, LONG_Upper, ReferenceType, ReturnaddressType

public abstract class Type extends Object
Abstract superclass for all possible Java types, namely basic types such as int, object types like String and array types, for example int[]
  • Field Details

    • VOID

      public static final BasicType VOID
      Predefined constants
    • BOOLEAN

      public static final BasicType BOOLEAN
      Predefined constant for boolean type.
    • INT

      public static final BasicType INT
      Predefined constant for int type.
    • SHORT

      public static final BasicType SHORT
      Predefined constant for short type.
    • BYTE

      public static final BasicType BYTE
      Predefined constant for byte type.
    • LONG

      public static final BasicType LONG
      Predefined constant for long type.
    • DOUBLE

      public static final BasicType DOUBLE
      Predefined constant for double type.
    • FLOAT

      public static final BasicType FLOAT
      Predefined constant for float type.
    • CHAR

      public static final BasicType CHAR
      Predefined constant for char type.
    • OBJECT

      public static final ObjectType OBJECT
      Predefined constant for Object type.
    • CLASS

      public static final ObjectType CLASS
      Predefined constant for Class type.
    • STRING

      public static final ObjectType STRING
      Predefined constant for String type.
    • STRINGBUFFER

      public static final ObjectType STRINGBUFFER
      Predefined constant for StringBuffer type.
    • THROWABLE

      public static final ObjectType THROWABLE
      Predefined constant for Throwable type.
    • NO_ARGS

      public static final Type[] NO_ARGS
      Empty array.
    • NULL

      public static final ReferenceType NULL
      Predefined constant for null type.
    • UNKNOWN

      public static final Type UNKNOWN
      Predefined constant for unknown type.
    • type

      @Deprecated protected byte type
      Deprecated.
      (since 6.0) will be made private; do not access directly, use getter/setter
    • signature

      Deprecated.
      (since 6.0) will be made private; do not access directly, use getter/setter
  • Constructor Details

    • Type

      protected Type(byte type, String signature)
      Constructs a Type.
      Parameters:
      type - The type constant.
      signature - The type signature.
  • Method Details

    • getArgumentTypes

      public static Type[] getArgumentTypes(String signature)
      Gets the argument types of a method from its signature as an array of Type objects.
      Parameters:
      signature - signature string such as (Ljava/lang/String;)V.
      Returns:
      array of argument types.
    • getMethodSignature

      public static String getMethodSignature(Type returnType, Type[] argTypes)
      Gets the Java method signature for the given types, for example, int[] f(java.lang.String x) becomes (Ljava/lang/String;)[I.
      Parameters:
      returnType - what the method returns.
      argTypes - what are the argument types.
      Returns:
      method signature for given type(s).
    • getReturnType

      public static Type getReturnType(String signature)
      Gets the return type of a method from its signature as a Type object.
      Parameters:
      signature - signature string such as (Ljava/lang/String;)V.
      Returns:
      return type.
    • getSignature

      public static String getSignature(Method meth)
      Gets the signature for a method.
      Parameters:
      meth - The method.
      Returns:
      The method signature.
    • getType

      public static Type getType(Class<?> cls)
      Gets the BCEL Type object corresponding to a runtime Class.
      Parameters:
      cls - Java class.
      Returns:
      corresponding Type object.
    • getType

      public static Type getType(String signature) throws StringIndexOutOfBoundsException
      Gets the Type object corresponding to a signature.
      Parameters:
      signature - signature string such as Ljava/lang/String;.
      Returns:
      type object.
      Throws:
      StringIndexOutOfBoundsException
    • getTypes

      public static Type[] getTypes(Class<?>[] classes)
      Gets the BCEL Type objects corresponding to an array of runtime classes.
      Parameters:
      classes - An array of runtime class objects.
      Returns:
      array of corresponding Type objects.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
      Returns:
      whether the Types are equal.
    • getClassName

      public String getClassName()
      Gets the class name.
      Returns:
      The class name.
    • getSignature

      public String getSignature()
      Gets the signature for this type.
      Returns:
      signature for given type.
    • getSize

      public int getSize()
      Gets the stack size of this type.
      Returns:
      stack size of this type (2 for long and double, 0 for void, 1 otherwise).
    • getType

      public byte getType()
      Gets the type as defined in Constants.
      Returns:
      type as defined in Constants.
    • hashCode

      public int hashCode()
      Gets the hash code of this Type.
      Overrides:
      hashCode in class Object
      Returns:
      hash code of Type.
    • normalizeForStackOrLocal

      boolean, short and char variable are considered as int in the stack or local variable area. Returns INT for BOOLEAN, SHORT or CHAR, otherwise returns the given type.
      Returns:
      The normalized type.
      Since:
      6.0
    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      Type string, for example 'int[]'.