Package javassist.bytecode
Class Descriptor
java.lang.Object
javassist.bytecode.Descriptor
A support class for dealing with descriptors.
See chapter 4.3 in "The Java Virtual Machine Specification (2nd ed.)"
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
appendParameter
(String classname, String desc) Appends a parameter type to the parameter list represented by the given descriptor.static String
appendParameter
(CtClass type, String descriptor) Appends a parameter type to the parameter list represented by the given descriptor.static int
arrayDimension
(String desc) Computes the dimension of the array represented by the given descriptor.static String
changeReturnType
(String classname, String desc) Changes the return type included in the given descriptor.static int
Computes the data size specified by the given descriptor.static boolean
eqParamTypes
(String desc1, String desc2) Returns true if the list of the parameter types of desc1 is equal to that of desc2.static String
getParamDescriptor
(String decl) Returns the signature of the given descriptor.static CtClass[]
getParameterTypes
(String desc, ClassPool cp) Returns theCtClass
objects representing the parameter types specified by the given descriptor.static CtClass
getReturnType
(String desc, ClassPool cp) Returns theCtClass
object representing the return type specified by the given descriptor.static String
insertParameter
(String classname, String desc) Inserts a parameter type at the beginning of the parameter list represented by the given descriptor.static String
insertParameter
(CtClass type, String descriptor) Inserts a parameter type at the beginning of the parameter list represented by the given descriptor.static int
numOfParameters
(String desc) Returns the number of the prameters included in the given descriptor.static String
Converts to a descriptor from a Java class namestatic String
Returns the descriptor representing the given type.static String
ofConstructor
(CtClass[] paramTypes) Returns the descriptor representing a constructor receiving the given parameter types.static String
Returns the descriptor representing a method that receives the given parameter types and returns the given type.static String
ofParameters
(CtClass[] paramTypes) Returns the descriptor representing a list of parameter types.static int
Computes the data size of parameters.static String
Substitutes a class name in the given descriptor string.static String
Substitutes class names in the given descriptor string according to the givenmap
.static String
toArrayComponent
(String desc, int dim) Returns the descriptor of the type of the array component.static String
toClassName
(String descriptor) Converts to a Java class name from a descriptor.static CtClass
Returns aCtClass
object representing the type specified by the given descriptor.static String
toJavaName
(String classname) Converts a class name from the internal representation used in the JVM to the normal one used in Java.static String
Converts a class name into the internal representation used in the JVM.static String
Returns the internal representation of the class name in the JVM.static String
Returns a human-readable representation of the given descriptor.
-
Constructor Details
-
Descriptor
public Descriptor()
-
-
Method Details
-
toJvmName
Converts a class name into the internal representation used in the JVM.Note that
toJvmName(toJvmName(s))
is equivalent totoJvmName(s)
. -
toJavaName
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, usetoClassName()
.- See Also:
-
toJvmName
Returns the internal representation of the class name in the JVM. -
toClassName
Converts to a Java class name from a descriptor.- Parameters:
descriptor
- type descriptor.
-
of
Converts to a descriptor from a Java class name -
rename
Substitutes a class name in the given descriptor string.- Parameters:
desc
- descriptor stringoldname
- replaced JVM class namenewname
- substituted JVM class name- See Also:
-
rename
Substitutes class names in the given descriptor string according to the givenmap
.- Parameters:
map
- a map between replaced and substituted JVM class names.- See Also:
-
of
Returns the descriptor representing the given type. -
ofConstructor
Returns the descriptor representing a constructor receiving the given parameter types.- Parameters:
paramTypes
- parameter types
-
ofMethod
Returns the descriptor representing a method that receives the given parameter types and returns the given type.- Parameters:
returnType
- return typeparamTypes
- parameter types
-
ofParameters
Returns the descriptor representing a list of parameter types. For example, if the given parameter types are twoint
, then this method returns"(II)"
.- Parameters:
paramTypes
- parameter types
-
appendParameter
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
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
- parameter type (not primitive type)desc
- descriptor
-
appendParameter
Appends a parameter type to the parameter list represented by the given descriptor. The appended parameter becomes the last parameter.- Parameters:
type
- the type of the appended parameter.descriptor
- the original descriptor.
-
insertParameter
Inserts a parameter type at the beginning of the parameter list represented by the given descriptor.- Parameters:
type
- the type of the inserted parameter.descriptor
- the descriptor of the method.
-
changeReturnType
Changes the return type included in the given descriptor.classname
must not be an array type.- Parameters:
classname
- return typedesc
- descriptor
-
getParameterTypes
Returns theCtClass
objects representing the parameter types specified by the given descriptor.- Parameters:
desc
- descriptorcp
- the class pool used for obtaining aCtClass
object.- Throws:
NotFoundException
-
eqParamTypes
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. -
getParamDescriptor
Returns the signature of the given descriptor. The signature does not include the return type. For example, the signature of "(I)V" is "(I)". -
getReturnType
Returns theCtClass
object representing the return type specified by the given descriptor.- Parameters:
desc
- descriptorcp
- the class pool used for obtaining aCtClass
object.- Throws:
NotFoundException
-
numOfParameters
Returns the number of the prameters included in the given descriptor.- Parameters:
desc
- descriptor
-
toCtClass
Returns aCtClass
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 acceptsLjava.lang.Object;
as well asLjava/lang/Object;
.- Parameters:
desc
- descriptor.cp
- the class pool used for obtaining aCtClass
object.- Throws:
NotFoundException
-
arrayDimension
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
- the descriptor.- Returns:
- 0 if the descriptor does not represent an array type.
-
toArrayComponent
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
- the descriptor.dim
- the array dimension.
-
dataSize
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
-
paramSize
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
- a method descriptor.
-
toString
Returns a human-readable representation of the given descriptor. For example,Ljava/lang/Object;
is converted intojava.lang.Object
.(I[I)V
is converted into(int, int[])
(the return type is ignored).
-