org.cojen.classfile
Class TypeDesc

java.lang.Object
  extended by org.cojen.classfile.Descriptor
      extended by org.cojen.classfile.TypeDesc
All Implemented Interfaces:
Serializable

public abstract class TypeDesc
extends Descriptor
implements Serializable

This class is used to build field and return type descriptor strings as defined in The Java Virtual Machine Specification, section 4.3.2. TypeDesc instances are canonicalized and therefore "==" comparable.

Author:
Brian S O'Neill
See Also:
Serialized Form

Field Summary
static TypeDesc BOOLEAN
          Primitive type boolean
static int BOOLEAN_CODE
          Type code returned from getTypeCode, which can be used with the newarray instruction.
static TypeDesc BYTE
          Primitive type byte
static int BYTE_CODE
          Type code returned from getTypeCode, which can be used with the newarray instruction.
static TypeDesc CHAR
          Primitive type char
static int CHAR_CODE
          Type code returned from getTypeCode, which can be used with the newarray instruction.
static TypeDesc DOUBLE
          Primitive type double
static int DOUBLE_CODE
          Type code returned from getTypeCode, which can be used with the newarray instruction.
static TypeDesc FLOAT
          Primitive type float
static int FLOAT_CODE
          Type code returned from getTypeCode, which can be used with the newarray instruction.
static TypeDesc INT
          Primitive type int
static int INT_CODE
          Type code returned from getTypeCode, which can be used with the newarray instruction.
static TypeDesc LONG
          Primitive type long
static int LONG_CODE
          Type code returned from getTypeCode, which can be used with the newarray instruction.
static TypeDesc OBJECT
          Object type java.lang.Object, provided for convenience
static int OBJECT_CODE
          Type code returned from getTypeCode, which can be used with the newarray instruction.
static TypeDesc SHORT
          Primitive type short
static int SHORT_CODE
          Type code returned from getTypeCode, which can be used with the newarray instruction.
static TypeDesc STRING
          Object type java.lang.String, provided for convenience
static TypeDesc VOID
          Primitive type void
static int VOID_CODE
          Type code returned from getTypeCode, which can be used with the newarray instruction.
 
Method Summary
 boolean equals(Object other)
           
static TypeDesc forClass(Class clazz)
          Acquire a TypeDesc from any class, including primitives and arrays.
static TypeDesc forClass(String name)
          Acquire a TypeDesc from any class name, including primitives and arrays.
static TypeDesc forDescriptor(String desc)
          Acquire a TypeDesc from a type descriptor.
abstract  TypeDesc getComponentType()
          Returns the component type of this array type.
 String getDescriptor()
          Returns a type descriptor string, excluding generics.
abstract  int getDimensions()
          Returns the number of dimensions this array type has.
abstract  String getFullName()
          Returns the class name for this descriptor.
abstract  TypeDesc getRootComponentType()
          Returns the root component type of this array type.
abstract  String getRootName()
          Returns the class name for this descriptor.
abstract  int getTypeCode()
          Returns a type code for operating on primitive types in switches.
 int hashCode()
           
abstract  boolean isArray()
          Returns true if this is an array type.
abstract  boolean isDoubleWord()
          Returns true if this is a primitive long or double type.
abstract  boolean isPrimitive()
          Returns true if this is a primitive type.
abstract  TypeDesc toArrayType()
          Convertes this type to an array type.
abstract  Class toClass()
          Returns this type as a class.
abstract  Class toClass(ClassLoader loader)
          Returns this type as a class.
abstract  TypeDesc toObjectType()
          Returns the object peer of this primitive type.
abstract  TypeDesc toPrimitiveType()
          Returns the primitive peer of this object type, if one exists.
 String toString()
           
 
Methods inherited from class org.cojen.classfile.Descriptor
parse
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

OBJECT_CODE

public static final int OBJECT_CODE
Type code returned from getTypeCode, which can be used with the newarray instruction.

See Also:
Constant Field Values

VOID_CODE

public static final int VOID_CODE
Type code returned from getTypeCode, which can be used with the newarray instruction.

See Also:
Constant Field Values

BOOLEAN_CODE

public static final int BOOLEAN_CODE
Type code returned from getTypeCode, which can be used with the newarray instruction.

See Also:
Constant Field Values

CHAR_CODE

public static final int CHAR_CODE
Type code returned from getTypeCode, which can be used with the newarray instruction.

See Also:
Constant Field Values

FLOAT_CODE

public static final int FLOAT_CODE
Type code returned from getTypeCode, which can be used with the newarray instruction.

See Also:
Constant Field Values

DOUBLE_CODE

public static final int DOUBLE_CODE
Type code returned from getTypeCode, which can be used with the newarray instruction.

See Also:
Constant Field Values

BYTE_CODE

public static final int BYTE_CODE
Type code returned from getTypeCode, which can be used with the newarray instruction.

See Also:
Constant Field Values

SHORT_CODE

public static final int SHORT_CODE
Type code returned from getTypeCode, which can be used with the newarray instruction.

See Also:
Constant Field Values

INT_CODE

public static final int INT_CODE
Type code returned from getTypeCode, which can be used with the newarray instruction.

See Also:
Constant Field Values

LONG_CODE

public static final int LONG_CODE
Type code returned from getTypeCode, which can be used with the newarray instruction.

See Also:
Constant Field Values

VOID

public static final TypeDesc VOID
Primitive type void


BOOLEAN

public static final TypeDesc BOOLEAN
Primitive type boolean


CHAR

public static final TypeDesc CHAR
Primitive type char


BYTE

public static final TypeDesc BYTE
Primitive type byte


SHORT

public static final TypeDesc SHORT
Primitive type short


INT

public static final TypeDesc INT
Primitive type int


LONG

public static final TypeDesc LONG
Primitive type long


FLOAT

public static final TypeDesc FLOAT
Primitive type float


DOUBLE

public static final TypeDesc DOUBLE
Primitive type double


OBJECT

public static final TypeDesc OBJECT
Object type java.lang.Object, provided for convenience


STRING

public static final TypeDesc STRING
Object type java.lang.String, provided for convenience

Method Detail

forClass

public static TypeDesc forClass(Class clazz)
Acquire a TypeDesc from any class, including primitives and arrays.


forClass

public static TypeDesc forClass(String name)
                         throws IllegalArgumentException
Acquire a TypeDesc from any class name, including primitives and arrays. Primitive and array syntax matches Java declarations.

Throws:
IllegalArgumentException

forDescriptor

public static TypeDesc forDescriptor(String desc)
                              throws IllegalArgumentException
Acquire a TypeDesc from a type descriptor. This syntax is described in section 4.3.2, Field Descriptors.

Throws:
IllegalArgumentException

getDescriptor

public final String getDescriptor()
Returns a type descriptor string, excluding generics.

Specified by:
getDescriptor in class Descriptor

getRootName

public abstract String getRootName()
Returns the class name for this descriptor. If the type is primitive, then the Java primitive type name is returned. If the type is an array, only the root component type name is returned.


getFullName

public abstract String getFullName()
Returns the class name for this descriptor. If the type is primitive, then the Java primitive type name is returned. If the type is an array, "[]" is append at the end of the name for each dimension.


getTypeCode

public abstract int getTypeCode()
Returns a type code for operating on primitive types in switches. If not primitive, OBJECT_CODE is returned.


isPrimitive

public abstract boolean isPrimitive()
Returns true if this is a primitive type.


isDoubleWord

public abstract boolean isDoubleWord()
Returns true if this is a primitive long or double type.


isArray

public abstract boolean isArray()
Returns true if this is an array type.


getDimensions

public abstract int getDimensions()
Returns the number of dimensions this array type has. If not an array, zero is returned.


getComponentType

public abstract TypeDesc getComponentType()
Returns the component type of this array type. If not an array, null is returned.


getRootComponentType

public abstract TypeDesc getRootComponentType()
Returns the root component type of this array type. If not an array, null is returned.


toArrayType

public abstract TypeDesc toArrayType()
Convertes this type to an array type. If already an array, another dimension is added.


toObjectType

public abstract TypeDesc toObjectType()
Returns the object peer of this primitive type. For int, the object peer is java.lang.Integer. If this type is an object type, it is simply returned.


toPrimitiveType

public abstract TypeDesc toPrimitiveType()
Returns the primitive peer of this object type, if one exists. For java.lang.Integer, the primitive peer is int. If this type is a primitive type, it is simply returned. Arrays have no primitive peer, and so null is returned instead.


toClass

public abstract Class toClass()
Returns this type as a class. If the class isn't found, null is returned.


toClass

public abstract Class toClass(ClassLoader loader)
Returns this type as a class. If the class isn't found, null is returned.

Parameters:
loader - optional ClassLoader to load class from

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object other)
Overrides:
equals in class Object


Copyright © 2004-2011 Brian S O'Neill. All Rights Reserved.