Top Description Inners Constructors Methods
javassist.bytecode

public Class Descriptor

extends Object
Class Inheritance
Imports
java.util.Map, javassist.ClassPool, .CtClass, .CtPrimitiveType, .NotFoundException

A support class for dealing with descriptors.

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Descriptor.Iterator

An Iterator over a descriptor.

pack-priv static class

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static String
appendParameter(String
parameter type (not primitive type)
classname
,
String
descriptor
desc
)

Appends a parameter type to the parameter list represented by the given descriptor.

public static String
appendParameter(CtClass
the type of the appended parameter.
type
,
String
the original descriptor.
descriptor
)

Appends a parameter type to the parameter list represented by the given descriptor.

public static int

Returns:

0 if the descriptor does not represent an array type.
arrayDimension
(String
the descriptor.
desc
)

Computes the dimension of the array represented by the given descriptor.

public static String
changeReturnType(String
return type
classname
,
String
descriptor
desc
)

Changes the return type included in the given descriptor.

public static int
dataSize(String
descriptor
desc
)

Computes the data size specified by the given descriptor.

private static int
dataSize(String desc, boolean withRet)

public static boolean
eqParamTypes(String desc1, String desc2)

Returns true if the list of the parameter types of desc1 is equal to that of desc2.

public static String
getParamDescriptor(String decl)

Returns the signature of the given descriptor.

public static CtClass[]
getParameterTypes(String
descriptor
desc
,
ClassPool
the class pool used for obtaining a CtClass object.
cp
)

Returns the CtClass objects representing the parameter types specified by the given descriptor.

public static CtClass
getReturnType(String
descriptor
desc
,
ClassPool
the class pool used for obtaining a CtClass object.
cp
)

Returns the CtClass object representing the return type specified by the given descriptor.

public static String
insertParameter(String
parameter type (not primitive type)
classname
,
String
descriptor
desc
)

Inserts a parameter type at the beginning of the parameter list represented by the given descriptor.

public static String
insertParameter(CtClass
the type of the inserted parameter.
type
,
String
the descriptor of the method.
descriptor
)

Inserts a parameter type at the beginning of the parameter list represented by the given descriptor.

public static int
numOfParameters(String
descriptor
desc
)

Returns the number of the prameters included in the given descriptor.

public static String
of(String classname)

Converts to a descriptor from a Java class name

public static String
of(CtClass type)

Returns the descriptor representing the given type.

public static String
ofConstructor(CtClass[]
parameter types
paramTypes
)

Returns the descriptor representing a constructor receiving the given parameter types.

public static String
ofMethod(CtClass
return type
returnType
,
CtClass[]
parameter types
paramTypes
)

Returns the descriptor representing a method that receives the given parameter types and returns the given type.

public static String
ofParameters(CtClass[]
parameter types
paramTypes
)

Returns the descriptor representing a list of parameter types.

public static int
paramSize(String
a method descriptor.
desc
)

Computes the data size of parameters.

public static String
rename(String
descriptor string
desc
,
String
replaced JVM class name
oldname
,
String
substituted JVM class name
newname
)

Substitutes a class name in the given descriptor string.

public static String
rename(String desc, Map<String, String>
a map between replaced and substituted JVM class names.
map
)

Substitutes class names in the given descriptor string according to the given map.

public static String
toArrayComponent(String
the descriptor.
desc
,
int
the array dimension.
dim
)

Returns the descriptor of the type of the array component.

public static String
toClassName(String
type descriptor.
descriptor
)

Converts to a Java class name from a descriptor.

public static CtClass
toCtClass(String
descriptor.
desc
,
ClassPool
the class pool used for obtaining a CtClass object.
cp
)

Returns a CtClass object representing the type specified by the given descriptor.

private static int
toCtClass(ClassPool cp, String desc, int i, CtClass[] args, int n)

private static void
public static String
toJavaName(String classname)

Converts a class name from the internal representation used in the JVM to the normal one used in Java.

public static String
toJvmName(String classname)

Converts a class name into the internal representation used in the JVM.

public static String
toJvmName(CtClass clazz)

Returns the internal representation of the class name in the JVM.

pack-priv static CtClass
public static String
toString(String desc)

Returns a human-readable representation of the given descriptor.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Descriptorback to summary
public Descriptor()

Method Detail

appendParameterback to summary
public static String appendParameter(String classname, String desc)

Appends a parameter type to the parameter list represented by the given descriptor.

classname must not be an array type.

Parameters
classname:String

parameter type (not primitive type)

desc:String

descriptor

appendParameterback to summary
public static String appendParameter(CtClass type, String descriptor)

Appends a parameter type to the parameter list represented by the given descriptor. The appended parameter becomes the last parameter.

Parameters
type:CtClass

the type of the appended parameter.

descriptor:String

the original descriptor.

arrayDimensionback to summary
public static int arrayDimension(String desc)

Computes the dimension of the array represented by the given descriptor. For example, if the descriptor is "[[I", then this method returns 2.

Parameters
desc:String

the descriptor.

Returns:int

0 if the descriptor does not represent an array type.

changeReturnTypeback to summary
public static String changeReturnType(String classname, String desc)

Changes the return type included in the given descriptor.

classname must not be an array type.

Parameters
classname:String

return type

desc:String

descriptor

dataSizeback to summary
public static int dataSize(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:String

descriptor

dataSizeback to summary
private static int dataSize(String desc, boolean withRet)
eqParamTypesback to summary
public static boolean eqParamTypes(String desc1, String desc2)

Returns true if the list of the parameter types of desc1 is equal to that of desc2. For example, "(II)V" and "(II)I" are equal.

getParamDescriptorback to summary
public static String getParamDescriptor(String decl)

Returns the signature of the given descriptor. The signature does not include the return type. For example, the signature of "(I)V" is "(I)".

getParameterTypesback to summary
public static CtClass[] getParameterTypes(String desc, ClassPool cp) throws NotFoundException

Returns the CtClass objects representing the parameter types specified by the given descriptor.

Parameters
desc:String

descriptor

cp:ClassPool

the class pool used for obtaining a CtClass object.

getReturnTypeback to summary
public static CtClass getReturnType(String desc, ClassPool cp) throws NotFoundException

Returns the CtClass object representing the return type specified by the given descriptor.

Parameters
desc:String

descriptor

cp:ClassPool

the class pool used for obtaining a CtClass object.

insertParameterback to summary
public static String insertParameter(String classname, String desc)

Inserts a parameter type at the beginning of the parameter list represented by the given descriptor.

classname must not be an array type.

Parameters
classname:String

parameter type (not primitive type)

desc:String

descriptor

insertParameterback to summary
public static String insertParameter(CtClass type, String descriptor)

Inserts a parameter type at the beginning of the parameter list represented by the given descriptor.

Parameters
type:CtClass

the type of the inserted parameter.

descriptor:String

the descriptor of the method.

numOfParametersback to summary
public static int numOfParameters(String desc)

Returns the number of the prameters included in the given descriptor.

Parameters
desc:String

descriptor

ofback to summary
public static String of(String classname)

Converts to a descriptor from a Java class name

ofback to summary
public static String of(CtClass type)

Returns the descriptor representing the given type.

ofConstructorback to summary
public static String ofConstructor(CtClass[] paramTypes)

Returns the descriptor representing a constructor receiving the given parameter types.

Parameters
paramTypes:CtClass[]

parameter types

ofMethodback to summary
public static String ofMethod(CtClass returnType, CtClass[] paramTypes)

Returns the descriptor representing a method that receives the given parameter types and returns the given type.

Parameters
returnType:CtClass

return type

paramTypes:CtClass[]

parameter types

ofParametersback to summary
public static String ofParameters(CtClass[] 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:CtClass[]

parameter types

paramSizeback to summary
public static int paramSize(String desc)

Computes the data size of parameters. If one of the parameters is double type, the size of that parameter is 2 words. For example, if the given descriptor is "(IJ)D", then this method returns 3. The size of the return type is not computed.

Parameters
desc:String

a method descriptor.

renameback to summary
public static String rename(String desc, String oldname, String newname)

Substitutes a class name in the given descriptor string.

Parameters
desc:String

descriptor string

oldname:String

replaced JVM class name

newname:String

substituted JVM class name

See Also
Descriptor#toJvmName(String)
renameback to summary
public static String rename(String desc, Map<String, String> map)

Substitutes class names in the given descriptor string according to the given map.

Parameters
map:Map<String, String>

a map between replaced and substituted JVM class names.

See Also
Descriptor#toJvmName(String)
toArrayComponentback to summary
public static String toArrayComponent(String desc, int dim)

Returns the descriptor of the type of the array component. For example, if the given descriptor is "[[Ljava/lang/String;" and the given dimension is 2, then this method returns "Ljava/lang/String;".

Parameters
desc:String

the descriptor.

dim:int

the array dimension.

toClassNameback to summary
public static String toClassName(String descriptor)

Converts to a Java class name from a descriptor.

Parameters
descriptor:String

type descriptor.

toCtClassback to summary
public static CtClass toCtClass(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:String

descriptor.

cp:ClassPool

the class pool used for obtaining a CtClass object.

toCtClassback to summary
private static int toCtClass(ClassPool cp, String desc, int i, CtClass[] args, int n) throws NotFoundException
toDescriptorback to summary
private static void toDescriptor(StringBuilder desc, CtClass type)
toJavaNameback to summary
public static String toJavaName(String classname)

Converts a class name from the internal representation used in the JVM to the normal one used in Java. This method does not deal with an array type name such as "[Ljava/lang/Object;" and "[I;". For such names, use toClassName().

See Also
toClassName(String)
toJvmNameback to summary
public static String toJvmName(String classname)

Converts a class name into the internal representation used in the JVM.

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

toJvmNameback to summary
public static String toJvmName(CtClass clazz)

Returns the internal representation of the class name in the JVM.

toPrimitiveClassback to summary
pack-priv static CtClass toPrimitiveClass(char c)
toStringback to summary
public static String toString(String desc)

Returns a human-readable representation of the given descriptor. For example, Ljava/lang/Object; is converted into java.lang.Object. (I[I)V is converted into (int, int[]) (the return type is ignored).

javassist.bytecode back to summary

public Class Descriptor.Iterator

extends Object
Class Inheritance

An Iterator over a descriptor.

Field Summary

Modifier and TypeField and Description
private int
private String
private int
private boolean

Constructor Summary

AccessConstructor and Description
public
Iterator(String
descriptor.
s
)

Constructs an iterator.

Method Summary

Modifier and TypeMethod and Description
public char
currentChar()

Returns the first character of the current element.

public boolean
hasNext()

Returns true if the iteration has more elements.

public boolean
is2byte()

Returns true if the current element is double or long type.

public boolean
isParameter()

Returns true if the current element is a parameter type.

public int
next()

Returns the position of the next type character.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

curPosback to summary
private int curPos
descback to summary
private String desc
indexback to summary
private int index
paramback to summary
private boolean param

Constructor Detail

Iteratorback to summary
public Iterator(String s)

Constructs an iterator.

Parameters
s:String

descriptor.

Method Detail

currentCharback to summary
public char currentChar()

Returns the first character of the current element.

hasNextback to summary
public boolean hasNext()

Returns true if the iteration has more elements.

is2byteback to summary
public boolean is2byte()

Returns true if the current element is double or long type.

isParameterback to summary
public boolean isParameter()

Returns true if the current element is a parameter type.

nextback to summary
public int next()

Returns the position of the next type character. That type character becomes a new current element.

javassist.bytecode back to summary

pack-priv Class Descriptor.PrettyPrinter

extends Object
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
pack-priv static int
readType(StringBuilder sbuf, int pos, String desc)

pack-priv static String
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

PrettyPrinterback to summary
pack-priv PrettyPrinter()

Method Detail

readTypeback to summary
pack-priv static int readType(StringBuilder sbuf, int pos, String desc)
toStringback to summary
pack-priv static String toString(String desc)