EDU.purdue.cs.bloat.editor
Class Type

java.lang.Object
  |
  +--EDU.purdue.cs.bloat.editor.Type

public class Type
extends java.lang.Object

Type represents a type descriptor in a classes constant pool. A type descriptor describes the type of a field of method using a funky encoding which is described in the Java Virtual Machine Specification. For example, the field int x[] has the type descriptor:

[I

The method String f(int a, boolean b, Object c) has the type descriptor:

(IZLjava/lang/Object;)Ljava/lang/String;

See Also:
Constant

Field Summary
static Type ADDRESS
           
static char ADDRESS_CHAR
           
static char ARRAY_CHAR
           
static Type BOOLEAN
           
static char BOOLEAN_CHAR
           
static int BOOLEAN_CODE
           
static Type BYTE
           
static char BYTE_CHAR
           
static int BYTE_CODE
           
static Type CHARACTER
           
static char CHARACTER_CHAR
           
static int CHARACTER_CODE
           
static Type CLASS
           
static char CLASS_CHAR
           
static Type CLONEABLE
           
static Type DOUBLE
           
static char DOUBLE_CHAR
           
static int DOUBLE_CODE
           
static Type FLOAT
           
static char FLOAT_CHAR
           
static int FLOAT_CODE
           
static Type INTEGER
           
static char INTEGER_CHAR
           
static int INTEGER_CODE
           
static Type LONG
           
static char LONG_CHAR
           
static int LONG_CODE
           
static Type NULL
           
static Type OBJECT
           
static boolean PRINT_TRUNCATED
          Print truncated (abbreviated) type names.
static Type SERIALIZABLE
           
static Type SHORT
           
static char SHORT_CHAR
           
static int SHORT_CODE
           
static Type STRING
           
static Type THROWABLE
           
static Type VOID
           
static char VOID_CHAR
           
 
Method Summary
 Type arrayType()
          Get a Type representing an array of this type.
 Type arrayType(int dimensions)
          Create a Type representing a multidimensional array of this type.
static java.lang.String classDescriptor(java.lang.String name)
          Get the type descriptor of a class from a string representation..
 java.lang.String className()
          Get the class name of the type.
static java.util.Comparator comparator()
          Returns a Comparator used to compare Types.
 java.lang.String descriptor()
          Get a descriptor of the type.
 int dimensions()
          Get the number of dimensions of an array type.
 Type elementType()
          Get the element type of an array type.
 Type elementType(int dimensions)
          Get the element type of this array type.
 boolean equals(java.lang.Object obj)
          Returns true if two Types are equal.
static Type getType(char typeChar)
          Returns a Type of a primitive type based on a one-character type descriptor.
static Type getType(java.lang.Class c)
          Returns a Type that represents a given Class.
static Type getType(int typeCode)
          Returns a Type for a primitive type based on its integer "type code".
static Type getType(java.lang.String desc)
          Returns a Type of a given descriptor.
static Type getType(Type[] paramTypes, Type returnType)
          Returns the Type for a method with the given parameter and return types
 int hashCode()
          Hash the type.
 Type[] indexedParamTypes()
          If this Type is a method type, get the parameter types of the method, including empty positions for the second word of wide types.
 boolean isAddress()
          Check if the type is a returnAddress.
 boolean isArray()
          Check if the type is an array type.
 boolean isIntegral()
          Check if the type is an integral type.
 boolean isMethod()
          Check if the type is a method type.
 boolean isNull()
          Check if the type is a null type.
 boolean isObject()
          Check if the type is an object type (not array).
 boolean isPrimitive()
          Check if the type is a primitive type.
 boolean isReference()
          Check if the type is an array or object.
 boolean isVoid()
          Check if the type is a void type.
 boolean isWide()
          Check if the type takes of 2 local variable or stack positions.
static void main(java.lang.String[] args)
          Test truncatedName.
 Type[] paramTypes()
          Get the parameter types of the method, not including empty positions for the second word of wide types.
static java.util.Comparator printComparator()
          Returns a Comparator that compares Types based on how they are displayed.
 java.lang.String qualifier()
          Get the qualifier of the type.
 Type returnType()
          Get a return type of a method type.
 java.lang.String shortName()
          Get a one character name for the type.
 Type simple()
          Get a simplification of the type.
 int stackHeight()
          Returns the number of slots in the stack that this Type takes up on the JVM stack.
 java.lang.String toString()
          Convert the type to a string.
static java.lang.String truncatedName(Type type)
          Returns a string representing the truncated name of a Type.
 int typeCode()
          Get the type code of the type (which must be a primitive type).
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ARRAY_CHAR

public static final char ARRAY_CHAR

BOOLEAN_CHAR

public static final char BOOLEAN_CHAR

BYTE_CHAR

public static final char BYTE_CHAR

CHARACTER_CHAR

public static final char CHARACTER_CHAR

CLASS_CHAR

public static final char CLASS_CHAR

DOUBLE_CHAR

public static final char DOUBLE_CHAR

FLOAT_CHAR

public static final char FLOAT_CHAR

INTEGER_CHAR

public static final char INTEGER_CHAR

LONG_CHAR

public static final char LONG_CHAR

SHORT_CHAR

public static final char SHORT_CHAR

VOID_CHAR

public static final char VOID_CHAR

ADDRESS_CHAR

public static final char ADDRESS_CHAR

BOOLEAN_CODE

public static final int BOOLEAN_CODE

CHARACTER_CODE

public static final int CHARACTER_CODE

FLOAT_CODE

public static final int FLOAT_CODE

DOUBLE_CODE

public static final int DOUBLE_CODE

BYTE_CODE

public static final int BYTE_CODE

SHORT_CODE

public static final int SHORT_CODE

INTEGER_CODE

public static final int INTEGER_CODE

LONG_CODE

public static final int LONG_CODE

OBJECT

public static final Type OBJECT

STRING

public static final Type STRING

CLASS

public static final Type CLASS

THROWABLE

public static final Type THROWABLE

CLONEABLE

public static final Type CLONEABLE

SERIALIZABLE

public static final Type SERIALIZABLE

NULL

public static final Type NULL

BOOLEAN

public static final Type BOOLEAN

CHARACTER

public static final Type CHARACTER

FLOAT

public static final Type FLOAT

DOUBLE

public static final Type DOUBLE

BYTE

public static final Type BYTE

SHORT

public static final Type SHORT

INTEGER

public static final Type INTEGER

LONG

public static final Type LONG

VOID

public static final Type VOID

ADDRESS

public static final Type ADDRESS

PRINT_TRUNCATED

public static boolean PRINT_TRUNCATED
Print truncated (abbreviated) type names.
Method Detail

getType

public static Type getType(java.lang.String desc)
Returns a Type of a given descriptor. Equals descriptors will result in the same Type.

getType

public static Type getType(java.lang.Class c)
Returns a Type that represents a given Class.

getType

public static Type getType(Type[] paramTypes,
                           Type returnType)
Returns the Type for a method with the given parameter and return types

getType

public static Type getType(int typeCode)
Returns a Type for a primitive type based on its integer "type code".

getType

public static Type getType(char typeChar)
Returns a Type of a primitive type based on a one-character type descriptor.

typeCode

public int typeCode()
Get the type code of the type (which must be a primitive type).
Returns:
The type code of the type.
Throws:
java.lang.IllegalArgumentException - If the type is not primitive.

shortName

public java.lang.String shortName()
Get a one character name for the type.

simple

public Type simple()
Get a simplification of the type. All integral types become INTEGER. All reference types (objects, arrays, returnAddress) become OBJECT.
Returns:
The simplified type.

descriptor

public java.lang.String descriptor()
Get a descriptor of the type.
Returns:
The type descriptor.

isMethod

public boolean isMethod()
Check if the type is a method type.
Returns:
true if a method type, false if not.

isNull

public boolean isNull()
Check if the type is a null type.
Returns:
true if a null type, false if not.

isVoid

public boolean isVoid()
Check if the type is a void type.
Returns:
true if a void type, false if not.

isPrimitive

public boolean isPrimitive()
Check if the type is a primitive type.
Returns:
true if a primitive type, false if not.

isIntegral

public boolean isIntegral()
Check if the type is an integral type. Integral contains BOOLEAN as far as the JVM is concerned.
Returns:
true if an integral type, false if not.

isArray

public boolean isArray()
Check if the type is an array type.
Returns:
true if an array type, false if not.

isObject

public boolean isObject()
Check if the type is an object type (not array).
Returns:
true if an object type, false if not.

isWide

public boolean isWide()
Check if the type takes of 2 local variable or stack positions.
Returns:
true if a wide type, false if not.

isAddress

public boolean isAddress()
Check if the type is a returnAddress.
Returns:
true if a address type, false if not.

isReference

public boolean isReference()
Check if the type is an array or object.
Returns:
true if a reference type, false if not.

classDescriptor

public static java.lang.String classDescriptor(java.lang.String name)
Get the type descriptor of a class from a string representation.. For example "java/lang/String" becomes "Ljava/lang/String;"
Parameters:
name - The name of the class.
Returns:
The type descriptor of the class.

className

public java.lang.String className()
Get the class name of the type. For example if the class descriptor is "Ljava/lang/String;", the class name is "java/lang/String".
Returns:
The class name of the type.

qualifier

public java.lang.String qualifier()
Get the qualifier of the type. For example if the class descriptor is "Ljava/lang/String;", the qualifier is "java/lang/".
Returns:
The qualifier of the type.

dimensions

public int dimensions()
Get the number of dimensions of an array type.

arrayType

public Type arrayType()
Get a Type representing an array of this type.

arrayType

public Type arrayType(int dimensions)
Create a Type representing a multidimensional array of this type.

elementType

public Type elementType(int dimensions)
Get the element type of this array type.
Parameters:
dimensions - The number of times to index into the array.
Returns:
The element type.
Throws:
java.lang.IllegalArgumentException - If the type is not an array.

elementType

public Type elementType()
Get the element type of an array type.
Returns:
The element type.
Throws:
java.lang.IllegalArgumentException - If the type is not an array.

returnType

public Type returnType()
Get a return type of a method type.
Returns:
The return type.

indexedParamTypes

public Type[] indexedParamTypes()
If this Type is a method type, get the parameter types of the method, including empty positions for the second word of wide types. This method is good for figuring out which local variables go with parameters. Recall that wide data takes up two local variables.

paramTypes

public Type[] paramTypes()
Get the parameter types of the method, not including empty positions for the second word of wide types.
Returns:
The parameter types.

stackHeight

public int stackHeight()
Returns the number of slots in the stack that this Type takes up on the JVM stack. This type descriptor is intended to represent the parameters of a method. If there are no parameters, 0 is returned. Else return count each parameter as 1 except wide parameters (longs and doubles) as 2.

It also give you an idea of how may parameters a method has.


hashCode

public int hashCode()
Hash the type.
Overrides:
hashCode in class java.lang.Object
Returns:
The hash code.

equals

public boolean equals(java.lang.Object obj)
Returns true if two Types are equal. Equal Types have equal descriptors.
Overrides:
equals in class java.lang.Object

comparator

public static java.util.Comparator comparator()
Returns a Comparator used to compare Types.

printComparator

public static java.util.Comparator printComparator()
Returns a Comparator that compares Types based on how they are displayed.

truncatedName

public static java.lang.String truncatedName(Type type)
Returns a string representing the truncated name of a Type. For instance java/lang/String would just return String.

toString

public java.lang.String toString()
Convert the type to a string.
Overrides:
toString in class java.lang.Object
Returns:
A string representation of the type.

main

public static void main(java.lang.String[] args)
Test truncatedName.