Class Type
java.lang.Object
EDU.purdue.cs.bloat.editor.Type
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
(IZLjava/lang/Object;)Ljava/lang/String;
The method String f(int a, boolean b, Object c) has the type descriptor:
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Typestatic final charstatic final charstatic final Typestatic final charstatic final intstatic final Typestatic final charstatic final intstatic final Typestatic final charstatic final intstatic final Typestatic final charstatic final Typestatic final Typestatic final charstatic final intstatic final Typestatic final charstatic final intstatic final Typestatic final charstatic final intstatic final Typestatic final charstatic final intstatic final Typestatic final Typestatic booleanPrint truncated (abbreviated) type names.static final Typestatic final Typestatic final charstatic final intstatic final Typestatic final Typestatic final Typestatic final char -
Method Summary
Modifier and TypeMethodDescriptionGet a Type representing an array of this type.arrayType(int dimensions) Create a Type representing a multidimensional array of this type.static StringclassDescriptor(String name) Get the type descriptor of a class from a string representation..Get the class name of the type.static ComparatorReturns a Comparator used to compare Types.Get a descriptor of the type.intGet the number of dimensions of an array type.Get the element type of an array type.elementType(int dimensions) Get the element type of this array type.booleanReturns true if two Types are equal.static TypegetType(char typeChar) Returns a Type of a primitive type based on a one-character type descriptor.static TypegetType(int typeCode) Returns a Type for a primitive type based on its integer "type code".static TypeReturns the Type for a method with the given parameter and return typesstatic TypeReturns aTypethat represents a givenClass.static TypeReturns a Type of a given descriptor.inthashCode()Hash the type.Type[]If this Type is a method type, get the parameter types of the method, including empty positions for the second word of wide types.booleanCheck if the type is a returnAddress.booleanisArray()Check if the type is an array type.booleanCheck if the type is an integral type.booleanisMethod()Check if the type is a method type.booleanisNull()Check if the type is a null type.booleanisObject()Check if the type is an object type (not array).booleanCheck if the type is a primitive type.booleanCheck if the type is an array or object.booleanisVoid()Check if the type is a void type.booleanisWide()Check if the type takes of 2 local variable or stack positions.static voidTest truncatedName.Type[]Get the parameter types of the method, not including empty positions for the second word of wide types.static ComparatorReturns a Comparator that compares Types based on how they are displayed.Get the qualifier of the type.Get a return type of a method type.Get a one character name for the type.simple()Get a simplification of the type.intReturns the number of slots in the stack that this Type takes up on the JVM stack.toString()Convert the type to a string.static StringtruncatedName(Type type) Returns a string representing the truncated name of a Type.inttypeCode()Get the type code of the type (which must be a primitive type).
-
Field Details
-
ARRAY_CHAR
public static final char ARRAY_CHAR- See Also:
-
BOOLEAN_CHAR
public static final char BOOLEAN_CHAR- See Also:
-
BYTE_CHAR
public static final char BYTE_CHAR- See Also:
-
CHARACTER_CHAR
public static final char CHARACTER_CHAR- See Also:
-
CLASS_CHAR
public static final char CLASS_CHAR- See Also:
-
DOUBLE_CHAR
public static final char DOUBLE_CHAR- See Also:
-
FLOAT_CHAR
public static final char FLOAT_CHAR- See Also:
-
INTEGER_CHAR
public static final char INTEGER_CHAR- See Also:
-
LONG_CHAR
public static final char LONG_CHAR- See Also:
-
SHORT_CHAR
public static final char SHORT_CHAR- See Also:
-
VOID_CHAR
public static final char VOID_CHAR- See Also:
-
ADDRESS_CHAR
public static final char ADDRESS_CHAR- See Also:
-
BOOLEAN_CODE
public static final int BOOLEAN_CODE- See Also:
-
CHARACTER_CODE
public static final int CHARACTER_CODE- See Also:
-
FLOAT_CODE
public static final int FLOAT_CODE- See Also:
-
DOUBLE_CODE
public static final int DOUBLE_CODE- See Also:
-
BYTE_CODE
public static final int BYTE_CODE- See Also:
-
SHORT_CODE
public static final int SHORT_CODE- See Also:
-
INTEGER_CODE
public static final int INTEGER_CODE- See Also:
-
LONG_CODE
public static final int LONG_CODE- See Also:
-
OBJECT
-
STRING
-
CLASS
-
THROWABLE
-
CLONEABLE
-
SERIALIZABLE
-
NULL
-
BOOLEAN
-
CHARACTER
-
FLOAT
-
DOUBLE
-
BYTE
-
SHORT
-
INTEGER
-
LONG
-
VOID
-
ADDRESS
-
PRINT_TRUNCATED
public static boolean PRINT_TRUNCATEDPrint truncated (abbreviated) type names.
-
-
Method Details
-
getType
-
getType
-
getType
-
getType
Returns a Type for a primitive type based on its integer "type code". -
getType
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:
IllegalArgumentException- If the type is not primitive.
-
shortName
Get a one character name for the 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
-
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
-
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
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
Get a Type representing an array of this type. -
arrayType
Create a Type representing a multidimensional array of this type. -
elementType
Get the element type of this array type.- Parameters:
dimensions- The number of times to index into the array.- Returns:
- The element type.
- Throws:
IllegalArgumentException- If the type is not an array.
-
elementType
Get the element type of an array type.- Returns:
- The element type.
- Throws:
IllegalArgumentException- If the type is not an array.
-
returnType
-
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
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
-
equals
-
comparator
Returns a Comparator used to compare Types. -
printComparator
Returns a Comparator that compares Types based on how they are displayed. -
truncatedName
-
toString
-
main
Test truncatedName.
-