Package javassist.bytecode.analysis
Class Type
java.lang.Object
javassist.bytecode.analysis.Type
- Direct Known Subclasses:
MultiArrayType
,MultiType
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 TypeFieldDescriptionstatic final Type
Represents a non-accessible value.static final Type
Represents the boolean primitive typestatic final Type
Represents the byte primitive typestatic final Type
Represents the char primitive typestatic final Type
Represents the java.lang.Coneable reference typestatic final Type
Represents the double primitive typestatic final Type
Represents the float primitive typestatic final Type
Represents the integer primitive typestatic final Type
Represents the long primitive typestatic final Type
Represents the java.lang.Object reference typestatic 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 typestatic final Type
Represents the short primitive typestatic final Type
Represents the java.lang.Throwable reference typestatic final Type
A placeholder used by the analyzer for the second word position of a double-word typestatic final Type
Represents an unknown, or null type.static final Type
Represents the void primitive type -
Method Summary
Modifier and TypeMethodDescriptionboolean
static Type
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
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
Returns whether or not this type is a normal java reference, i.e.boolean
Returns whether or not the type is special.Finds the common base type, or interface which both this and the specified type can be assigned.toString()
-
Field Details
-
DOUBLE
Represents the double primitive type -
BOOLEAN
Represents the boolean primitive type -
LONG
Represents the long primitive type -
CHAR
Represents the char primitive type -
BYTE
Represents the byte primitive type -
SHORT
Represents the short primitive type -
INTEGER
Represents the integer primitive type -
FLOAT
Represents the float primitive type -
VOID
Represents the void primitive 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
Represents an internal JVM return address, which is used by the RET instruction to return to a JSR that invoked the subroutine. -
TOP
A placeholder used by the analyzer for the second word position of a double-word 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
Represents the java.lang.Object reference type -
SERIALIZABLE
Represents the java.io.Serializable reference type -
CLONEABLE
Represents the java.lang.Coneable reference type -
THROWABLE
Represents the java.lang.Throwable reference type
-
-
Method Details
-
get
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
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
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
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
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 aMultiType
, or aMultiArrayType
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() -
equals
-
toString
-