Package org.openjdk.jmc.common.util
Class MethodToolkit
java.lang.Object
org.openjdk.jmc.common.util.MethodToolkit
Helper class to support
IMCType and IMCMethod implementations and to handle
conversion of reference types and field descriptors according to The Java Virtual Machine
Specification, Section 4.4.1 and Section 4.3.2, respectively, into Java type formats
according to The Java Language Specification, Sections 6.7 and 13.1.-
Method Summary
Modifier and TypeMethodDescriptionstatic StringbinaryNameToCanonical(String binaryName) Convert a binary name to a canonical name, as defined in The Java Language Specification, Sections 6.7 and 13.1, respectively.static intfieldDescToBinaryJLS(CharSequence desc, int start, Appendable out) Convert the field descriptor, according to The Java Virtual Machine Specification, Section 4.3.2, starting at positionstartindesc, into a binary Java type name according to The Java Language Specification, Section 13.1.static StringfieldDescToBinaryJLS(String fieldDesc) Convert a field descriptor according to The Java Virtual Machine Specification, Section 4.3.2, into a binary Java type name according to The Java Language Specification, Section 13.1.static StringformatQualifiedName(IMCPackage mcPackage, String className) Create a fully qualified class name based on a package.static BooleanhasNestedTypes(String className) Check if a class name denotes a nested class.static BooleanCheck if a type name denotes an array.static booleanisDescOrRefArray(String fieldDesc) Check if a field descriptor or a reference type according to The Java Virtual Machine Specification, Sections 4.3.2 and 4.4.1 respectively, designates an array.static booleanisDescPrimitive(String fieldDesc) Check if a field descriptor according to The Java Virtual Machine Specification, Section 4.3.2, designates a primitive type.static booleanisPrimitive(String typeName) Check if a type name denotes a primitive type.static StringnestedTypes(String className) Get the nested type name of a class.static StringrefTypeToBinaryJLS(String refType) Convert a reference type according to The Java Virtual Machine Specification, Section 4.4.1, into a binary Java type name according to The Java Language Specification, Section 13.1.static StringrefTypeToFieldDescriptor(String refType) Convert a reference type according to The Java Virtual Machine Specification, Section 4.4.1, into a field descriptor according to The Java Virtual Machine Specification, Section 4.3.2.static StringtopLevelType(String className) Get the top level type of a class.static IMCTypetypeFromBinaryJLS(String jlsType) Convert a binary Java type name according to The Java Language Specification, Section 13.1, into anIMCType.static IMCTypetypeFromReference(String refType) Convert a reference type according to The Java Virtual Machine Specification, Section 4.4.1, into anIMCType.
-
Method Details
-
isPrimitive
Check if a type name denotes a primitive type.- Parameters:
typeName- type name to check- Returns:
trueif the type is primitive,falseif not
-
formatQualifiedName
Create a fully qualified class name based on a package.- Parameters:
mcPackage- package for the classclassName- class name- Returns:
- a fully qualified class name
-
hasNestedTypes
Check if a class name denotes a nested class.- Parameters:
className- class name to check- Returns:
trueif the class is nested,falseif not
-
topLevelType
Get the top level type of a class. This is the class name without any nested components.- Parameters:
className- class name with possible nested components- Returns:
- class name without nested components
-
nestedTypes
Get the nested type name of a class. This is the class name without the top level class name. If there are multiple nested levels then all levels will be returned.- Parameters:
className- class name with possible nested components- Returns:
- nested class name part if present,
nullif there is no nested class
-
isArray
Check if a type name denotes an array.- Parameters:
typeName- type name to check- Returns:
trueif the type is an array,falseif not
-
refTypeToFieldDescriptor
Convert a reference type according to The Java Virtual Machine Specification, Section 4.4.1, into a field descriptor according to The Java Virtual Machine Specification, Section 4.3.2.- Parameters:
refType- the reference type to convert- Returns:
- the corresponding field descriptor
-
binaryNameToCanonical
Convert a binary name to a canonical name, as defined in The Java Language Specification, Sections 6.7 and 13.1, respectively. These names only differ in that the former uses "$" as nested class separator while the latter uses ".".- Parameters:
binaryName- the binary name to convert- Returns:
- the converted canonical name
-
refTypeToBinaryJLS
Convert a reference type according to The Java Virtual Machine Specification, Section 4.4.1, into a binary Java type name according to The Java Language Specification, Section 13.1.- Parameters:
refType- the reference type to convert- Returns:
- the converted name
- Throws:
IllegalArgumentException- ifrefTypeis not a valid reference type
-
typeFromReference
Convert a reference type according to The Java Virtual Machine Specification, Section 4.4.1, into anIMCType.- Parameters:
refType- the reference type to convert- Returns:
- the type object
- Throws:
IllegalArgumentException- ifrefTypeis not a valid reference type
-
typeFromBinaryJLS
Convert a binary Java type name according to The Java Language Specification, Section 13.1, into anIMCType.- Parameters:
jlsType- the JLS type name to convert- Returns:
- the type object
- Throws:
IllegalArgumentException- ifrefTypeis not a valid reference type
-
fieldDescToBinaryJLS
Convert a field descriptor according to The Java Virtual Machine Specification, Section 4.3.2, into a binary Java type name according to The Java Language Specification, Section 13.1.- Parameters:
fieldDesc- the field descriptor (according to the JVM Specification) to convert- Returns:
- the converted type name according to JLS
- Throws:
IllegalArgumentException- iffieldDescis not a valid field descriptor
-
fieldDescToBinaryJLS
public static int fieldDescToBinaryJLS(CharSequence desc, int start, Appendable out) throws IllegalArgumentException, IOException Convert the field descriptor, according to The Java Virtual Machine Specification, Section 4.3.2, starting at positionstartindesc, into a binary Java type name according to The Java Language Specification, Section 13.1. and appends it toout.- Parameters:
desc- aCharSequencecontaining the field descriptor (according to the JVM Specification) to convertstart- the position indescwhere the descriptor to convert startsout- anAppendableto which the result will be appended- Returns:
- the first position in
descnot converted - Throws:
IllegalArgumentException- ifdescis not a valid field descriptorIOException- If an I/O error occurs when appending toout. Note that this cannot happen when usingStringBuilderorStringBuffer.
-
isDescOrRefArray
Check if a field descriptor or a reference type according to The Java Virtual Machine Specification, Sections 4.3.2 and 4.4.1 respectively, designates an array.- Parameters:
fieldDesc- a non-null field descriptor or reference type (according to the JVM Specification)- Returns:
- true iff the descriptor denotes an array type
-
isDescPrimitive
Check if a field descriptor according to The Java Virtual Machine Specification, Section 4.3.2, designates a primitive type.- Parameters:
fieldDesc- a non-null field descriptor (according to the JVM Specification)- Returns:
- true iff the descriptor denotes a primitive type
-