Package proguard.classfile.util
Class ClassUtil
- java.lang.Object
-
- proguard.classfile.util.ClassUtil
-
public class ClassUtil extends java.lang.Object
Utility methods for:- Converting between internal and external representations of names and descriptions
- Operation on
Clazz
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
canonicalClassName(java.lang.String externalClassName)
Converts an external class name into a canonical class name.static void
checkMagicNumber(int magicNumber)
Checks whether the given class magic number is correct.static void
checkVersionNumbers(int internalClassVersion)
Checks whether the given class version number is supported.static int
externalArrayTypeDimensionCount(java.lang.String externalType)
Returns the number of dimensions of the given external type.static java.lang.String
externalBaseType(java.lang.String externalArrayType)
Returns the external base type of an external array type, dropping any array brackets.static java.lang.String
externalClassAccessFlags(int accessFlags)
Converts internal class access flags into an external access description.static java.lang.String
externalClassAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal class access flags into an external access description.static java.lang.String
externalClassForNameType(java.lang.String internalType)
Converts an internal type into an external type, as expected by Class.forName.static java.lang.String
externalClassName(java.lang.String internalClassName)
Converts an internal class name into an external class name.static java.lang.String
externalClassVersion(int internalClassVersion)
Returns the minor part of the given class version number.static java.lang.String
externalExportsAccessFlags(int accessFlags)
Converts internal module exports access flags into an external access description.static java.lang.String
externalExportsAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal module exports access flags into an external access description.static java.lang.String
externalFieldAccessFlags(int accessFlags)
Converts internal field access flags into an external access description.static java.lang.String
externalFieldAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal field access flags into an external access description.static java.lang.String
externalFullClassDescription(int accessFlags, java.lang.String internalClassName)
Converts an internal class description into an external class description.static java.lang.String
externalFullFieldDescription(int accessFlags, java.lang.String fieldName, java.lang.String internalFieldDescriptor)
Converts an internal field description into an external full field description.static java.lang.String
externalFullMethodDescription(java.lang.String internalClassName, int accessFlags, java.lang.String internalMethodName, java.lang.String internalMethodDescriptor)
Converts an internal method description into an external full method description.static java.lang.String
externalMethodAccessFlags(int accessFlags)
Converts internal method access flags into an external access description.static java.lang.String
externalMethodAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal method access flags into an external access description.static java.lang.String
externalMethodArguments(java.lang.String internalMethodDescriptor)
Converts an internal method descriptor into an external method argument description.static java.lang.String
externalMethodName(java.lang.String externalMethodNameAndArguments)
Returns the name part of the given external method name and arguments.static java.lang.String
externalMethodReturnType(java.lang.String internalMethodDescriptor)
Converts an internal method descriptor into an external method return type.static java.lang.String
externalModuleAccessFlags(int accessFlags)
Converts internal module access flags into an external access description.static java.lang.String
externalModuleAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal module access flags into an external access description.static java.lang.String
externalOpensAccessFlags(int accessFlags)
Converts internal module opens access flags into an external access description.static java.lang.String
externalOpensAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal module opens access flags into an external access description.static java.lang.String
externalPackageName(java.lang.String externalClassName)
Returns the external package name of the given external class name.static java.lang.String
externalPackagePrefix(java.lang.String externalClassName)
Returns the external package prefix of the given external class name.static java.lang.String
externalParameterAccessFlags(int accessFlags)
Converts internal method parameter access flags into an external access description.static java.lang.String
externalParameterAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal method parameter access flags into an external access description.static java.lang.String
externalRequiresAccessFlags(int accessFlags)
Converts internal module requires access flags into an external access description.static java.lang.String
externalRequiresAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal module requires access flags into an external access description.static java.lang.String
externalShortClassName(java.lang.String externalClassName)
Returns the external short class name of an external class name, dropping the package specification.static java.lang.String
externalType(java.lang.String internalType)
Converts an internal type into an external type.static int
internalArrayTypeDimensionCount(java.lang.String internalType)
Returns the number of dimensions of the given internal type.static java.lang.String
internalArrayTypeFromClassName(java.lang.String internalClassName, int dimensionCount)
Returns the internal array type of a given class name with a given number of dimensions.static java.lang.String
internalArrayTypeFromType(java.lang.String internalType, int dimensionDelta)
Returns the internal array type of a given type, with a given number of additional dimensions.static java.lang.String
internalClassName(java.lang.String externalClassName)
Converts an external class name into an internal class name.static java.lang.String
internalClassNameFromClassSignature(java.lang.String classSignature)
Returns the internal class name for a given Class Signature.static java.lang.String
internalClassNameFromClassType(java.lang.String internalClassType)
Returns the internal class name of a given internal class type (including an array type).static java.lang.String
internalClassNameFromType(java.lang.String internalClassType)
Returns the internal class name of any given internal descriptor type, disregarding array prefixes.static java.lang.String
internalClassTypeFromType(java.lang.String internalType)
Returns the internal class type (class name or array type) of a given internal type (including an array type).static int
internalClassVersion(int majorVersion, int minorVersion)
Returns the combined class version number.static int
internalClassVersion(java.lang.String externalClassVersion)
Returns the internal class version number.static int
internalMajorClassVersion(int internalClassVersion)
Returns the major part of the given class version number.static java.lang.String
internalMethodDescriptor(java.lang.String externalReturnType, java.lang.String externalMethodNameAndArguments)
Converts the given external method return type and name and arguments to an internal method descriptor.static java.lang.String
internalMethodDescriptor(java.lang.String externalReturnType, java.util.List<java.lang.String> externalArguments)
Converts the given external method return type and List of arguments to an internal method descriptor.static java.lang.String
internalMethodDescriptorFromInternalTypes(java.lang.String internalReturnType, java.util.List<java.lang.String> internalArguments)
Converts the given internal method return type and List of arguments to an internal method descriptor.static int
internalMethodParameterCount(java.lang.String internalMethodDescriptor)
Returns the number of parameters of the given internal method descriptor.static int
internalMethodParameterCount(java.lang.String internalMethodDescriptor, boolean isStatic)
Returns the number of parameters of the given internal method descriptor.static int
internalMethodParameterCount(java.lang.String internalMethodDescriptor, int accessFlags)
Returns the number of parameters of the given internal method descriptor.static int
internalMethodParameterNumber(java.lang.String internalMethodDescriptor, boolean isStatic, int variableIndex)
Returns the parameter number in the given internal method descriptor, corresponding to the given variable index.static int
internalMethodParameterNumber(java.lang.String internalMethodDescriptor, int accessFlags, int variableIndex)
Returns the parameter number in the given internal method descriptor, corresponding to the given variable index.static int
internalMethodParameterSize(java.lang.String internalMethodDescriptor)
Returns the size taken up on the stack by the parameters of the given internal method descriptor.static int
internalMethodParameterSize(java.lang.String internalMethodDescriptor, boolean isStatic)
Returns the size taken up on the stack by the parameters of the given internal method descriptor.static int
internalMethodParameterSize(java.lang.String internalMethodDescriptor, int accessFlags)
Returns the size taken up on the stack by the parameters of the given internal method descriptor.static java.lang.String
internalMethodParameterType(java.lang.String internalMethodDescriptor, int parameterIndex)
Returns the internal type of the parameter in the given method descriptor, at the given index.static java.lang.String
internalMethodReturnType(java.lang.String internalMethodDescriptor)
Returns the internal type of the given internal method descriptor.static int
internalMethodVariableIndex(java.lang.String internalMethodDescriptor, boolean isStatic, int parameterNumber)
Returns the parameter index in the given internal method descriptor, corresponding to the given variable number.static int
internalMethodVariableIndex(java.lang.String internalMethodDescriptor, int accessFlags, int parameterNumber)
Returns the variable index corresponding to the given parameter number in the given internal method descriptor.static int
internalMinorClassVersion(int internalClassVersion)
Returns the internal class version number.static java.lang.String
internalNumericClassNameFromPrimitiveType(char internalPrimitiveType)
Returns the internal numeric (or void or array) class name corresponding to the given internal primitive type.static java.lang.String
internalPackageName(java.lang.String internalClassName)
Returns the internal package name of the given internal class name.static java.lang.String
internalPackagePrefix(java.lang.String internalClassName)
Returns the internal package prefix of the given internal class name.static char
internalPrimitiveTypeFromNumericClassName(java.lang.String internalPrimitiveClassName)
Returns the internal numeric (or void or array) class name corresponding to the given internal primitive type.static char
internalPrimitiveTypeFromPrimitiveBoxingType(java.lang.String type)
Returns the primitive type corresponding to the given internal primitive boxing type.static int
internalPrimitiveTypeToComputationalType(java.lang.String internalPrimitiveType)
The internal primitive type computational type.static java.lang.String
internalShortClassName(java.lang.String internalClassName)
Returns the internal short class name of an internal class name, dropping the package specification.static java.lang.String
internalSimpleClassName(java.lang.String internalClassName)
Returns the simple name of an internal class name, dropping the package specification and any outer class part.static java.lang.String
internalType(java.lang.String externalType)
Converts an external type into an internal type.static java.lang.String
internalTypeFromArrayType(java.lang.String internalArrayType)
Returns the internal element type of a given internal array type.static java.lang.String
internalTypeFromClassName(java.lang.String internalClassName)
Returns the internal type of a given class name.static java.lang.String
internalTypeFromClassType(java.lang.String internalType)
Returns the internal type of a given class type (class name or array type).static int
internalTypeSize(java.lang.String internalType)
Returns the size taken up on the stack by the given internal type.static boolean
isClassInitializer(java.lang.String internalMethodName)
Returns whether the given method name refers to a class initializer.static boolean
isExtendable(Clazz clazz)
Returns `true` if aClazz
is null or if it does not represent a final class.static boolean
isExternalMethodNameAndArguments(java.lang.String externalMemberNameAndArguments)
Returns whether the given member String represents an external method name with arguments.static boolean
isInitializer(java.lang.String internalMethodName)
Returns whether the given method name refers to a class initializer or an instance initializer.static boolean
isInstanceInitializer(java.lang.String internalMethodName)
Returns whether the given method name refers to an instance initializer.static boolean
isInternalArrayInterfaceName(java.lang.String internalClassName)
Returns whether the given internal class name is one of the interfaces that is implemented by all array types.static boolean
isInternalArrayType(java.lang.String internalType)
Returns whether the given internal type is an array type.static boolean
isInternalCategory2Type(java.lang.String internalType)
Returns whether the given internal type is a primitive Category 2 type.static boolean
isInternalClassType(java.lang.String internalType)
Returns whether the given internal type is a plain class type (including an array type of a plain class type).static boolean
isInternalMethodDescriptor(java.lang.String internalDescriptor)
Returns whether the given internal descriptor String represents a method descriptor.static boolean
isInternalPrimitiveBoxingType(java.lang.String internalType)
Returns whether the given class is a class boxing a primitive type (not void).static boolean
isInternalPrimitiveType(char internalType)
Returns whether the given internal type is a plain primitive type (not void).static boolean
isInternalPrimitiveType(java.lang.String internalType)
Returns whether the given internal type is a plain primitive type (not void).static boolean
isInternalPrimitiveTypeOrString(java.lang.String internalType)
Returns whether the given internal type is a plain primitive type (not void) or a java/lang/String.static boolean
isInternalType(java.lang.String type)
Returns whether the given type is an internal type, i.e.static java.lang.String
removeGenericTypes(java.lang.String descriptor)
Remove any generic type parameters from the given descriptor.
-
-
-
Method Detail
-
checkMagicNumber
public static void checkMagicNumber(int magicNumber) throws java.lang.UnsupportedOperationException
Checks whether the given class magic number is correct.- Parameters:
magicNumber
- the magic number.- Throws:
java.lang.UnsupportedOperationException
- when the magic number is incorrect.
-
internalClassVersion
public static int internalClassVersion(int majorVersion, int minorVersion)
Returns the combined class version number.- Parameters:
majorVersion
- the major part of the class version number.minorVersion
- the minor part of the class version number.- Returns:
- the combined class version number.
-
internalMajorClassVersion
public static int internalMajorClassVersion(int internalClassVersion)
Returns the major part of the given class version number.- Parameters:
internalClassVersion
- the combined class version number.- Returns:
- the major part of the class version number.
-
internalMinorClassVersion
public static int internalMinorClassVersion(int internalClassVersion)
Returns the internal class version number.- Parameters:
internalClassVersion
- the external class version number.- Returns:
- the internal class version number.
-
internalClassVersion
public static int internalClassVersion(java.lang.String externalClassVersion)
Returns the internal class version number.- Parameters:
externalClassVersion
- the external class version number.- Returns:
- the internal class version number.
-
externalClassVersion
public static java.lang.String externalClassVersion(int internalClassVersion)
Returns the minor part of the given class version number.- Parameters:
internalClassVersion
- the combined class version number.- Returns:
- the minor part of the class version number.
-
checkVersionNumbers
public static void checkVersionNumbers(int internalClassVersion) throws java.lang.UnsupportedOperationException
Checks whether the given class version number is supported.- Parameters:
internalClassVersion
- the combined class version number.- Throws:
java.lang.UnsupportedOperationException
- when the version is not supported.
-
internalClassName
public static java.lang.String internalClassName(java.lang.String externalClassName)
Converts an external class name into an internal class name.- Parameters:
externalClassName
- the external class name, e.g. "java.lang.Object
"- Returns:
- the internal class name, e.g. "
java/lang/Object
".
-
canonicalClassName
public static java.lang.String canonicalClassName(java.lang.String externalClassName)
Converts an external class name into a canonical class name.- Parameters:
externalClassName
- the external class name e.g.com.example.Enclosing$Inner
- Returns:
- the canonical class name, e.g.
com.example.Enclosing.Inner
-
externalFullClassDescription
public static java.lang.String externalFullClassDescription(int accessFlags, java.lang.String internalClassName)
Converts an internal class description into an external class description.- Parameters:
accessFlags
- the access flags of the class.internalClassName
- the internal class name, e.g. "java/lang/Object
".- Returns:
- the external class description, e.g. "
public java.lang.Object
".
-
externalClassName
public static java.lang.String externalClassName(java.lang.String internalClassName)
Converts an internal class name into an external class name.- Parameters:
internalClassName
- the internal class name, e.g. "java/lang/Object
".- Returns:
- the external class name, e.g. "
java.lang.Object
".
-
externalBaseType
public static java.lang.String externalBaseType(java.lang.String externalArrayType)
Returns the external base type of an external array type, dropping any array brackets.- Parameters:
externalArrayType
- the external array type, e.g. "java.lang.Object[][]
"- Returns:
- the external base type, e.g. "
java.lang.Object
".
-
externalShortClassName
public static java.lang.String externalShortClassName(java.lang.String externalClassName)
Returns the external short class name of an external class name, dropping the package specification.- Parameters:
externalClassName
- the external class name, e.g. "java.lang.Object
"- Returns:
- the external short class name, e.g. "
Object
".
-
internalShortClassName
public static java.lang.String internalShortClassName(java.lang.String internalClassName)
Returns the internal short class name of an internal class name, dropping the package specification.- Parameters:
internalClassName
- the internal class name, e.g. "java/lang/Object
"- Returns:
- the internal short class name, e.g. "
Object
".
-
isInternalArrayType
public static boolean isInternalArrayType(java.lang.String internalType)
Returns whether the given internal type is an array type.- Parameters:
internalType
- the internal type, e.g. "[[Ljava/lang/Object;
".- Returns:
true
if the given type is an array type,false
otherwise.
-
internalArrayTypeDimensionCount
public static int internalArrayTypeDimensionCount(java.lang.String internalType)
Returns the number of dimensions of the given internal type.- Parameters:
internalType
- the internal type, e.g. "[[Ljava/lang/Object;
".- Returns:
- the number of dimensions, e.g. 2.
-
isInternalArrayInterfaceName
public static boolean isInternalArrayInterfaceName(java.lang.String internalClassName)
Returns whether the given internal class name is one of the interfaces that is implemented by all array types. These class names are "java/lang/Object
", "java/lang/Cloneable
", and "java/io/Serializable
"- Parameters:
internalClassName
- the internal class name, e.g. "java/lang/Object
".- Returns:
true
if the given type is an array interface name,false
otherwise.
-
isInternalPrimitiveType
public static boolean isInternalPrimitiveType(char internalType)
Returns whether the given internal type is a plain primitive type (not void).- Parameters:
internalType
- the internal type, e.g. "I
".- Returns:
true
if the given type is a class type,false
otherwise.
-
isInternalPrimitiveType
public static boolean isInternalPrimitiveType(java.lang.String internalType)
Returns whether the given internal type is a plain primitive type (not void).- Parameters:
internalType
- the internal type, e.g. "I
".- Returns:
true
if the given type is an internal primitive type,false
otherwise.
-
isInternalPrimitiveBoxingType
public static boolean isInternalPrimitiveBoxingType(java.lang.String internalType)
Returns whether the given class is a class boxing a primitive type (not void).- Parameters:
internalType
- the internal type, e.g. "Ljava/lang/Integer;
".- Returns:
true
if the given type is a boxing internal type of a class boxing a primitive,false
otherwise.
-
internalPrimitiveTypeFromPrimitiveBoxingType
public static char internalPrimitiveTypeFromPrimitiveBoxingType(java.lang.String type)
Returns the primitive type corresponding to the given internal primitive boxing type.- Parameters:
type
- an internal primitive boxing type, e.g. "Ljava/lang/Integer;
".- Returns:
- the corresponding primitive type, e.g. "
I
".
-
isInternalPrimitiveTypeOrString
public static boolean isInternalPrimitiveTypeOrString(java.lang.String internalType)
Returns whether the given internal type is a plain primitive type (not void) or a java/lang/String.- Parameters:
internalType
- the internal type, e.g. "I
".- Returns:
true
if the given type is a class type,false
otherwise.
-
isInternalCategory2Type
public static boolean isInternalCategory2Type(java.lang.String internalType)
Returns whether the given internal type is a primitive Category 2 type.- Parameters:
internalType
- the internal type, e.g. "L
".- Returns:
true
if the given type is a Category 2 type,false
otherwise.
-
isInternalClassType
public static boolean isInternalClassType(java.lang.String internalType)
Returns whether the given internal type is a plain class type (including an array type of a plain class type).- Parameters:
internalType
- the internal type, e.g. "Ljava/lang/Object;
".- Returns:
true
if the given type is a class type,false
otherwise.
-
isInternalType
public static boolean isInternalType(java.lang.String type)
Returns whether the given type is an internal type, i.e. one of:- an internal array type; - an internal primitive type; - an internal class type.
- Parameters:
type
- the type, e.g. "Ljava/lang/String;
", "I
"- Returns:
true
if the given type is a class type,false
otherwise.
-
internalTypeFromClassName
public static java.lang.String internalTypeFromClassName(java.lang.String internalClassName)
Returns the internal type of a given class name.- Parameters:
internalClassName
- the internal class name, e.g. "java/lang/Object
".- Returns:
- the internal type, e.g. "
Ljava/lang/Object;
".
-
internalArrayTypeFromClassName
public static java.lang.String internalArrayTypeFromClassName(java.lang.String internalClassName, int dimensionCount)
Returns the internal array type of a given class name with a given number of dimensions. If the number of dimensions is 0, the class name itself is returned.- Parameters:
internalClassName
- the internal class name, e.g. "java/lang/Object
".dimensionCount
- the number of array dimensions.- Returns:
- the internal array type of the array elements, e.g. "
Ljava/lang/Object;
".
-
internalArrayTypeFromType
public static java.lang.String internalArrayTypeFromType(java.lang.String internalType, int dimensionDelta)
Returns the internal array type of a given type, with a given number of additional dimensions.- Parameters:
internalType
- the internal class name, e.g. "[Ljava/lang/Object;
".dimensionDelta
- the number of additional array dimensions, e.g. 1.- Returns:
- the internal array type of the array elements, e.g. "
[[Ljava/lang/Object;
".
-
internalTypeFromArrayType
public static java.lang.String internalTypeFromArrayType(java.lang.String internalArrayType)
Returns the internal element type of a given internal array type.- Parameters:
internalArrayType
- the internal array type, e.g. "[[Ljava/lang/Object;
" or "[I
".- Returns:
- the internal type of the array elements, e.g. "
Ljava/lang/Object;
" or "I
".
-
internalClassTypeFromType
public static java.lang.String internalClassTypeFromType(java.lang.String internalType)
Returns the internal class type (class name or array type) of a given internal type (including an array type). This is the type that can be stored in a class constant.- Parameters:
internalType
- the internal class type, e.g. "[I
", "[Ljava/lang/Object;
", or "Ljava/lang/Object;
".- Returns:
- the internal class name, e.g. "
[I
", "[Ljava/lang/Object;
", or "java/lang/Object
".
-
internalTypeFromClassType
public static java.lang.String internalTypeFromClassType(java.lang.String internalType)
Returns the internal type of a given class type (class name or array type). This is the type that can be stored in a class constant.- Parameters:
internalType
- the internal class type, e.g. "[I
", "[Ljava/lang/Object;
", or "java/lang/Object
".- Returns:
- the internal class name, e.g. "
[I
", "[Ljava/lang/Object;
", or "Ljava/lang/Object;
".
-
internalClassNameFromClassType
public static java.lang.String internalClassNameFromClassType(java.lang.String internalClassType)
Returns the internal class name of a given internal class type (including an array type). Types involving primitive types are returned unchanged. Note: If you are parsing a Signature attribute string, useinternalClassNameFromClassSignature(String)
instead, as this method will not handle generic type parameters and the '.' as inner class separator.- Parameters:
internalClassType
- the internal class type, e.g. "[Ljava/lang/Object;
", "Ljava/lang/Object;
", or "java/lang/Object
".- Returns:
- the internal class name, e.g. "
java/lang/Object
".
-
internalClassNameFromClassSignature
public static java.lang.String internalClassNameFromClassSignature(java.lang.String classSignature)
Returns the internal class name for a given Class Signature.- Parameters:
classSignature
- the class signature, e.g. "Lsome/package/Klass< T;>.Inner
"- Returns:
- the internal class name, e.g. "
some/package/Klass$Inner
".
-
removeGenericTypes
public static java.lang.String removeGenericTypes(java.lang.String descriptor)
Remove any generic type parameters from the given descriptor.
-
internalClassNameFromType
public static java.lang.String internalClassNameFromType(java.lang.String internalClassType)
Returns the internal class name of any given internal descriptor type, disregarding array prefixes.- Parameters:
internalClassType
- the internal class type, e.g. "Ljava/lang/Object;
" or "[[I
".- Returns:
- the internal class name, e.g. "
java/lang/Object
" ornull
.
-
internalNumericClassNameFromPrimitiveType
public static java.lang.String internalNumericClassNameFromPrimitiveType(char internalPrimitiveType)
Returns the internal numeric (or void or array) class name corresponding to the given internal primitive type.- Parameters:
internalPrimitiveType
- the internal class type, e.g. "I
" or "V
".- Returns:
- the internal class name, e.g. "
java/lang/Integer
" orjava/lang/Void
.
-
internalPrimitiveTypeFromNumericClassName
public static char internalPrimitiveTypeFromNumericClassName(java.lang.String internalPrimitiveClassName)
Returns the internal numeric (or void or array) class name corresponding to the given internal primitive type.- Parameters:
internalPrimitiveClassName
- the internal class name, e.g. "java/lang/Integer
" orjava/lang/Void
.- Returns:
- the internal class type, e.g. "
I
" or "V
".
-
internalSimpleClassName
public static java.lang.String internalSimpleClassName(java.lang.String internalClassName)
Returns the simple name of an internal class name, dropping the package specification and any outer class part.- Parameters:
internalClassName
- the internal class name, e.g. "java/lang/Object
"- Returns:
- the simple class name, e.g. "
Object
".
-
internalPrimitiveTypeToComputationalType
public static int internalPrimitiveTypeToComputationalType(java.lang.String internalPrimitiveType)
The internal primitive type computational type.- Parameters:
internalPrimitiveType
- an internal primitive type (e.g., "Z")- Returns:
- the int representing the type internally (from the constants in
Value
).
-
isInitializer
public static boolean isInitializer(java.lang.String internalMethodName)
Returns whether the given method name refers to a class initializer or an instance initializer.- Parameters:
internalMethodName
- The internal method name, e.g. "<clinit>
".- Returns:
- Whether the method name refers to an initializer, e.g.
true
.
-
isClassInitializer
public static boolean isClassInitializer(java.lang.String internalMethodName)
Returns whether the given method name refers to a class initializer.- Parameters:
internalMethodName
- The internal method name, e.g. "<clinit>
".- Returns:
- Whether the method name refers to a class initializer, e.g.
true
.
-
isInstanceInitializer
public static boolean isInstanceInitializer(java.lang.String internalMethodName)
Returns whether the given method name refers to an instance initializer.- Parameters:
internalMethodName
- The internal method name, e.g. "<init>
".- Returns:
- Whether the method name refers to an instance initializer, e.g.
true
.
-
internalMethodReturnType
public static java.lang.String internalMethodReturnType(java.lang.String internalMethodDescriptor)
Returns the internal type of the given internal method descriptor.- Parameters:
internalMethodDescriptor
- the internal method descriptor, e.g. "(II)Z
".- Returns:
- the internal return type, e.g. "
Z
".
-
internalMethodParameterCount
public static int internalMethodParameterCount(java.lang.String internalMethodDescriptor)
Returns the number of parameters of the given internal method descriptor.- Parameters:
internalMethodDescriptor
- the internal method descriptor, e.g. "(ID)Z
".- Returns:
- the number of parameters, e.g. 2.
-
internalMethodParameterCount
public static int internalMethodParameterCount(java.lang.String internalMethodDescriptor, int accessFlags)
Returns the number of parameters of the given internal method descriptor.- Parameters:
internalMethodDescriptor
- the internal method descriptor, e.g. "(ID)Z
".accessFlags
- the access flags of the method, e.g. 0.- Returns:
- the number of parameters, e.g. 3.
-
internalMethodParameterCount
public static int internalMethodParameterCount(java.lang.String internalMethodDescriptor, boolean isStatic)
Returns the number of parameters of the given internal method descriptor.- Parameters:
internalMethodDescriptor
- the internal method descriptor, e.g. "(ID)Z
".isStatic
- specifies whether the method is static, e.g. false.- Returns:
- the number of parameters, e.g. 3.
-
internalMethodParameterSize
public static int internalMethodParameterSize(java.lang.String internalMethodDescriptor)
Returns the size taken up on the stack by the parameters of the given internal method descriptor. This accounts for long and double parameters taking up two entries.- Parameters:
internalMethodDescriptor
- the internal method descriptor, e.g. "(ID)Z
".- Returns:
- the size taken up on the stack, e.g. 3.
-
internalMethodParameterSize
public static int internalMethodParameterSize(java.lang.String internalMethodDescriptor, int accessFlags)
Returns the size taken up on the stack by the parameters of the given internal method descriptor. This accounts for long and double parameters taking up two entries, and a non-static method taking up an additional entry.- Parameters:
internalMethodDescriptor
- the internal method descriptor, e.g. "(ID)Z
".accessFlags
- the access flags of the method, e.g. 0.- Returns:
- the size taken up on the stack, e.g. 4.
-
internalMethodParameterSize
public static int internalMethodParameterSize(java.lang.String internalMethodDescriptor, boolean isStatic)
Returns the size taken up on the stack by the parameters of the given internal method descriptor. This accounts for long and double parameters taking up two spaces, and a non-static method taking up an additional entry.- Parameters:
internalMethodDescriptor
- the internal method descriptor, e.g. "(ID)Z
".isStatic
- specifies whether the method is static, e.g. false.- Returns:
- the size taken up on the stack, e.g. 4.
-
internalMethodParameterNumber
public static int internalMethodParameterNumber(java.lang.String internalMethodDescriptor, int accessFlags, int variableIndex)
Returns the parameter number in the given internal method descriptor, corresponding to the given variable index. This accounts for long and double parameters taking up two spaces, and a non-static method taking up an additional entry. The method returns 0 if the index corresponds to the 'this' parameter and -1 if the index does not correspond to a parameter.- Parameters:
internalMethodDescriptor
- the internal method descriptor, e.g. "(IDI)Z
".accessFlags
- the access flags of the method, e.g. 0.variableIndex
- the variable index of the parameter, e.g. 4.- Returns:
- the parameter number in the descriptor, e.g. 3.
-
internalMethodParameterNumber
public static int internalMethodParameterNumber(java.lang.String internalMethodDescriptor, boolean isStatic, int variableIndex)
Returns the parameter number in the given internal method descriptor, corresponding to the given variable index. This accounts for long and double parameters taking up two spaces, and a non-static method taking up an additional entry. The method returns 0 if the index corresponds to the 'this' parameter and -1 if the index does not correspond to a parameter.- Parameters:
internalMethodDescriptor
- the internal method descriptor, e.g. "(IDI)Z
".isStatic
- specifies whether the method is static, e.g. false.variableIndex
- the variable index of the parameter, e.g. 4.- Returns:
- the parameter number in the descriptor, e.g. 3.
-
internalMethodVariableIndex
public static int internalMethodVariableIndex(java.lang.String internalMethodDescriptor, int accessFlags, int parameterNumber)
Returns the variable index corresponding to the given parameter number in the given internal method descriptor. This accounts for long and double parameters taking up two spaces, and a non-static method taking up an additional entry. The method returns 0 if the number corresponds to the 'this' parameter and -1 if the number does not correspond to a parameter.- Parameters:
internalMethodDescriptor
- the internal method descriptor, e.g. "(IDI)Z
".accessFlags
- the access flags of the method, e.g. 0.parameterNumber
- the parameter number, e.g. 3.- Returns:
- the corresponding variable index, e.g. 4.
-
internalMethodVariableIndex
public static int internalMethodVariableIndex(java.lang.String internalMethodDescriptor, boolean isStatic, int parameterNumber)
Returns the parameter index in the given internal method descriptor, corresponding to the given variable number. This accounts for long and double parameters taking up two spaces, and a non-static method taking up an additional entry. The method returns 0 if the number corresponds to the 'this' parameter and -1 if the number does not correspond to a parameter.- Parameters:
internalMethodDescriptor
- the internal method descriptor, e.g. "(IDI)Z
".isStatic
- specifies whether the method is static, e.g. false.parameterNumber
- the parameter number, e.g. 3.- Returns:
- the corresponding variable index, e.g. 4.
-
internalMethodParameterType
public static java.lang.String internalMethodParameterType(java.lang.String internalMethodDescriptor, int parameterIndex)
Returns the internal type of the parameter in the given method descriptor, at the given index.- Parameters:
internalMethodDescriptor
- the internal method descriptor e.g. "(IDI)Z
".parameterIndex
- the parameter index, e.g. 1.- Returns:
- the parameter's type, e.g. "
D
".
-
internalTypeSize
public static int internalTypeSize(java.lang.String internalType)
Returns the size taken up on the stack by the given internal type. The size is 1, except for long and double types, for which it is 2, and for the void type, for which 0 is returned.- Parameters:
internalType
- the internal type, e.g. "I
".- Returns:
- the size taken up on the stack, e.g. 1.
-
internalType
public static java.lang.String internalType(java.lang.String externalType)
Converts an external type into an internal type.- Parameters:
externalType
- the external type, e.g. "java.lang.Object[][]
" or "int[]
".- Returns:
- the internal type, e.g. "
[[Ljava/lang/Object;
" or "[I
".
-
externalArrayTypeDimensionCount
public static int externalArrayTypeDimensionCount(java.lang.String externalType)
Returns the number of dimensions of the given external type.- Parameters:
externalType
- the external type, e.g. "[[Ljava/lang/Object;
".- Returns:
- the number of dimensions, e.g. 2.
-
externalType
public static java.lang.String externalType(java.lang.String internalType)
Converts an internal type into an external type.- Parameters:
internalType
- the internal type, e.g. "Ljava/lang/Object;
" or "[[Ljava/lang/Object;
" or "[I
".- Returns:
- the external type, e.g. "
java.lang.Object
" or "java.lang.Object[][]
" or "int[]
". - Throws:
java.lang.IllegalArgumentException
- if the type is invalid.
-
externalClassForNameType
public static java.lang.String externalClassForNameType(java.lang.String internalType)
Converts an internal type into an external type, as expected by Class.forName.- Parameters:
internalType
- the internal type, e.g. "Ljava/lang/Object;
" or "[[Ljava/lang/Object;
" or "[I
".- Returns:
- the external type, e.g. "
java.lang.Object
" or "[[Ljava.lang.Object;
" or "[I
".
-
isInternalMethodDescriptor
public static boolean isInternalMethodDescriptor(java.lang.String internalDescriptor)
Returns whether the given internal descriptor String represents a method descriptor.- Parameters:
internalDescriptor
- the internal descriptor String, e.g. "(II)Z
".- Returns:
true
if the given String is a method descriptor,false
otherwise.
-
isExternalMethodNameAndArguments
public static boolean isExternalMethodNameAndArguments(java.lang.String externalMemberNameAndArguments)
Returns whether the given member String represents an external method name with arguments.- Parameters:
externalMemberNameAndArguments
- the external member String, e.g. "myField
" or e.g. "myMethod(int,int)
".- Returns:
true
if the given String refers to a method,false
otherwise.
-
externalMethodName
public static java.lang.String externalMethodName(java.lang.String externalMethodNameAndArguments)
Returns the name part of the given external method name and arguments.- Parameters:
externalMethodNameAndArguments
- the external method name and arguments, e.g. "myMethod(int,int)
".- Returns:
- the name part of the String, e.g. "
myMethod
".
-
internalMethodDescriptor
public static java.lang.String internalMethodDescriptor(java.lang.String externalReturnType, java.lang.String externalMethodNameAndArguments)
Converts the given external method return type and name and arguments to an internal method descriptor.- Parameters:
externalReturnType
- the external method return type, e.g. "boolean
".externalMethodNameAndArguments
- the external method name and arguments, e.g. "myMethod(int,int)
".- Returns:
- the internal method descriptor, e.g. "
(II)Z
".
-
internalMethodDescriptor
public static java.lang.String internalMethodDescriptor(java.lang.String externalReturnType, java.util.List<java.lang.String> externalArguments)
Converts the given external method return type and List of arguments to an internal method descriptor.- Parameters:
externalReturnType
- the external method return type, e.g. "boolean
".externalArguments
- the external method arguments, e.g.{ "int", "int" }
.- Returns:
- the internal method descriptor, e.g. "
(II)Z
".
-
internalMethodDescriptorFromInternalTypes
public static java.lang.String internalMethodDescriptorFromInternalTypes(java.lang.String internalReturnType, java.util.List<java.lang.String> internalArguments)
Converts the given internal method return type and List of arguments to an internal method descriptor.- Parameters:
internalReturnType
- the external method return type, e.g. "Z
".internalArguments
- the external method arguments, e.g.{ "I", "I" }
.- Returns:
- the internal method descriptor, e.g. "
(II)Z
".
-
externalFullFieldDescription
public static java.lang.String externalFullFieldDescription(int accessFlags, java.lang.String fieldName, java.lang.String internalFieldDescriptor)
Converts an internal field description into an external full field description.- Parameters:
accessFlags
- the access flags of the field.fieldName
- the field name, e.g. "myField
".internalFieldDescriptor
- the internal field descriptor, e.g. "Z
".- Returns:
- the external full field description, e.g. "
public boolean myField
".
-
externalFullMethodDescription
public static java.lang.String externalFullMethodDescription(java.lang.String internalClassName, int accessFlags, java.lang.String internalMethodName, java.lang.String internalMethodDescriptor)
Converts an internal method description into an external full method description.- Parameters:
internalClassName
- the internal name of the class of the method, e.g. "mypackage/MyClass
".accessFlags
- the access flags of the method.internalMethodName
- the internal method name, e.g. "myMethod
" or "<init>
".internalMethodDescriptor
- the internal method descriptor, e.g. "(II)Z
".- Returns:
- the external full method description, e.g. "
public boolean myMethod(int,int)
" or "public MyClass(int,int)
".
-
externalClassAccessFlags
public static java.lang.String externalClassAccessFlags(int accessFlags)
Converts internal class access flags into an external access description.- Parameters:
accessFlags
- the class access flags.- Returns:
- the external class access description, e.g. "
public final
".
-
externalClassAccessFlags
public static java.lang.String externalClassAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal class access flags into an external access description.- Parameters:
accessFlags
- the class access flags.prefix
- a prefix that is added to each access modifier.- Returns:
- the external class access description, e.g. "
public final
".
-
externalFieldAccessFlags
public static java.lang.String externalFieldAccessFlags(int accessFlags)
Converts internal field access flags into an external access description.- Parameters:
accessFlags
- the field access flags.- Returns:
- the external field access description, e.g. "
public volatile
".
-
externalFieldAccessFlags
public static java.lang.String externalFieldAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal field access flags into an external access description.- Parameters:
accessFlags
- the field access flags.prefix
- a prefix that is added to each access modifier.- Returns:
- the external field access description, e.g. "
public volatile
".
-
externalMethodAccessFlags
public static java.lang.String externalMethodAccessFlags(int accessFlags)
Converts internal method access flags into an external access description.- Parameters:
accessFlags
- the method access flags.- Returns:
- the external method access description, e.g. "
public synchronized
".
-
externalMethodAccessFlags
public static java.lang.String externalMethodAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal method access flags into an external access description.- Parameters:
accessFlags
- the method access flags.prefix
- a prefix that is added to each access modifier.- Returns:
- the external method access description, e.g. "public synchronized ".
-
externalParameterAccessFlags
public static java.lang.String externalParameterAccessFlags(int accessFlags)
Converts internal method parameter access flags into an external access description.- Parameters:
accessFlags
- the method parameter access flags.- Returns:
- the external method parameter access description, e.g. "
final mandated
".
-
externalParameterAccessFlags
public static java.lang.String externalParameterAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal method parameter access flags into an external access description.- Parameters:
accessFlags
- the method parameter access flags.prefix
- a prefix that is added to each access modifier.- Returns:
- the external method parameter access description, e.g. "final mandated ".
-
externalMethodReturnType
public static java.lang.String externalMethodReturnType(java.lang.String internalMethodDescriptor)
Converts an internal method descriptor into an external method return type.- Parameters:
internalMethodDescriptor
- the internal method descriptor, e.g. "(II)Z
".- Returns:
- the external method return type, e.g. "
boolean
".
-
externalModuleAccessFlags
public static java.lang.String externalModuleAccessFlags(int accessFlags)
Converts internal module access flags into an external access description.- Parameters:
accessFlags
- the module access flags.- Returns:
- the external module access description, e.g. "
open mandated
".
-
externalModuleAccessFlags
public static java.lang.String externalModuleAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal module access flags into an external access description.- Parameters:
accessFlags
- the module access flags.prefix
- a prefix that is added to each access modifier.- Returns:
- the external module access description, e.g. "
final mandated
".
-
externalRequiresAccessFlags
public static java.lang.String externalRequiresAccessFlags(int accessFlags)
Converts internal module requires access flags into an external access description.- Parameters:
accessFlags
- the module requires access flags.- Returns:
- the external module requires access description, e.g. "
static mandated
".
-
externalRequiresAccessFlags
public static java.lang.String externalRequiresAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal module requires access flags into an external access description.- Parameters:
accessFlags
- the module requires access flags.prefix
- a prefix that is added to each access modifier.- Returns:
- the external module requires access description, e.g. "
static mandated
".
-
externalExportsAccessFlags
public static java.lang.String externalExportsAccessFlags(int accessFlags)
Converts internal module exports access flags into an external access description.- Parameters:
accessFlags
- the module exports access flags.- Returns:
- the external module exports access description, e.g. "
synthetic mandated
".
-
externalExportsAccessFlags
public static java.lang.String externalExportsAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal module exports access flags into an external access description.- Parameters:
accessFlags
- the module exports access flags.prefix
- a prefix that is added to each access modifier.- Returns:
- the external module exports access description, e.g. "
static mandated
".
-
externalOpensAccessFlags
public static java.lang.String externalOpensAccessFlags(int accessFlags)
Converts internal module opens access flags into an external access description.- Parameters:
accessFlags
- the module opens access flags.- Returns:
- the external module opens access description, e.g. "
synthetic mandated
".
-
externalOpensAccessFlags
public static java.lang.String externalOpensAccessFlags(int accessFlags, java.lang.String prefix)
Converts internal module opens access flags into an external access description.- Parameters:
accessFlags
- the module opens access flags.prefix
- a prefix that is added to each access modifier.- Returns:
- the external module opens access description, e.g. "
static mandated
".
-
externalMethodArguments
public static java.lang.String externalMethodArguments(java.lang.String internalMethodDescriptor)
Converts an internal method descriptor into an external method argument description.- Parameters:
internalMethodDescriptor
- the internal method descriptor, e.g. "(II)Z
".- Returns:
- the external method argument description, e.g. "
int,int
".
-
internalPackageName
public static java.lang.String internalPackageName(java.lang.String internalClassName)
Returns the internal package name of the given internal class name.- Parameters:
internalClassName
- the internal class name, e.g. "java/lang/Object
".- Returns:
- the internal package name, e.g. "
java/lang
".
-
internalPackagePrefix
public static java.lang.String internalPackagePrefix(java.lang.String internalClassName)
Returns the internal package prefix of the given internal class name.- Parameters:
internalClassName
- the internal class name, e.g. "java/lang/Object
".- Returns:
- the internal package prefix, e.g. "
java/lang/
".
-
externalPackageName
public static java.lang.String externalPackageName(java.lang.String externalClassName)
Returns the external package name of the given external class name.- Parameters:
externalClassName
- the external class name, e.g. "java.lang.Object
".- Returns:
- the external package name, e.g. "
java.lang
".
-
externalPackagePrefix
public static java.lang.String externalPackagePrefix(java.lang.String externalClassName)
Returns the external package prefix of the given external class name.- Parameters:
externalClassName
- the external class name, e.g. "java.lang.Object
".- Returns:
- the external package prefix, e.g. "
java.lang.
".
-
-