Class Type

  • Direct Known Subclasses:
    MultiArrayType, MultiType

    public class Type
    extends java.lang.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 Type BOGUS
      Represents a non-accessible value.
      static Type BOOLEAN
      Represents the boolean primitive type
      static Type BYTE
      Represents the byte primitive type
      static Type CHAR
      Represents the char primitive type
      static Type CLONEABLE
      Represents the java.lang.Coneable reference type
      static Type DOUBLE
      Represents the double primitive type
      static Type FLOAT
      Represents the float primitive type
      static Type INTEGER
      Represents the integer primitive type
      static Type LONG
      Represents the long primitive type
      static Type OBJECT
      Represents the java.lang.Object reference type
      static 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.
      static Type SERIALIZABLE
      Represents the java.io.Serializable reference type
      static Type SHORT
      Represents the short primitive type
      static Type THROWABLE
      Represents the java.lang.Throwable reference type
      static Type TOP
      A placeholder used by the analyzer for the second word position of a double-word type
      static Type UNINIT
      Represents an unknown, or null type.
      static Type VOID
      Represents the void primitive type
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      static Type get​(CtClass clazz)
      Obtain the Type for a given class.
      Type getComponent()
      Returns the array component if this type is an array.
      CtClass getCtClass()
      Returns the class this type represents.
      int getDimensions()
      Returns the number of dimensions of this array.
      int getSize()
      Gets the word size of this type.
      int hashCode()  
      boolean isArray()
      Returns whether or not this type is an array.
      boolean isAssignableFrom​(Type type)
      Determines whether this type is assignable, to the passed type.
      boolean isReference()
      Returns whether or not this type is a normal java reference, i.e.
      boolean isSpecial()
      Returns whether or not the type is special.
      Type merge​(Type type)
      Finds the common base type, or interface which both this and the specified type can be assigned.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • 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 Detail

      • 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 java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object