Package EDU.purdue.cs.bloat.editor
Class Type
- java.lang.Object
-
- EDU.purdue.cs.bloat.editor.Type
-
public class Type extends java.lang.ObjectType 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
Fields Modifier and Type Field Description static TypeADDRESSstatic charADDRESS_CHARstatic charARRAY_CHARstatic TypeBOOLEANstatic charBOOLEAN_CHARstatic intBOOLEAN_CODEstatic TypeBYTEstatic charBYTE_CHARstatic intBYTE_CODEstatic TypeCHARACTERstatic charCHARACTER_CHARstatic intCHARACTER_CODEstatic TypeCLASSstatic charCLASS_CHARstatic TypeCLONEABLEstatic TypeDOUBLEstatic charDOUBLE_CHARstatic intDOUBLE_CODEstatic TypeFLOATstatic charFLOAT_CHARstatic intFLOAT_CODEstatic TypeINTEGERstatic charINTEGER_CHARstatic intINTEGER_CODEstatic TypeLONGstatic charLONG_CHARstatic intLONG_CODEstatic TypeNULLstatic TypeOBJECTstatic booleanPRINT_TRUNCATEDPrint truncated (abbreviated) type names.static TypeSERIALIZABLEstatic TypeSHORTstatic charSHORT_CHARstatic intSHORT_CODEstatic TypeSTRINGstatic TypeTHROWABLEstatic TypeVOIDstatic charVOID_CHAR
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TypearrayType()Get a Type representing an array of this type.TypearrayType(int dimensions)Create a Type representing a multidimensional array of this type.static java.lang.StringclassDescriptor(java.lang.String name)Get the type descriptor of a class from a string representation..java.lang.StringclassName()Get the class name of the type.static java.util.Comparatorcomparator()Returns a Comparator used to compare Types.java.lang.Stringdescriptor()Get a descriptor of the type.intdimensions()Get the number of dimensions of an array type.TypeelementType()Get the element type of an array type.TypeelementType(int dimensions)Get the element type of this array type.booleanequals(java.lang.Object obj)Returns 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 TypegetType(Type[] paramTypes, Type returnType)Returns the Type for a method with the given parameter and return typesstatic TypegetType(java.lang.Class c)Returns aTypethat represents a givenClass.static TypegetType(java.lang.String desc)Returns a Type of a given descriptor.inthashCode()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.booleanisAddress()Check if the type is a returnAddress.booleanisArray()Check if the type is an array type.booleanisIntegral()Check 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).booleanisPrimitive()Check if the type is a primitive type.booleanisReference()Check 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 voidmain(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.ComparatorprintComparator()Returns a Comparator that compares Types based on how they are displayed.java.lang.Stringqualifier()Get the qualifier of the type.TypereturnType()Get a return type of a method type.java.lang.StringshortName()Get a one character name for the type.Typesimple()Get a simplification of the type.intstackHeight()Returns the number of slots in the stack that this Type takes up on the JVM stack.java.lang.StringtoString()Convert the type to a string.static java.lang.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 Detail
-
ARRAY_CHAR
public static final char ARRAY_CHAR
- See Also:
- Constant Field Values
-
BOOLEAN_CHAR
public static final char BOOLEAN_CHAR
- See Also:
- Constant Field Values
-
BYTE_CHAR
public static final char BYTE_CHAR
- See Also:
- Constant Field Values
-
CHARACTER_CHAR
public static final char CHARACTER_CHAR
- See Also:
- Constant Field Values
-
CLASS_CHAR
public static final char CLASS_CHAR
- See Also:
- Constant Field Values
-
DOUBLE_CHAR
public static final char DOUBLE_CHAR
- See Also:
- Constant Field Values
-
FLOAT_CHAR
public static final char FLOAT_CHAR
- See Also:
- Constant Field Values
-
INTEGER_CHAR
public static final char INTEGER_CHAR
- See Also:
- Constant Field Values
-
LONG_CHAR
public static final char LONG_CHAR
- See Also:
- Constant Field Values
-
SHORT_CHAR
public static final char SHORT_CHAR
- See Also:
- Constant Field Values
-
VOID_CHAR
public static final char VOID_CHAR
- See Also:
- Constant Field Values
-
ADDRESS_CHAR
public static final char ADDRESS_CHAR
- See Also:
- Constant Field Values
-
BOOLEAN_CODE
public static final int BOOLEAN_CODE
- See Also:
- Constant Field Values
-
CHARACTER_CODE
public static final int CHARACTER_CODE
- See Also:
- Constant Field Values
-
FLOAT_CODE
public static final int FLOAT_CODE
- See Also:
- Constant Field Values
-
DOUBLE_CODE
public static final int DOUBLE_CODE
- See Also:
- Constant Field Values
-
BYTE_CODE
public static final int BYTE_CODE
- See Also:
- Constant Field Values
-
SHORT_CODE
public static final int SHORT_CODE
- See Also:
- Constant Field Values
-
INTEGER_CODE
public static final int INTEGER_CODE
- See Also:
- Constant Field Values
-
LONG_CODE
public static final int LONG_CODE
- See Also:
- Constant Field Values
-
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 aTypethat represents a givenClass.
-
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:
hashCodein classjava.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:
equalsin classjava.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:
toStringin classjava.lang.Object- Returns:
- A string representation of the type.
-
main
public static void main(java.lang.String[] args)
Test truncatedName.
-
-