org.logicalcobwebs.asm
Class Type

java.lang.Object
  extended by org.logicalcobwebs.asm.Type

public class Type
extends java.lang.Object

A Java type. This class can be used to make it easier to manipulate type and method descriptors.


Field Summary
static int ARRAY
          The sort of array reference types.
static int BOOLEAN
          The sort of the boolean type.
static Type BOOLEAN_TYPE
          The boolean type.
private  char[] buf
          A buffer containing the descriptor of this Java type.
static int BYTE
          The sort of the byte type.
static Type BYTE_TYPE
          The byte type.
static int CHAR
          The sort of the char type.
static Type CHAR_TYPE
          The char type.
static int DOUBLE
          The sort of the double type.
static Type DOUBLE_TYPE
          The double type.
static int FLOAT
          The sort of the float type.
static Type FLOAT_TYPE
          The float type.
static int INT
          The sort of the int type.
static Type INT_TYPE
          The int type.
private  int len
          The length of the descriptor of this Java type.
static int LONG
          The sort of the long type.
static Type LONG_TYPE
          The long type.
static int OBJECT
          The sort of object reference type.
private  int off
          The offset of the descriptor of this Java type in buf.
static int SHORT
          The sort of the short type.
static Type SHORT_TYPE
          The short type.
private  int sort
          The sort of this Java type.
static int VOID
          The sort of the void type.
static Type VOID_TYPE
          The void type.
 
Constructor Summary
private Type(int sort)
          Constructs a primitive type.
private Type(int sort, char[] buf, int off, int len)
          Constructs a reference type.
 
Method Summary
 boolean equals(java.lang.Object o)
           
static Type[] getArgumentTypes(java.lang.reflect.Method method)
          Returns the Java types corresponding to the argument types of the given method.
static Type[] getArgumentTypes(java.lang.String methodDescriptor)
          Returns the Java types corresponding to the argument types of the given method descriptor.
 java.lang.String getClassName()
          Returns the name of the class corresponding to this object type.
 java.lang.String getDescriptor()
          Returns the descriptor corresponding to this Java type.
static java.lang.String getDescriptor(java.lang.Class c)
          Returns the descriptor corresponding to the given Java type.
private  void getDescriptor(java.lang.StringBuffer buf)
          Appends the descriptor corresponding to this Java type to the given string buffer.
private static void getDescriptor(java.lang.StringBuffer buf, java.lang.Class c)
          Appends the descriptor of the given class to the given string buffer.
 int getDimensions()
          Returns the number of dimensions of this array type.
 Type getElementType()
          Returns the type of the elements of this array type.
 java.lang.String getInternalName()
          Returns the internal name of the class corresponding to this object type.
static java.lang.String getInternalName(java.lang.Class c)
          Returns the internal name of the given class.
static java.lang.String getMethodDescriptor(java.lang.reflect.Method m)
          Returns the descriptor corresponding to the given method.
static java.lang.String getMethodDescriptor(Type returnType, Type[] argumentTypes)
          Returns the descriptor corresponding to the given argument and return types.
 int getOpcode(int opcode)
          Returns a JVM instruction opcode adapted to this Java type.
static Type getReturnType(java.lang.reflect.Method method)
          Returns the Java type corresponding to the return type of the given method.
static Type getReturnType(java.lang.String methodDescriptor)
          Returns the Java type corresponding to the return type of the given method descriptor.
 int getSize()
          Returns the size of values of this type.
 int getSort()
          Returns the sort of this Java type.
private static Type getType(char[] buf, int off)
          Returns the Java type corresponding to the given type descriptor.
static Type getType(java.lang.Class c)
          Returns the Java type corresponding to the given class.
static Type getType(java.lang.String typeDescriptor)
          Returns the Java type corresponding to the given type descriptor.
 int hashCode()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VOID

public static final int VOID
The sort of the void type. See getSort.

See Also:
Constant Field Values

BOOLEAN

public static final int BOOLEAN
The sort of the boolean type. See getSort.

See Also:
Constant Field Values

CHAR

public static final int CHAR
The sort of the char type. See getSort.

See Also:
Constant Field Values

BYTE

public static final int BYTE
The sort of the byte type. See getSort.

See Also:
Constant Field Values

SHORT

public static final int SHORT
The sort of the short type. See getSort.

See Also:
Constant Field Values

INT

public static final int INT
The sort of the int type. See getSort.

See Also:
Constant Field Values

FLOAT

public static final int FLOAT
The sort of the float type. See getSort.

See Also:
Constant Field Values

LONG

public static final int LONG
The sort of the long type. See getSort.

See Also:
Constant Field Values

DOUBLE

public static final int DOUBLE
The sort of the double type. See getSort.

See Also:
Constant Field Values

ARRAY

public static final int ARRAY
The sort of array reference types. See getSort.

See Also:
Constant Field Values

OBJECT

public static final int OBJECT
The sort of object reference type. See getSort.

See Also:
Constant Field Values

VOID_TYPE

public static final Type VOID_TYPE
The void type.


BOOLEAN_TYPE

public static final Type BOOLEAN_TYPE
The boolean type.


CHAR_TYPE

public static final Type CHAR_TYPE
The char type.


BYTE_TYPE

public static final Type BYTE_TYPE
The byte type.


SHORT_TYPE

public static final Type SHORT_TYPE
The short type.


INT_TYPE

public static final Type INT_TYPE
The int type.


FLOAT_TYPE

public static final Type FLOAT_TYPE
The float type.


LONG_TYPE

public static final Type LONG_TYPE
The long type.


DOUBLE_TYPE

public static final Type DOUBLE_TYPE
The double type.


sort

private final int sort
The sort of this Java type.


buf

private char[] buf
A buffer containing the descriptor of this Java type. This field is only used for reference types.


off

private int off
The offset of the descriptor of this Java type in buf. This field is only used for reference types.


len

private int len
The length of the descriptor of this Java type.

Constructor Detail

Type

private Type(int sort)
Constructs a primitive type.

Parameters:
sort - the sort of the primitive type to be constructed.

Type

private Type(int sort,
             char[] buf,
             int off,
             int len)
Constructs a reference type.

Parameters:
sort - the sort of the reference type to be constructed.
buf - a buffer containing the descriptor of the previous type.
off - the offset of this descriptor in the previous buffer.
len - the length of this descriptor.
Method Detail

getType

public static Type getType(java.lang.String typeDescriptor)
Returns the Java type corresponding to the given type descriptor.

Parameters:
typeDescriptor - a type descriptor.
Returns:
the Java type corresponding to the given type descriptor.

getType

public static Type getType(java.lang.Class c)
Returns the Java type corresponding to the given class.

Parameters:
c - a class.
Returns:
the Java type corresponding to the given class.

getArgumentTypes

public static Type[] getArgumentTypes(java.lang.String methodDescriptor)
Returns the Java types corresponding to the argument types of the given method descriptor.

Parameters:
methodDescriptor - a method descriptor.
Returns:
the Java types corresponding to the argument types of the given method descriptor.

getArgumentTypes

public static Type[] getArgumentTypes(java.lang.reflect.Method method)
Returns the Java types corresponding to the argument types of the given method.

Parameters:
method - a method.
Returns:
the Java types corresponding to the argument types of the given method.

getReturnType

public static Type getReturnType(java.lang.String methodDescriptor)
Returns the Java type corresponding to the return type of the given method descriptor.

Parameters:
methodDescriptor - a method descriptor.
Returns:
the Java type corresponding to the return type of the given method descriptor.

getReturnType

public static Type getReturnType(java.lang.reflect.Method method)
Returns the Java type corresponding to the return type of the given method.

Parameters:
method - a method.
Returns:
the Java type corresponding to the return type of the given method.

getType

private static Type getType(char[] buf,
                            int off)
Returns the Java type corresponding to the given type descriptor.

Parameters:
buf - a buffer containing a type descriptor.
off - the offset of this descriptor in the previous buffer.
Returns:
the Java type corresponding to the given type descriptor.

getSort

public int getSort()
Returns the sort of this Java type.

Returns:
VOID, BOOLEAN, CHAR, BYTE, SHORT, INT, FLOAT, LONG, DOUBLE, ARRAY or OBJECT.

getDimensions

public int getDimensions()
Returns the number of dimensions of this array type. This method should only be used for an array type.

Returns:
the number of dimensions of this array type.

getElementType

public Type getElementType()
Returns the type of the elements of this array type. This method should only be used for an array type.

Returns:
Returns the type of the elements of this array type.

getClassName

public java.lang.String getClassName()
Returns the name of the class corresponding to this object type. This method should only be used for an object type.

Returns:
the fully qualified name of the class corresponding to this object type.

getInternalName

public java.lang.String getInternalName()
Returns the internal name of the class corresponding to this object type. The internal name of a class is its fully qualified name, where '.' are replaced by '/'. * This method should only be used for an object type.

Returns:
the internal name of the class corresponding to this object type.

getDescriptor

public java.lang.String getDescriptor()
Returns the descriptor corresponding to this Java type.

Returns:
the descriptor corresponding to this Java type.

getMethodDescriptor

public static java.lang.String getMethodDescriptor(Type returnType,
                                                   Type[] argumentTypes)
Returns the descriptor corresponding to the given argument and return types.

Parameters:
returnType - the return type of the method.
argumentTypes - the argument types of the method.
Returns:
the descriptor corresponding to the given argument and return types.

getDescriptor

private void getDescriptor(java.lang.StringBuffer buf)
Appends the descriptor corresponding to this Java type to the given string buffer.

Parameters:
buf - the string buffer to which the descriptor must be appended.

getInternalName

public static java.lang.String getInternalName(java.lang.Class c)
Returns the internal name of the given class. The internal name of a class is its fully qualified name, where '.' are replaced by '/'.

Parameters:
c - an object class.
Returns:
the internal name of the given class.

getDescriptor

public static java.lang.String getDescriptor(java.lang.Class c)
Returns the descriptor corresponding to the given Java type.

Parameters:
c - an object class, a primitive class or an array class.
Returns:
the descriptor corresponding to the given class.

getMethodDescriptor

public static java.lang.String getMethodDescriptor(java.lang.reflect.Method m)
Returns the descriptor corresponding to the given method.

Parameters:
m - a Method object.
Returns:
the descriptor of the given method.

getDescriptor

private static void getDescriptor(java.lang.StringBuffer buf,
                                  java.lang.Class c)
Appends the descriptor of the given class to the given string buffer.

Parameters:
buf - the string buffer to which the descriptor must be appended.
c - the class whose descriptor must be computed.

getSize

public int getSize()
Returns the size of values of this type.

Returns:
the size of values of this type, i.e., 2 for long and double, and 1 otherwise.

getOpcode

public int getOpcode(int opcode)
Returns a JVM instruction opcode adapted to this Java type.

Parameters:
opcode - a JVM instruction opcode. This opcode must be one of ILOAD, ISTORE, IALOAD, IASTORE, IADD, ISUB, IMUL, IDIV, IREM, INEG, ISHL, ISHR, IUSHR, IAND, IOR, IXOR and IRETURN.
Returns:
an opcode that is similar to the given opcode, but adapted to this Java type. For example, if this type is float and opcode is IRETURN, this method returns FRETURN.

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object