Package com.tonic.util
Class DescriptorUtil
- java.lang.Object
-
- com.tonic.util.DescriptorUtil
-
public final class DescriptorUtil extends Object
Utility class for JVM descriptor parsing and manipulation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDescriptorUtil.DescriptorCategoryDescriptor categories for JVM types.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DescriptorUtil.DescriptorCategorycategorize(char c)Categorizes a type descriptor character.static DescriptorUtil.DescriptorCategorycategorize(String descriptor)Categorizes a type descriptor string.static intcountParameters(String methodDescriptor)Counts the number of parameters in a method descriptor.static intcountParameterSlots(String methodDescriptor)Counts the total number of stack/local slots needed for method parameters.static StringextractClassName(String descriptor)Extracts the class name from an object type descriptor.static Set<String>extractClassNames(String descriptor)Extracts all class names referenced in a descriptor (internal format).static intgetArrayDimensions(String arrayDescriptor)Gets the number of array dimensions.static StringgetArrayElementType(String arrayDescriptor)Gets the element type from an array descriptor.static intgetTypeSlots(String descriptor)Gets the number of slots a type occupies on the stack/locals.static booleanisPrimitive(char c)Checks if a character represents a primitive type descriptor.static booleanisWideType(String descriptor)Checks if a type descriptor represents a wide type (takes 2 slots).static List<String>parseParameterDescriptors(String methodDescriptor)Parses the parameter descriptors from a method descriptor.static StringparseReturnDescriptor(String methodDescriptor)Parses the return type descriptor from a method descriptor.static StringtoObjectDescriptor(String internalName)Creates an object type descriptor from an internal class name.
-
-
-
Method Detail
-
categorize
public static DescriptorUtil.DescriptorCategory categorize(char c)
Categorizes a type descriptor character.- Parameters:
c- the first character of the descriptor- Returns:
- the category, or null if not a valid descriptor character
-
categorize
public static DescriptorUtil.DescriptorCategory categorize(String descriptor)
Categorizes a type descriptor string.- Parameters:
descriptor- the type descriptor- Returns:
- the category, or null if empty or invalid
-
isPrimitive
public static boolean isPrimitive(char c)
Checks if a character represents a primitive type descriptor.- Parameters:
c- the descriptor character- Returns:
- true if this is a primitive type (Z, B, C, S, I, J, F, D, V)
-
isWideType
public static boolean isWideType(String descriptor)
Checks if a type descriptor represents a wide type (takes 2 slots).- Parameters:
descriptor- the type descriptor- Returns:
- true if this is a long (J) or double (D)
-
getTypeSlots
public static int getTypeSlots(String descriptor)
Gets the number of slots a type occupies on the stack/locals.- Parameters:
descriptor- the type descriptor- Returns:
- 2 for long/double, 0 for void, 1 for everything else
-
parseParameterDescriptors
public static List<String> parseParameterDescriptors(String methodDescriptor)
Parses the parameter descriptors from a method descriptor.- Parameters:
methodDescriptor- the full method descriptor (e.g., "(ILjava/lang/String;)V")- Returns:
- list of individual parameter descriptors (e.g., ["I", "Ljava/lang/String;"])
-
parseReturnDescriptor
public static String parseReturnDescriptor(String methodDescriptor)
Parses the return type descriptor from a method descriptor.- Parameters:
methodDescriptor- the full method descriptor (e.g., "(I)Ljava/lang/String;")- Returns:
- the return type descriptor (e.g., "Ljava/lang/String;")
-
countParameters
public static int countParameters(String methodDescriptor)
Counts the number of parameters in a method descriptor.- Parameters:
methodDescriptor- the full method descriptor- Returns:
- the number of parameters
-
countParameterSlots
public static int countParameterSlots(String methodDescriptor)
Counts the total number of stack/local slots needed for method parameters.- Parameters:
methodDescriptor- the full method descriptor- Returns:
- the total slot count (long/double count as 2)
-
extractClassNames
public static Set<String> extractClassNames(String descriptor)
Extracts all class names referenced in a descriptor (internal format).- Parameters:
descriptor- a type or method descriptor- Returns:
- set of internal class names (e.g., "java/lang/String")
-
getArrayElementType
public static String getArrayElementType(String arrayDescriptor)
Gets the element type from an array descriptor.- Parameters:
arrayDescriptor- the array type descriptor (e.g., "[[I" or "[Ljava/lang/String;")- Returns:
- the element type (e.g., "I" or "Ljava/lang/String;"), or null if not an array
-
getArrayDimensions
public static int getArrayDimensions(String arrayDescriptor)
Gets the number of array dimensions.- Parameters:
arrayDescriptor- the array type descriptor- Returns:
- the number of dimensions, or 0 if not an array
-
extractClassName
public static String extractClassName(String descriptor)
Extracts the class name from an object type descriptor.- Parameters:
descriptor- the object type descriptor (e.g., "Ljava/lang/String;")- Returns:
- the internal class name (e.g., "java/lang/String"), or null if not an object type
-
-