Jode 1.90-CVS
Build Aug 6, 2004

net.sf.jode.type
Class Type

java.lang.Object
  extended bynet.sf.jode.type.Type
Direct Known Subclasses:
IntegerType, MethodType, RangeType, ReferenceType

public class Type
extends java.lang.Object

This is my type class. It differs from java.lang.class, in that it represents a set of types. Since most times this set is infinite, it needs a special representation.
The main operation on a type sets are tSuperType, tSubType and intersection.

Author:
Jochen Hoenicke

Field Summary
static ClassType[] EMPTY_IFACES
           
static Type tBoolByte
          This type represents the set of the boolean and byte type.
static Type tBoolean
          This type represents the singleton set containing the boolean type.
static Type tBoolInt
          This type represents the set of the boolean and int type.
static Type tBoolUInt
          This type represents the set of boolean and all integer types, up to 32 bit.
static Type tByte
          This type represents the singleton set containing the byte type.
static int TC_ARRAY
           
static int TC_BOOLEAN
           
static int TC_BYTE
           
static int TC_CHAR
           
static int TC_CLASS
           
static int TC_CLASSIFACE
           
static int TC_DOUBLE
           
static int TC_ERROR
           
static int TC_FLOAT
           
static int TC_INT
           
static int TC_INTEGER
           
static int TC_LONG
           
static int TC_METHOD
           
static int TC_NULL
           
static int TC_RANGE
           
static int TC_SHORT
           
static int TC_SYSCLASS
           
static int TC_UNKNOWN
           
static int TC_VOID
           
static Type tChar
          This type represents the singleton set containing the char type.
static SystemClassType tCloneable
          This type represents the singleton set containing java.lang.Comparable.
static SystemClassType tComparable
          This type represents the singleton set containing java.lang.Comparable.
static Type tDouble
          This type represents the singleton set containing the double type.
static Type tError
          This type represents the empty set, and probably means, that something has gone wrong.
static Type tFloat
          This type represents the singleton set containing the float type.
static Type tInt
          This type represents the singleton set containing the int type.
static SystemClassType tJavaLangClass
          This type represents the singleton set containing java.lang.Class.
static Type tLong
          This type represents the singleton set containing the long type.
static ReferenceType tNull
          This type represents the singleton set containing the special null type (the type of null).
static SystemClassType tObject
          This type represents the singleton set containing java.lang.Object.
static SystemClassType tSerializable
          This type represents the singleton set containing java.lang.Comparable.
static Type tShort
          This type represents the singleton set containing the short type.
static SystemClassType tString
          This type represents the singleton set containing java.lang.String.
static SystemClassType tStringBuffer
          This type represents the singleton set containing java.lang.StringBuffer.
static SystemClassType tStringBuilder
          This type represents the singleton set containing java.lang.StringBuffer.
static Type tUInt
          This type represents the set of all integer types, up to 32 bit.
static Type tUnknown
          This type represents the set of all possible types.
static Type tUObject
          This type represents the set of all reference types, including class types, array types, interface types and the null type.
static Type tVoid
          This type represents the void type.
 
Constructor Summary
protected Type(int tc)
          Create a new type with the given type code.
 
Method Summary
 Type getCanonic()
          Returns the canonic type of this type set.
 Type getCastHelper(Type fromType)
          Checks if we need to cast to a middle type, before we can cast from fromType to this type.
 java.lang.String getDefaultName()
          Generates the default name, that is the `natural' choice for local of this type.
 java.lang.Object getDefaultValue()
          Generates the default value, that is the initial value of a field of this type.
 Type getHint()
          Returns the hint type of this type set.
 Type getSubType()
          The sub types of this type.
 Type getSuperType()
          The super types of this type.
 java.lang.Class getTypeClass()
          Returns the java.lang.Class representing this type.
 int getTypeCode()
          Returns the type code of this type.
 java.lang.String getTypeSignature()
          Returns the type signature of this type.
 Type intersection(Type type)
          Intersect this set of types with another type set and return the intersection.
 boolean isClassType()
          Checks if this is a class or array type (but not a null type).
 boolean isOfType(Type type)
          Check if this type set and the other type set are not disjunct.
 boolean isSubTypeOf(Type type)
          Returns true, if this is a sub type of type.
 boolean isValidType()
          Checks if this type represents a valid singleton type.
 boolean maybeSubTypeOf(Type type)
          Returns true, if this is a sub type of type.
 int stackSize()
          Returns the number of stack/local entries an object of this type occupies.
static Type tArray(Type type)
          Generate/look up the set of the array type whose element types are in the given type set.
static ClassType tClass(ClassInfo clazzinfo)
          Generate the singleton set of the type represented by the given class info.
static ClassType tClass(ClassPath classPath, java.lang.String clazzname)
          Generate the singleton set of the type represented by the given class name.
static MethodType tMethod(ClassPath cp, java.lang.String signature)
          Generate/look up the method type for the given signature
 java.lang.String toString()
          Returns a string representation describing this type set.
static Type tRange(ReferenceType bottom, ReferenceType top)
          Generate the range type from bottom to top.
static Type tSubType(Type type)
          Generate the set of types, which can be casted to one of the types in type by a widening cast.
static Type tSuperType(Type type)
          Generate the set of types, to which one of the types in type can be casted to by a widening cast.
static SystemClassType tSystemClass(java.lang.String clazzName, ClassType superClass, ClassType[] ifaces, boolean isFinal, boolean isInterface)
          Generate the singleton set of the type represented by the given class name.
static Type tType(ClassPath cp, java.lang.String type)
          Generate the singleton set of the type represented by the given string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TC_BOOLEAN

public static final int TC_BOOLEAN
See Also:
Constant Field Values

TC_BYTE

public static final int TC_BYTE
See Also:
Constant Field Values

TC_CHAR

public static final int TC_CHAR
See Also:
Constant Field Values

TC_SHORT

public static final int TC_SHORT
See Also:
Constant Field Values

TC_INT

public static final int TC_INT
See Also:
Constant Field Values

TC_LONG

public static final int TC_LONG
See Also:
Constant Field Values

TC_FLOAT

public static final int TC_FLOAT
See Also:
Constant Field Values

TC_DOUBLE

public static final int TC_DOUBLE
See Also:
Constant Field Values

TC_NULL

public static final int TC_NULL
See Also:
Constant Field Values

TC_ARRAY

public static final int TC_ARRAY
See Also:
Constant Field Values

TC_CLASS

public static final int TC_CLASS
See Also:
Constant Field Values

TC_VOID

public static final int TC_VOID
See Also:
Constant Field Values

TC_METHOD

public static final int TC_METHOD
See Also:
Constant Field Values

TC_ERROR

public static final int TC_ERROR
See Also:
Constant Field Values

TC_UNKNOWN

public static final int TC_UNKNOWN
See Also:
Constant Field Values

TC_RANGE

public static final int TC_RANGE
See Also:
Constant Field Values

TC_INTEGER

public static final int TC_INTEGER
See Also:
Constant Field Values

TC_SYSCLASS

public static final int TC_SYSCLASS
See Also:
Constant Field Values

TC_CLASSIFACE

public static final int TC_CLASSIFACE
See Also:
Constant Field Values

tBoolean

public static final Type tBoolean
This type represents the singleton set containing the boolean type.


tByte

public static final Type tByte
This type represents the singleton set containing the byte type.


tChar

public static final Type tChar
This type represents the singleton set containing the char type.


tShort

public static final Type tShort
This type represents the singleton set containing the short type.


tInt

public static final Type tInt
This type represents the singleton set containing the int type.


tLong

public static final Type tLong
This type represents the singleton set containing the long type.


tFloat

public static final Type tFloat
This type represents the singleton set containing the float type.


tDouble

public static final Type tDouble
This type represents the singleton set containing the double type.


tVoid

public static final Type tVoid
This type represents the void type. It is really not a type at all.


tError

public static final Type tError
This type represents the empty set, and probably means, that something has gone wrong.


tUnknown

public static final Type tUnknown
This type represents the set of all possible types.


tUInt

public static final Type tUInt
This type represents the set of all integer types, up to 32 bit.


tBoolInt

public static final Type tBoolInt
This type represents the set of the boolean and int type.


tBoolUInt

public static final Type tBoolUInt
This type represents the set of boolean and all integer types, up to 32 bit.


tBoolByte

public static final Type tBoolByte
This type represents the set of the boolean and byte type.


EMPTY_IFACES

public static final ClassType[] EMPTY_IFACES

tObject

public static final SystemClassType tObject
This type represents the singleton set containing java.lang.Object.


tNull

public static final ReferenceType tNull
This type represents the singleton set containing the special null type (the type of null).


tUObject

public static final Type tUObject
This type represents the set of all reference types, including class types, array types, interface types and the null type.


tSerializable

public static final SystemClassType tSerializable
This type represents the singleton set containing java.lang.Comparable.


tCloneable

public static final SystemClassType tCloneable
This type represents the singleton set containing java.lang.Comparable.


tComparable

public static final SystemClassType tComparable
This type represents the singleton set containing java.lang.Comparable.


tString

public static final SystemClassType tString
This type represents the singleton set containing java.lang.String.


tStringBuffer

public static final SystemClassType tStringBuffer
This type represents the singleton set containing java.lang.StringBuffer.


tStringBuilder

public static final SystemClassType tStringBuilder
This type represents the singleton set containing java.lang.StringBuffer.


tJavaLangClass

public static final SystemClassType tJavaLangClass
This type represents the singleton set containing java.lang.Class.

Constructor Detail

Type

protected Type(int tc)
Create a new type with the given type code.

Method Detail

tType

public static final Type tType(ClassPath cp,
                               java.lang.String type)
Generate the singleton set of the type represented by the given string.

Parameters:
type - the type signature (or method signature).
Returns:
a singleton set containing the given type.

tClass

public static final ClassType tClass(ClassPath classPath,
                                     java.lang.String clazzname)
Generate the singleton set of the type represented by the given class name.

Parameters:
clazzname - the full qualified name of the class. The packages may be separated by `.' or `/'.
Returns:
a singleton set containing the given type.

tSystemClass

public static final SystemClassType tSystemClass(java.lang.String clazzName,
                                                 ClassType superClass,
                                                 ClassType[] ifaces,
                                                 boolean isFinal,
                                                 boolean isInterface)
Generate the singleton set of the type represented by the given class name.

Returns:
a singleton set containing the given type.

tClass

public static final ClassType tClass(ClassInfo clazzinfo)
Generate the singleton set of the type represented by the given class info.

Parameters:
clazzinfo - the net.sf.jode.bytecode.ClassInfo.
Returns:
a singleton set containing the given type.

tArray

public static final Type tArray(Type type)
Generate/look up the set of the array type whose element types are in the given type set.

Parameters:
type - the element types (which may be the empty set tError).
Returns:
the set of array types (which may be the empty set tError).

tMethod

public static MethodType tMethod(ClassPath cp,
                                 java.lang.String signature)
Generate/look up the method type for the given signature

Parameters:
signature - the method decriptor.
Returns:
a method type (a singleton set).

tRange

public static final Type tRange(ReferenceType bottom,
                                ReferenceType top)
Generate the range type from bottom to top. This should represent all reference types, that can be casted to bottom by a widening cast and where top can be casted to. You should not use this method directly; use tSubType, tSuperType and intersection instead, which is more general.

Parameters:
bottom - the bottom type.
top - the top type.
Returns:
the range type.

tSuperType

public static Type tSuperType(Type type)
Generate the set of types, to which one of the types in type can be casted to by a widening cast. The following holds:

Parameters:
type - a set of types.
Returns:
the super types of type.

tSubType

public static Type tSubType(Type type)
Generate the set of types, which can be casted to one of the types in type by a widening cast. The following holds:

Parameters:
type - a set of types.
Returns:
the sub types of type.

getSubType

public Type getSubType()
The sub types of this type.

Returns:
tSubType(this).

getSuperType

public Type getSuperType()
The super types of this type.

Returns:
tSuperType(this).

getHint

public Type getHint()
Returns the hint type of this type set. This returns the singleton set containing only the `most likely' type in this set. This doesn't work for tError or tUnknown, and may lead to errors for certain range types.

Returns:
the hint type.

getCanonic

public Type getCanonic()
Returns the canonic type of this type set. The intention is, to return for each expression the type, that the java compiler would assign to this expression.

Returns:
the canonic type.

getTypeCode

public final int getTypeCode()
Returns the type code of this type. Don't use this; it is merily needed by the sub types (and the bytecode verifier, which has its own type merging methods).

Returns:
the type code of the type.

stackSize

public int stackSize()
Returns the number of stack/local entries an object of this type occupies.

Returns:
0 for tVoid, 2 for tDouble and tLong and 1 for every other type.

isSubTypeOf

public boolean isSubTypeOf(Type type)
Returns true, if this is a sub type of type.


maybeSubTypeOf

public boolean maybeSubTypeOf(Type type)
Returns true, if this is a sub type of type.


intersection

public Type intersection(Type type)
Intersect this set of types with another type set and return the intersection.

Parameters:
type - the other type set.
Returns:
the intersection, tError, if the intersection is empty.

getCastHelper

public Type getCastHelper(Type fromType)
Checks if we need to cast to a middle type, before we can cast from fromType to this type. For example it is impossible to cast a String to a StringBuffer, but if we cast to Object in between this is allowed (it doesn't make much sense though).

Returns:
the middle type, or null if it is not necessary.

isValidType

public boolean isValidType()
Checks if this type represents a valid singleton type.


isClassType

public boolean isClassType()
Checks if this is a class or array type (but not a null type).

Returns:
true if this is a class or array type.

isOfType

public boolean isOfType(Type type)
Check if this type set and the other type set are not disjunct.

Parameters:
type - the other type set.
Returns:
true if this they aren't disjunct.

getDefaultName

public java.lang.String getDefaultName()
Generates the default name, that is the `natural' choice for local of this type.

Returns:
the default name of a local of this type.

getDefaultValue

public java.lang.Object getDefaultValue()
Generates the default value, that is the initial value of a field of this type.

Returns:
the default value of a field of this type.

getTypeSignature

public java.lang.String getTypeSignature()
Returns the type signature of this type. You should only call this on singleton types.

Returns:
the type (or method) signature of this type.

getTypeClass

public java.lang.Class getTypeClass()
                             throws java.lang.ClassNotFoundException
Returns the java.lang.Class representing this type. You should only call this on singleton types.

Returns:
the Class object representing this type.
Throws:
java.lang.ClassNotFoundException

toString

public java.lang.String toString()
Returns a string representation describing this type set.

Returns:
a string representation describing this type set.

Jode 1.90-CVS
Build Aug 6, 2004

Copyright © 1998-2004 by Jochen Hoenicke.