Class Type

java.lang.Object
javassist.bytecode.analysis.Type
Direct Known Subclasses:
MultiArrayType, MultiType

public class Type extends Object
Represents a JVM type in data-flow analysis. This abstraction is necessary since a JVM type not only includes all normal Java types, but also a few special types that are used by the JVM internally. See the static field types on this class for more info on these special types. All primitive and special types reuse the same instance, so identity comparison can be used when examining them. Normal java types must use equals(Object) to compare type instances. In most cases, applications which consume this API, only need to call getCtClass() to obtain the needed type information.
Author:
Jason T. Greene
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Type
    Represents a non-accessible value.
    static final Type
    Represents the boolean primitive type
    static final Type
    Represents the byte primitive type
    static final Type
    Represents the char primitive type
    static final Type
    Represents the java.lang.Coneable reference type
    static final Type
    Represents the double primitive type
    static final Type
    Represents the float primitive type
    static final Type
    Represents the integer primitive type
    static final Type
    Represents the long primitive type
    static final Type
    Represents the java.lang.Object reference type
    static final Type
    Represents an internal JVM return address, which is used by the RET instruction to return to a JSR that invoked the subroutine.
    static final Type
    Represents the java.io.Serializable reference type
    static final Type
    Represents the short primitive type
    static final Type
    Represents the java.lang.Throwable reference type
    static final Type
    A placeholder used by the analyzer for the second word position of a double-word type
    static final Type
    Represents an unknown, or null type.
    static final Type
    Represents the void primitive type
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
     
    static Type
    get(CtClass clazz)
    Obtain the Type for a given class.
    Returns the array component if this type is an array.
    Returns the class this type represents.
    int
    Returns the number of dimensions of this array.
    int
    Gets the word size of this type.
    int
     
    boolean
    Returns whether or not this type is an array.
    boolean
    Determines whether this type is assignable, to the passed type.
    boolean
    Returns whether or not this type is a normal java reference, i.e.
    boolean
    Returns whether or not the type is special.
    merge(Type type)
    Finds the common base type, or interface which both this and the specified type can be assigned.
     

    Methods inherited from class java.lang.Object

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

    • DOUBLE

      public static final Type DOUBLE
      Represents the double primitive type
    • BOOLEAN

      public static final Type BOOLEAN
      Represents the boolean primitive type
    • LONG

      public static final Type LONG
      Represents the long primitive type
    • CHAR

      public static final Type CHAR
      Represents the char primitive type
    • BYTE

      public static final Type BYTE
      Represents the byte primitive type
    • SHORT

      public static final Type SHORT
      Represents the short primitive type
    • INTEGER

      public static final Type INTEGER
      Represents the integer primitive type
    • FLOAT

      public static final Type FLOAT
      Represents the float primitive type
    • VOID

      public static final Type VOID
      Represents the void primitive type
    • UNINIT

      public static final Type UNINIT
      Represents an unknown, or null type. This occurs when aconst_null is used. It is important not to treat this type as java.lang.Object, since a null can be assigned to any reference type. The analyzer will replace these with an actual known type if it can be determined by a merged path with known type information. If this type is encountered on a frame then it is guaranteed to be null, and the type information is simply not available. Any attempts to infer the type, without further information from the compiler would be a guess.
    • RETURN_ADDRESS

      public static final Type RETURN_ADDRESS
      Represents an internal JVM return address, which is used by the RET instruction to return to a JSR that invoked the subroutine.
    • TOP

      public static final Type TOP
      A placeholder used by the analyzer for the second word position of a double-word type
    • BOGUS

      public static final Type BOGUS
      Represents a non-accessible value. Code cannot access the value this type represents. It occurs when bytecode reuses a local variable table position with non-mergable types. An example would be compiled code which uses the same position for a primitive type in one branch, and a reference type in another branch.
    • OBJECT

      public static final Type OBJECT
      Represents the java.lang.Object reference type
    • SERIALIZABLE

      public static final Type SERIALIZABLE
      Represents the java.io.Serializable reference type
    • CLONEABLE

      public static final Type CLONEABLE
      Represents the java.lang.Coneable reference type
    • THROWABLE

      public static final Type THROWABLE
      Represents the java.lang.Throwable reference type
  • Method Details

    • get

      public static Type get(CtClass clazz)
      Obtain the Type for a given class. If the class is a primitive, the the unique type instance for the primitive will be returned. Otherwise a new Type instance representing the class is returned.
      Parameters:
      clazz - The java class
      Returns:
      a type instance for this class
    • getSize

      public int getSize()
      Gets the word size of this type. Double-word types, such as long and double will occupy two positions on the local variable table or stack.
      Returns:
      the number of words needed to hold this type
    • getCtClass

      public CtClass getCtClass()
      Returns the class this type represents. If the type is special, null will be returned.
      Returns:
      the class for this type, or null if special
    • isReference

      public boolean isReference()
      Returns whether or not this type is a normal java reference, i.e. it is or extends java.lang.Object.
      Returns:
      true if a java reference, false if a primitive or special
    • isSpecial

      public boolean isSpecial()
      Returns whether or not the type is special. A special type is one that is either used for internal tracking, or is only used internally by the JVM.
      Returns:
      true if special, false if not
    • isArray

      public boolean isArray()
      Returns whether or not this type is an array.
      Returns:
      true if an array, false if not
    • getDimensions

      public int getDimensions()
      Returns the number of dimensions of this array. If the type is not an array zero is returned.
      Returns:
      zero if not an array, otherwise the number of array dimensions.
    • getComponent

      public Type getComponent()
      Returns the array component if this type is an array. If the type is not an array null is returned.
      Returns:
      the array component if an array, otherwise null
    • isAssignableFrom

      public boolean isAssignableFrom(Type type)
      Determines whether this type is assignable, to the passed type. A type is assignable to another if it is either the same type, or a sub-type.
      Parameters:
      type - the type to test assignability to
      Returns:
      true if this is assignable to type, otherwise false
    • merge

      public Type merge(Type type)
      Finds the common base type, or interface which both this and the specified type can be assigned. If there is more than one possible answer, then a MultiType, or a MultiArrayType is returned. Multi-types have special rules, and successive merges and assignment tests on them will alter their internal state, as well as other multi-types they have been merged with. This method is used by the data-flow analyzer to merge the type state from multiple branches.
      Parameters:
      type - the type to merge with
      Returns:
      the merged type
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object