Package org.openjdk.jmc.common.util
Class MethodToolkit
- java.lang.Object
-
- org.openjdk.jmc.common.util.MethodToolkit
-
public class MethodToolkit extends java.lang.ObjectHelper class to supportIMCTypeandIMCMethodimplementations 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.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String[]PRIMITIVE_TYPESprivate static java.lang.StringTYPE_BOOLEANprivate static java.lang.StringTYPE_BYTEprivate static java.lang.StringTYPE_CHARprivate static java.lang.StringTYPE_DOUBLEprivate static java.lang.StringTYPE_FLOATprivate static java.lang.StringTYPE_INTEGERprivate static java.lang.StringTYPE_LONGprivate static java.lang.StringTYPE_SHORTprivate static java.lang.StringTYPE_VOID
-
Constructor Summary
Constructors Modifier Constructor Description privateMethodToolkit()Do not instantiate.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringbinaryNameToCanonical(java.lang.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(java.lang.CharSequence desc, int start, java.lang.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 java.lang.StringfieldDescToBinaryJLS(java.lang.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 java.lang.StringformatQualifiedName(IMCPackage mcPackage, java.lang.String className)Create a fully qualified class name based on a package.private static java.lang.StringformatQualifiedName(IMCPackage mcPackage, java.lang.String className, char separator)Create a fully qualified class name based on a package.static java.lang.BooleanhasNestedTypes(java.lang.String className)Check if a class name denotes a nested class.static java.lang.BooleanisArray(java.lang.String typeName)Check if a type name denotes an array.static booleanisDescOrRefArray(java.lang.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(java.lang.String fieldDesc)Check if a field descriptor according to The Java Virtual Machine Specification, Section 4.3.2, designates a primitive type.static booleanisPrimitive(java.lang.String typeName)Check if a type name denotes a primitive type.static java.lang.StringnestedTypes(java.lang.String className)Get the nested type name of a class.static java.lang.StringrefTypeToBinaryJLS(java.lang.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 java.lang.StringrefTypeToFieldDescriptor(java.lang.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 java.lang.StringtopLevelType(java.lang.String className)Get the top level type of a class.static IMCTypetypeFromBinaryJLS(java.lang.String jlsType)Convert a binary Java type name according to The Java Language Specification, Section 13.1, into anIMCType.static IMCTypetypeFromReference(java.lang.String refType)Convert a reference type according to The Java Virtual Machine Specification, Section 4.4.1, into anIMCType.
-
-
-
Field Detail
-
TYPE_VOID
private static final java.lang.String TYPE_VOID
-
TYPE_BOOLEAN
private static final java.lang.String TYPE_BOOLEAN
-
TYPE_BYTE
private static final java.lang.String TYPE_BYTE
-
TYPE_CHAR
private static final java.lang.String TYPE_CHAR
-
TYPE_SHORT
private static final java.lang.String TYPE_SHORT
-
TYPE_INTEGER
private static final java.lang.String TYPE_INTEGER
-
TYPE_LONG
private static final java.lang.String TYPE_LONG
-
TYPE_FLOAT
private static final java.lang.String TYPE_FLOAT
-
TYPE_DOUBLE
private static final java.lang.String TYPE_DOUBLE
-
PRIMITIVE_TYPES
private static final java.lang.String[] PRIMITIVE_TYPES
-
-
Method Detail
-
isPrimitive
public static boolean isPrimitive(java.lang.String typeName)
Check if a type name denotes a primitive type.- Parameters:
typeName- type name to check- Returns:
trueif the type is primitive,falseif not
-
formatQualifiedName
public static java.lang.String formatQualifiedName(IMCPackage mcPackage, java.lang.String className)
Create a fully qualified class name based on a package.- Parameters:
mcPackage- package for the classclassName- class name- Returns:
- a fully qualified class name
-
formatQualifiedName
private static java.lang.String formatQualifiedName(IMCPackage mcPackage, java.lang.String className, char separator)
Create a fully qualified class name based on a package.- Parameters:
mcPackage- package for the classclassName- class nameseparator- The separator to use between elements in the class name. Typically only '.' and '/' are useful.- Returns:
- a fully qualified class name
-
hasNestedTypes
public static java.lang.Boolean hasNestedTypes(java.lang.String className)
Check if a class name denotes a nested class.- Parameters:
className- class name to check- Returns:
trueif the class is nested,falseif not
-
topLevelType
public static java.lang.String topLevelType(java.lang.String className)
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
public static java.lang.String nestedTypes(java.lang.String className)
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
public static java.lang.Boolean isArray(java.lang.String typeName)
Check if a type name denotes an array.- Parameters:
typeName- type name to check- Returns:
trueif the type is an array,falseif not
-
refTypeToFieldDescriptor
public static java.lang.String refTypeToFieldDescriptor(java.lang.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.- Parameters:
refType- the reference type to convert- Returns:
- the corresponding field descriptor
-
binaryNameToCanonical
public static java.lang.String binaryNameToCanonical(java.lang.String binaryName)
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
public static java.lang.String refTypeToBinaryJLS(java.lang.String refType) throws java.lang.IllegalArgumentExceptionConvert 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:
java.lang.IllegalArgumentException- ifrefTypeis not a valid reference type
-
typeFromReference
public static IMCType typeFromReference(java.lang.String refType) throws java.lang.IllegalArgumentException
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:
java.lang.IllegalArgumentException- ifrefTypeis not a valid reference type
-
typeFromBinaryJLS
public static IMCType typeFromBinaryJLS(java.lang.String jlsType) throws java.lang.IllegalArgumentException
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:
java.lang.IllegalArgumentException- ifrefTypeis not a valid reference type
-
fieldDescToBinaryJLS
public static java.lang.String fieldDescToBinaryJLS(java.lang.String fieldDesc) throws java.lang.IllegalArgumentExceptionConvert 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:
java.lang.IllegalArgumentException- iffieldDescis not a valid field descriptor
-
fieldDescToBinaryJLS
public static int fieldDescToBinaryJLS(java.lang.CharSequence desc, int start, java.lang.Appendable out) throws java.lang.IllegalArgumentException, java.io.IOExceptionConvert 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:
java.lang.IllegalArgumentException- ifdescis not a valid field descriptorjava.io.IOException- If an I/O error occurs when appending toout. Note that this cannot happen when usingStringBuilderorStringBuffer.
-
isDescOrRefArray
public static boolean isDescOrRefArray(java.lang.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.- 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
public static boolean isDescPrimitive(java.lang.String fieldDesc)
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
-
-