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

      • clazz

        private final CtClass clazz
      • special

        private final boolean special
      • prims

        private static final java.util.Map<CtClass,​Type> prims
      • 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
    • Constructor Detail

      • Type

        private Type​(CtClass clazz,
                     boolean special)
    • 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
      • lookupType

        private static Type lookupType​(java.lang.String name)
      • popChanged

        boolean popChanged()
      • 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
      • getRootComponent

        Type getRootComponent​(Type type)
      • createArray

        private Type createArray​(Type rootComponent,
                                 int dims)
      • arrayName

        java.lang.String arrayName​(java.lang.String component,
                                   int dims)
      • getClassPool

        private ClassPool getClassPool​(Type rootComponent)
      • mergeArray

        private Type mergeArray​(Type type)
      • findCommonInterfaces

        private java.util.Map<java.lang.String,​CtClass> findCommonInterfaces​(Type type)
      • findExclusiveDeclaredInterfaces

        private java.util.Map<java.lang.String,​CtClass> findExclusiveDeclaredInterfaces​(Type type,
                                                                                              CtClass exclude)
      • findCommonInterfaces

        java.util.Map<java.lang.String,​CtClass> findCommonInterfaces​(java.util.Map<java.lang.String,​CtClass> typeMap,
                                                                           java.util.Map<java.lang.String,​CtClass> alterMap)
      • getAllInterfaces

        java.util.Map<java.lang.String,​CtClass> getAllInterfaces​(CtClass clazz,
                                                                       java.util.Map<java.lang.String,​CtClass> map)
      • getDeclaredInterfaces

        java.util.Map<java.lang.String,​CtClass> getDeclaredInterfaces​(CtClass clazz,
                                                                            java.util.Map<java.lang.String,​CtClass> map)
      • 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