Class Type

java.lang.Object
EDU.purdue.cs.bloat.editor.Type

public class Type extends 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:
  • 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

      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
  • Method Details

    • getType

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

      public static Type getType(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:
      IllegalArgumentException - If the type is not primitive.
    • shortName

      public 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 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 String classDescriptor(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 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 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:
      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:
      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 Object
      Returns:
      The hash code.
    • equals

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

      public static Comparator comparator()
      Returns a Comparator used to compare Types.
    • printComparator

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

      public static 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 String toString()
      Convert the type to a string.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the type.
    • main

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