classUtils.javassist.bytecode
Class Descriptor

java.lang.Object
  extended by classUtils.javassist.bytecode.Descriptor

public class Descriptor
extends java.lang.Object

A support class for dealing with descriptors.

See chapter 4.3 in "The Java Virtual Machine Specification (2nd ed.)"


Constructor Summary
Descriptor()
           
 
Method Summary
static java.lang.String appendParameter(java.lang.String classname, java.lang.String desc)
          Appends a parameter type to the parameter list represented by the given descriptor.
static java.lang.String changeReturnType(java.lang.String classname, java.lang.String desc)
          Changes the return type included in the given descriptor.
static int dataSize(java.lang.String desc)
          Computes the data size specified by the given descriptor.
static CompileTimeClass[] getParameterTypes(java.lang.String desc, ClassPool cp)
          Returns the CtClass objects representing the parameter types specified by the given descriptor.
static CompileTimeClass getReturnType(java.lang.String desc, ClassPool cp)
          Returns the CtClass object representing the return type specified by the given descriptor.
static java.lang.String insertParameter(java.lang.String classname, java.lang.String desc)
          Inserts a parameter type affineTransform the beginning of the parameter list represented by the given descriptor.
static int numOfParameters(java.lang.String desc)
          Returns the number of the prameters included in the given descriptor.
static java.lang.String of(CompileTimeClass type)
          Returns the descriptor representing the given type.
static java.lang.String ofConstructor(CompileTimeClass[] paramTypes)
          Returns the descriptor representing a constructor receiving the given parameter types.
static java.lang.String ofMethod(CompileTimeClass returnType, CompileTimeClass[] paramTypes)
          Returns the descriptor representing a method that receives the given parameter types and returns the given type.
static java.lang.String ofParameters(CompileTimeClass[] paramTypes)
          Returns the descriptor representing a list of parameter types.
static java.lang.String rename(java.lang.String desc, java.util.Map map)
          Substitutes class names in the given descriptor string according to the given map.
static java.lang.String rename(java.lang.String desc, java.lang.String oldname, java.lang.String newname)
          Substitutes a class name in the given descriptor string.
static CompileTimeClass toCtClass(java.lang.String desc, ClassPool cp)
          Returns a CtClass object representing the type specified by the given descriptor.
static java.lang.String toJavaName(java.lang.String classname)
          Converts a class name from the internal representation used in the JVM to the normal one used in Java.
static java.lang.String toJvmName(CompileTimeClass clazz)
          Returns the internal representation of the class name in the JVM.
static java.lang.String toJvmName(java.lang.String classname)
          Converts a class name into the internal representation used in the JVM.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Descriptor

public Descriptor()
Method Detail

toJvmName

public static java.lang.String toJvmName(java.lang.String classname)
Converts a class name into the internal representation used in the JVM.

Note that toJvmName(toJvmName(s)) is equivalent to toJvmName(s).


toJavaName

public static java.lang.String toJavaName(java.lang.String classname)
Converts a class name from the internal representation used in the JVM to the normal one used in Java.


toJvmName

public static java.lang.String toJvmName(CompileTimeClass clazz)
Returns the internal representation of the class name in the JVM.


rename

public static java.lang.String rename(java.lang.String desc,
                                      java.lang.String oldname,
                                      java.lang.String newname)
Substitutes a class name in the given descriptor string.

Parameters:
desc - descriptor string
oldname - replaced JVM class name
newname - substituted JVM class name
See Also:
toJvmName(String)

rename

public static java.lang.String rename(java.lang.String desc,
                                      java.util.Map map)
Substitutes class names in the given descriptor string according to the given map.

Parameters:
map - a map between replaced and substituted JVM class names.
See Also:
toJvmName(String)

of

public static java.lang.String of(CompileTimeClass type)
Returns the descriptor representing the given type.


ofConstructor

public static java.lang.String ofConstructor(CompileTimeClass[] paramTypes)
Returns the descriptor representing a constructor receiving the given parameter types.

Parameters:
paramTypes - parameter types

ofMethod

public static java.lang.String ofMethod(CompileTimeClass returnType,
                                        CompileTimeClass[] paramTypes)
Returns the descriptor representing a method that receives the given parameter types and returns the given type.

Parameters:
returnType - return type
paramTypes - parameter types

ofParameters

public static java.lang.String ofParameters(CompileTimeClass[] paramTypes)
Returns the descriptor representing a list of parameter types. For example, if the given parameter types are two int, then this method returns "(II)".

Parameters:
paramTypes - parameter types

appendParameter

public static java.lang.String appendParameter(java.lang.String classname,
                                               java.lang.String desc)
Appends a parameter type to the parameter list represented by the given descriptor.

classname must not be an array type.

Parameters:
classname - parameter type (not primitive type)
desc - descriptor

insertParameter

public static java.lang.String insertParameter(java.lang.String classname,
                                               java.lang.String desc)
Inserts a parameter type affineTransform the beginning of the parameter list represented by the given descriptor.

classname must not be an array type.

Parameters:
classname - parameter type (not primitive type)
desc - descriptor

changeReturnType

public static java.lang.String changeReturnType(java.lang.String classname,
                                                java.lang.String desc)
Changes the return type included in the given descriptor.

classname must not be an array type.

Parameters:
classname - return type
desc - descriptor

getParameterTypes

public static CompileTimeClass[] getParameterTypes(java.lang.String desc,
                                                   ClassPool cp)
                                            throws NotFoundException
Returns the CtClass objects representing the parameter types specified by the given descriptor.

Parameters:
desc - descriptor
cp - the class pool used for obtaining a CtClass object.
Throws:
NotFoundException

getReturnType

public static CompileTimeClass getReturnType(java.lang.String desc,
                                             ClassPool cp)
                                      throws NotFoundException
Returns the CtClass object representing the return type specified by the given descriptor.

Parameters:
desc - descriptor
cp - the class pool used for obtaining a CtClass object.
Throws:
NotFoundException

numOfParameters

public static int numOfParameters(java.lang.String desc)
Returns the number of the prameters included in the given descriptor.

Parameters:
desc - descriptor

toCtClass

public static CompileTimeClass toCtClass(java.lang.String desc,
                                         ClassPool cp)
                                  throws NotFoundException
Returns a CtClass object representing the type specified by the given descriptor.

This method works even if the package-class separator is not / but . (period). For example, it accepts Ljava.lang.Object; as well as Ljava/lang/Object;.

Parameters:
desc - descriptor
cp - the class pool used for obtaining a CtClass object.
Throws:
NotFoundException

dataSize

public static int dataSize(java.lang.String desc)
Computes the data size specified by the given descriptor. For example, if the descriptor is "D", this method returns 2.

If the descriptor represents a method type, this method returns (the size of the returned value) - (the sum of the data sizes of all the parameters). For example, if the descriptor is "(I)D", then this method returns 1 (= 2 - 1).

Parameters:
desc - descriptor