Top Description Fields Constructors Methods
javassist.bytecode.analysis

public Class Type

extends Object
Class Inheritance
Known Direct Subclasses
javassist.bytecode.analysis.MultiArrayType, javassist.bytecode.analysis.MultiType
Imports
java.util.*, javassist.ClassPool, .CtClass, .NotFoundException

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

Modifier and TypeField and Description
public static final Type
BOGUS

Represents a non-accessible value.

public static final Type
BOOLEAN

Represents the boolean primitive type

public static final Type
BYTE

Represents the byte primitive type

public static final Type
CHAR

Represents the char primitive type

private final CtClass
public static final Type
CLONEABLE

Represents the java.lang.Coneable reference type

public static final Type
DOUBLE

Represents the double primitive type

public static final Type
FLOAT

Represents the float primitive type

public static final Type
INTEGER

Represents the integer primitive type

public static final Type
LONG

Represents the long primitive type

public static final Type
OBJECT

Represents the java.lang.Object reference type

private static final Map<CtClass, Type>
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.

public static final Type
SERIALIZABLE

Represents the java.io.Serializable reference type

public static final Type
SHORT

Represents the short primitive type

private final boolean
public static final Type
THROWABLE

Represents the java.lang.Throwable reference type

public static final Type
TOP

A placeholder used by the analyzer for the second word position of a double-word type

public static final Type
UNINIT

Represents an unknown, or null type.

public static final Type
VOID

Represents the void primitive type

Constructor Summary

AccessConstructor and Description
pack-priv
Type(CtClass clazz)

private
Type(CtClass clazz, boolean special)

Method Summary

Modifier and TypeMethod and Description
pack-priv String
arrayName(String component, int dims)

private Type
createArray(Type rootComponent, int dims)

pack-priv static boolean
eq(CtClass one, CtClass two)

public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

private Map<String, CtClass>
pack-priv Map<String, CtClass>
private static CtClass
private Map<String, CtClass>
public static Type

Returns:

a type instance for this class
get
(CtClass
The java class
clazz
)

Obtain the Type for a given class.

pack-priv Map<String, CtClass>
private ClassPool
getClassPool(Type rootComponent)

public Type

Returns:

the array component if an array, otherwise null
getComponent
()

Returns the array component if this type is an array.

public CtClass

Returns:

the class for this type, or null if special
getCtClass
()

Returns the class this type represents.

pack-priv Map<String, CtClass>
public int

Returns:

zero if not an array, otherwise the number of array dimensions.
getDimensions
()

Returns the number of dimensions of this array.

pack-priv Type
public int

Returns:

the number of words needed to hold this type
getSize
()

Gets the word size of this type.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public boolean

Returns:

true if an array, false if not
isArray
()

Returns whether or not this type is an array.

public boolean

Returns:

true if this is assignable to type, otherwise false
isAssignableFrom
(Type
the type to test assignability to
type
)

Determines whether this type is assignable, to the passed type.

public boolean

Returns:

true if a java reference, false if a primitive or special
isReference
()

Returns whether or not this type is a normal java reference, i.e. it is or extends java.lang.Object.

public boolean

Returns:

true if special, false if not
isSpecial
()

Returns whether or not the type is special.

private static Type
public Type

Returns:

the merged type
merge
(Type
the type to merge with
type
)

Finds the common base type, or interface which both this and the specified type can be assigned.

private Type
private Type
pack-priv boolean
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

BOGUSback to summary
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.

BOOLEANback to summary
public static final Type BOOLEAN

Represents the boolean primitive type

BYTEback to summary
public static final Type BYTE

Represents the byte primitive type

CHARback to summary
public static final Type CHAR

Represents the char primitive type

clazzback to summary
private final CtClass clazz
CLONEABLEback to summary
public static final Type CLONEABLE

Represents the java.lang.Coneable reference type

DOUBLEback to summary
public static final Type DOUBLE

Represents the double primitive type

FLOATback to summary
public static final Type FLOAT

Represents the float primitive type

INTEGERback to summary
public static final Type INTEGER

Represents the integer primitive type

LONGback to summary
public static final Type LONG

Represents the long primitive type

OBJECTback to summary
public static final Type OBJECT

Represents the java.lang.Object reference type

primsback to summary
private static final Map<CtClass, Type> prims
RETURN_ADDRESSback to summary
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.

SERIALIZABLEback to summary
public static final Type SERIALIZABLE

Represents the java.io.Serializable reference type

SHORTback to summary
public static final Type SHORT

Represents the short primitive type

specialback to summary
private final boolean special
THROWABLEback to summary
public static final Type THROWABLE

Represents the java.lang.Throwable reference type

TOPback to summary
public static final Type TOP

A placeholder used by the analyzer for the second word position of a double-word type

UNINITback to summary
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.

VOIDback to summary
public static final Type VOID

Represents the void primitive type

Constructor Detail

Typeback to summary
pack-priv Type(CtClass clazz)
Typeback to summary
private Type(CtClass clazz, boolean special)

Method Detail

arrayNameback to summary
pack-priv String arrayName(String component, int dims)
createArrayback to summary
private Type createArray(Type rootComponent, int dims)
eqback to summary
pack-priv static boolean eq(CtClass one, CtClass two)
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
findCommonInterfacesback to summary
private Map<String, CtClass> findCommonInterfaces(Type type)
findCommonInterfacesback to summary
pack-priv Map<String, CtClass> findCommonInterfaces(Map<String, CtClass> typeMap, Map<String, CtClass> alterMap)
findCommonSuperClassback to summary
private static CtClass findCommonSuperClass(CtClass one, CtClass two) throws NotFoundException
findExclusiveDeclaredInterfacesback to summary
private Map<String, CtClass> findExclusiveDeclaredInterfaces(Type type, CtClass exclude)
getback to summary
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:CtClass

The java class

Returns:Type

a type instance for this class

getAllInterfacesback to summary
pack-priv Map<String, CtClass> getAllInterfaces(CtClass clazz, Map<String, CtClass> map)
getClassPoolback to summary
private ClassPool getClassPool(Type rootComponent)
getComponentback to summary
public Type getComponent()

Returns the array component if this type is an array. If the type is not an array null is returned.

Returns:Type

the array component if an array, otherwise null

getCtClassback to summary
public CtClass getCtClass()

Returns the class this type represents. If the type is special, null will be returned.

Returns:CtClass

the class for this type, or null if special

getDeclaredInterfacesback to summary
pack-priv Map<String, CtClass> getDeclaredInterfaces(CtClass clazz, Map<String, CtClass> map)
getDimensionsback to summary
public int getDimensions()

Returns the number of dimensions of this array. If the type is not an array zero is returned.

Returns:int

zero if not an array, otherwise the number of array dimensions.

getRootComponentback to summary
pack-priv Type getRootComponent(Type type)
getSizeback to summary
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:int

the number of words needed to hold this type

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isArrayback to summary
public boolean isArray()

Returns whether or not this type is an array.

Returns:boolean

true if an array, false if not

isAssignableFromback to summary
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:Type

the type to test assignability to

Returns:boolean

true if this is assignable to type, otherwise false

isReferenceback to summary
public boolean isReference()

Returns whether or not this type is a normal java reference, i.e. it is or extends java.lang.Object.

Returns:boolean

true if a java reference, false if a primitive or special

isSpecialback to summary
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:boolean

true if special, false if not

lookupTypeback to summary
private static Type lookupType(String name)
mergeback to summary
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:Type

the type to merge with

Returns:Type

the merged type

mergeArrayback to summary
private Type mergeArray(Type type)
mergeClassesback to summary
private Type mergeClasses(Type type) throws NotFoundException
popChangedback to summary
pack-priv boolean popChanged()
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override