Package proguard.classfile.util
Class ClassUtil
java.lang.Object
proguard.classfile.util.ClassUtil
Utility methods for:
- Converting between internal and external representations of names and descriptions
- Operation on
Clazz
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringcanonicalClassName(String externalClassName) Converts an external class name into a canonical class name.static voidcheckMagicNumber(int magicNumber) Checks whether the given class magic number is correct.static voidcheckVersionNumbers(int internalClassVersion) Checks whether the given class version number is supported.static intexternalArrayTypeDimensionCount(String externalType) Returns the number of dimensions of the given external type.static StringexternalBaseType(String externalArrayType) Returns the external base type of an external array type, dropping any array brackets.static StringexternalClassAccessFlags(int accessFlags) Converts internal class access flags into an external access description.static StringexternalClassAccessFlags(int accessFlags, String prefix) Converts internal class access flags into an external access description.static StringexternalClassForNameType(String internalType) Converts an internal type into an external type, as expected by Class.forName.static StringexternalClassName(String internalClassName) Converts an internal class name into an external class name.static StringexternalClassName(String internalClassName, boolean quoted) Converts an internal class name into an external class name.static StringexternalClassVersion(int internalClassVersion) Returns the external class version number.static StringexternalExportsAccessFlags(int accessFlags) Converts internal module exports access flags into an external access description.static StringexternalExportsAccessFlags(int accessFlags, String prefix) Converts internal module exports access flags into an external access description.static StringexternalFieldAccessFlags(int accessFlags) Converts internal field access flags into an external access description.static StringexternalFieldAccessFlags(int accessFlags, String prefix) Converts internal field access flags into an external access description.static StringexternalFullClassDescription(int accessFlags, String internalClassName) Converts an internal class description into an external class description.static StringexternalFullFieldDescription(int accessFlags, String fieldName, String internalFieldDescriptor) static StringexternalFullFieldDescription(int accessFlags, String fieldName, String internalFieldDescriptor, boolean quoted) Converts an internal field description into an external full field description.static StringexternalFullMethodDescription(String internalClassName, int accessFlags, String internalMethodName, String internalMethodDescriptor) Converts an internal method description into an external full method description.static StringexternalFullMethodDescription(String internalClassName, int accessFlags, String internalMethodName, String internalMethodDescriptor, boolean quoted) Converts an internal method description into an external full method description.static StringexternalMethodAccessFlags(int accessFlags) Converts internal method access flags into an external access description.static StringexternalMethodAccessFlags(int accessFlags, String prefix) Converts internal method access flags into an external access description.static StringexternalMethodArguments(String internalMethodDescriptor) Converts an internal method descriptor into an external method argument description.static StringexternalMethodArguments(String internalMethodDescriptor, boolean quoted) Converts an internal method descriptor into an external method argument description.static StringexternalMethodName(String externalMethodNameAndArguments) Returns the name part of the given external method name and arguments.static StringexternalMethodReturnType(String internalMethodDescriptor) Converts an internal method descriptor into an external method return type.static StringexternalModuleAccessFlags(int accessFlags) Converts internal module access flags into an external access description.static StringexternalModuleAccessFlags(int accessFlags, String prefix) Converts internal module access flags into an external access description.static StringexternalOpensAccessFlags(int accessFlags) Converts internal module opens access flags into an external access description.static StringexternalOpensAccessFlags(int accessFlags, String prefix) Converts internal module opens access flags into an external access description.static StringexternalPackageName(String externalClassName) Returns the external package name of the given external class name.static StringexternalPackagePrefix(String externalClassName) Returns the external package prefix of the given external class name.static StringexternalParameterAccessFlags(int accessFlags) Converts internal method parameter access flags into an external access description.static StringexternalParameterAccessFlags(int accessFlags, String prefix) Converts internal method parameter access flags into an external access description.static StringexternalRequiresAccessFlags(int accessFlags) Converts internal module requires access flags into an external access description.static StringexternalRequiresAccessFlags(int accessFlags, String prefix) Converts internal module requires access flags into an external access description.static StringexternalShortClassName(String externalClassName) Returns the external short class name of an external class name, dropping the package specification.static StringexternalType(String internalType) Converts an internal type into an external type.static StringexternalType(String internalType, boolean quoted) Converts an internal type into an external type.static intinternalArrayTypeDimensionCount(String internalType) Returns the number of dimensions of the given internal type.static StringinternalArrayTypeFromClassName(String internalClassName, int dimensionCount) Returns the internal array type of a given class name with a given number of dimensions.static StringinternalArrayTypeFromType(String internalType, int dimensionDelta) Returns the internal array type of a given type, with a given number of additional dimensions.static StringinternalClassName(String externalClassName) Converts an external class name into an internal class name.static StringinternalClassNameFromClassSignature(String classSignature) Returns the internal class name for a given Class Signature.static StringinternalClassNameFromClassType(String internalClassType) Returns the internal class name of a given internal class type (including an array type).static StringinternalClassNameFromType(String internalClassType) Returns the internal class name of any given internal descriptor type, disregarding array prefixes.static StringinternalClassTypeFromType(String internalType) Returns the internal class type (class name or array type) of a given internal type (including an array type).static intinternalClassVersion(int majorVersion, int minorVersion) Returns the combined class version number.static intinternalClassVersion(String externalClassVersion) Returns the internal class version number.static intinternalMajorClassVersion(int internalClassVersion) Returns the major part of the given class version number.static StringinternalMethodDescriptor(String externalReturnType, String externalMethodNameAndArguments) Converts the given external method return type and name and arguments to an internal method descriptor.static StringinternalMethodDescriptor(String externalReturnType, List<String> externalArguments) Converts the given external method return type and List of arguments to an internal method descriptor.static StringinternalMethodDescriptorFromInternalTypes(String internalReturnType, List<String> internalArguments) Converts the given internal method return type and List of arguments to an internal method descriptor.static intinternalMethodParameterCount(String internalMethodDescriptor) Returns the number of parameters of the given internal method descriptor.static intinternalMethodParameterCount(String internalMethodDescriptor, boolean isStatic) Returns the number of parameters of the given internal method descriptor.static intinternalMethodParameterCount(String internalMethodDescriptor, int accessFlags) Returns the number of parameters of the given internal method descriptor.static intinternalMethodParameterNumber(String internalMethodDescriptor, boolean isStatic, int variableIndex) Returns the parameter number in the given internal method descriptor, corresponding to the given variable index.static intinternalMethodParameterNumber(String internalMethodDescriptor, int accessFlags, int variableIndex) Returns the parameter number in the given internal method descriptor, corresponding to the given variable index.static intinternalMethodParameterSize(String internalMethodDescriptor) Returns the size taken up on the stack by the parameters of the given internal method descriptor.static intinternalMethodParameterSize(String internalMethodDescriptor, boolean isStatic) Returns the size taken up on the stack by the parameters of the given internal method descriptor.static intinternalMethodParameterSize(String internalMethodDescriptor, int accessFlags) Returns the size taken up on the stack by the parameters of the given internal method descriptor.static StringinternalMethodParameterType(String internalMethodDescriptor, int parameterIndex) Returns the internal type of the parameter in the given method descriptor, at the given index.static StringinternalMethodReturnType(String internalMethodDescriptor) Returns the internal type of the given internal method descriptor.static intinternalMethodVariableIndex(String internalMethodDescriptor, boolean isStatic, int parameterNumber) Returns the parameter index in the given internal method descriptor, corresponding to the given variable number.static intinternalMethodVariableIndex(String internalMethodDescriptor, int accessFlags, int parameterNumber) Returns the variable index corresponding to the given parameter number in the given internal method descriptor.static intinternalMinorClassVersion(int internalClassVersion) Returns the minor part of the given class version number.static StringinternalNumericClassNameFromPrimitiveType(char internalPrimitiveType) Returns the internal numeric (or void or array) class name corresponding to the given internal primitive type.static StringinternalPackageName(String internalClassName) Returns the internal package name of the given internal class name.static StringinternalPackagePrefix(String internalClassName) Returns the internal package prefix of the given internal class name.static charinternalPrimitiveTypeFromNumericClassName(String internalPrimitiveClassName) Returns the internal numeric (or void or array) class name corresponding to the given internal primitive type.static charReturns the primitive type corresponding to the given internal primitive boxing type.static intinternalPrimitiveTypeToComputationalType(String internalPrimitiveType) The internal primitive type computational type.static StringinternalShortClassName(String internalClassName) Returns the internal short class name of an internal class name, dropping the package specification.static StringinternalSimpleClassName(String internalClassName) Returns the simple name of an internal class name, dropping the package specification and any outer class part.static StringinternalType(String externalType) Converts an external type into an internal type.static StringinternalTypeFromArrayType(String internalArrayType) Returns the internal element type of a given internal array type.static StringinternalTypeFromClassName(String internalClassName) Returns the internal type of a given class name.static StringinternalTypeFromClassType(String internalType) Returns the internal type of a given class type (class name or array type).static intinternalTypeSize(String internalType) Returns the size taken up on the stack by the given internal type.static booleanisClassInitializer(String internalMethodName) Returns whether the given method name refers to a class initializer.static booleanisExtendable(Clazz clazz) Returns `true` if aClazzis null or if it does not represent a final class.static booleanisExternalMethodNameAndArguments(String externalMemberNameAndArguments) Returns whether the given member String represents an external method name with arguments.static booleanisInitializer(String internalMethodName) Returns whether the given method name refers to a class initializer or an instance initializer.static booleanisInstanceInitializer(String internalMethodName) Returns whether the given method name refers to an instance initializer.static booleanisInternalArrayInterfaceName(String internalClassName) Returns whether the given internal class name is one of the interfaces that is implemented by all array types.static booleanisInternalArrayType(String internalType) Returns whether the given internal type is an array type.static booleanisInternalCategory2Type(String internalType) Returns whether the given internal type is a primitive Category 2 type.static booleanisInternalClassType(String internalType) Returns whether the given internal type is a plain class type (including an array type of a plain class type).static booleanisInternalMethodDescriptor(String internalDescriptor) Returns whether the given internal descriptor String represents a method descriptor.static booleanisInternalPrimitiveBoxingType(String internalType) Returns whether the given class is a class boxing a primitive type (not void).static booleanisInternalPrimitiveType(char internalType) Returns whether the given internal type is a plain primitive type (not void).static booleanisInternalPrimitiveType(String internalType) Returns whether the given internal type is a plain primitive type (not void).static booleanisInternalPrimitiveTypeOrString(String internalType) Returns whether the given internal type is a plain primitive type (not void) or a java/lang/String.static booleanisInternalType(String type) Returns whether the given type is an internal type, i.e.static Class<?>primitiveClassFromInternalBoxingType(String internalBoxingType) static StringquotedIdentifier(String identifier) Wraps given identifier in quotes in case it's empty, or it contains space character.static StringremoveGenericTypes(String descriptor) Remove any generic type parameters from the given descriptor.
-
Method Details
-
checkMagicNumber
Checks whether the given class magic number is correct.- Parameters:
magicNumber- the magic number.- Throws:
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 minor part of the given class version number.- Parameters:
internalClassVersion- the combined class version number.- Returns:
- the minor part of the class version number.
-
internalClassVersion
Returns the internal class version number.- Parameters:
externalClassVersion- the external class version number.- Returns:
- the internal class version number, or 0 if unrecognized.
-
externalClassVersion
Returns the external class version number.- Parameters:
internalClassVersion- the internal class version number.- Returns:
- the external class version number, or
nullif unrecognized.
-
checkVersionNumbers
public static void checkVersionNumbers(int internalClassVersion) throws UnsupportedOperationException Checks whether the given class version number is supported.- Parameters:
internalClassVersion- the combined class version number.- Throws:
UnsupportedOperationException- when the version is not supported.
-
internalClassName
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
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
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
Converts an internal class name into an external class name.- Parameters:
internalClassName- the internal class name, e.g. "java/lang/Object".quoted- whether the result should be quoted; should be set to true if it is going to be parsed as configuration later. UsesquotedIdentifier(String)for quoting.- Returns:
- the external class name, e.g. "
java.lang.Object".
-
externalClassName
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
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
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
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
Returns whether the given internal type is an array type.- Parameters:
internalType- the internal type, e.g. "[[Ljava/lang/Object;".- Returns:
trueif the given type is an array type,falseotherwise.
-
internalArrayTypeDimensionCount
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
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:
trueif the given type is an array interface name,falseotherwise.
-
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:
trueif the given type is a class type,falseotherwise.
-
isInternalPrimitiveType
Returns whether the given internal type is a plain primitive type (not void).- Parameters:
internalType- the internal type, e.g. "I".- Returns:
trueif the given type is an internal primitive type,falseotherwise.
-
isInternalPrimitiveBoxingType
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:
trueif the given type is a boxing internal type of a class boxing a primitive,falseotherwise.
-
internalPrimitiveTypeFromPrimitiveBoxingType
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".
-
primitiveClassFromInternalBoxingType
-
isInternalPrimitiveTypeOrString
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:
trueif the given type is a class type,falseotherwise.
-
isInternalCategory2Type
Returns whether the given internal type is a primitive Category 2 type.- Parameters:
internalType- the internal type, e.g. "L".- Returns:
trueif the given type is a Category 2 type,falseotherwise.
-
isInternalClassType
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:
trueif the given type is a class type,falseotherwise.
-
isInternalType
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:
trueif the given type is a class type,falseotherwise.
-
internalTypeFromClassName
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
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
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
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
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
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
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
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
Remove any generic type parameters from the given descriptor. -
internalClassNameFromType
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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(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(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(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(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 String internalMethodParameterType(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
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
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
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
Converts an internal type into an external type.- Parameters:
internalType- the internal type, e.g. "Ljava/lang/Object;" or "[[Ljava/lang/Object;" or "[I".quoted- whether the result should be quoted; should be set to true if it is going to be parsed as configuration later. UsesquotedIdentifier(String)for quoting.- Returns:
- the external type, e.g. "
java.lang.Object" or "java.lang.Object[][]" or "int[]". - Throws:
IllegalArgumentException- if the type is invalid.
-
externalType
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:
IllegalArgumentException- if the type is invalid.
-
externalClassForNameType
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
Returns whether the given internal descriptor String represents a method descriptor.- Parameters:
internalDescriptor- the internal descriptor String, e.g. "(II)Z".- Returns:
trueif the given String is a method descriptor,falseotherwise.
-
isExternalMethodNameAndArguments
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:
trueif the given String refers to a method,falseotherwise.
-
externalMethodName
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 String internalMethodDescriptor(String externalReturnType, 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 String internalMethodDescriptor(String externalReturnType, List<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 String internalMethodDescriptorFromInternalTypes(String internalReturnType, List<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 String externalFullFieldDescription(int accessFlags, String fieldName, String internalFieldDescriptor, boolean quoted) 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".quoted- whether the identifiers should be quoted; should be set to true if it is going to be parsed as configuration later. UsesquotedIdentifier(String)for quoting.- Returns:
- the external full field description, e.g. "
public boolean myField".
-
externalFullFieldDescription
-
externalFullMethodDescription
public static String externalFullMethodDescription(String internalClassName, int accessFlags, String internalMethodName, String internalMethodDescriptor, boolean quoted) 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".quoted- whether the types and names should be quoted; should be set to true if it is going to be parsed as configuration later. UsesquotedIdentifier(String)for quoting.- Returns:
- the external full method description, e.g. "
public boolean myMethod(int,int)" or "public MyClass(int,int)".
-
externalFullMethodDescription
public static String externalFullMethodDescription(String internalClassName, int accessFlags, String internalMethodName, 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Converts an internal method descriptor into an external method argument description.- Parameters:
internalMethodDescriptor- the internal method descriptor, e.g. "(II)Z".quoted- whether result should be quoted; should be set to true if it is going to be parsed as configuration later. UsesquotedIdentifier(String)for quoting.- Returns:
- the external method argument description, e.g. "
int,int".
-
externalMethodArguments
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
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
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
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
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.".
-
isExtendable
Returns `true` if aClazzis null or if it does not represent a final class. This means that for the sake of our analysis we can consider value of this class not extendable. -
quotedIdentifier
Wraps given identifier in quotes in case it's empty, or it contains space character. Quotes and backslashes in the input will be escaped.- Parameters:
identifier- unquoted input identifier- Returns:
- quoted identifier
-