Package com.mebigfatguy.fbcontrib.utils
Class SignatureUtils
- java.lang.Object
-
- com.mebigfatguy.fbcontrib.utils.SignatureUtils
-
public final class SignatureUtils extends java.lang.Object
a collection of static methods for parsing signatures to find information out about them
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.Pattern
ANONYMOUS_COMPONENT
private static java.util.regex.Pattern
CLASS_COMPONENT_DELIMITER
private static java.lang.String
ECLIPSE_WEIRD_SIG_CHARS
private static java.util.Map<java.lang.String,java.lang.String>
PRIMITIVE_NAME_TO_SIG
static java.util.Set<java.lang.String>
PRIMITIVE_TYPES
private static java.util.Set<java.lang.String>
TWO_SLOT_TYPES
-
Constructor Summary
Constructors Modifier Constructor Description private
SignatureUtils()
private to reinforce the helper status of the class
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.String
classToSignature(java.lang.String className)
returns a slashed or dotted class name into a signature, like java/lang/String -- Ljava/lang/String; Primitives and arrays are accepted.static boolean
compareGenericSignature(java.lang.String genericSignature, java.lang.String regularSignature)
private static org.apache.bcel.classfile.JavaClass
findInheritedMethod(org.apache.bcel.classfile.JavaClass[] classes, java.lang.String methodName, java.lang.String signature)
static int
getFirstRegisterSlot(org.apache.bcel.classfile.Method m)
returns the first open register slot after parametersstatic java.lang.String
getNonAnonymousPortion(java.lang.String className)
static int
getNumParameters(java.lang.String methodSignature)
returns the number of parameters in this method signaturestatic java.lang.String
getPackageName(java.lang.String className)
parses the package name from a fully qualified class namestatic java.util.List<java.lang.String>
getParameterSignatures(java.lang.String methodSignature)
returns a List of parameter signaturesstatic java.util.Map<java.lang.Integer,java.lang.String>
getParameterSlotAndSignatures(boolean methodIsStatic, java.lang.String methodSignature)
returns a Map that represents the type of the parameter in slot xstatic java.lang.String
getReturnSignature(java.lang.String methodSig)
gets the return type signature from a method signaturestatic int
getSignatureSize(java.lang.String signature)
static java.lang.String
getTypeCodeSignature(int typeCode)
converts a primitive type code to a signaturestatic boolean
isInheritedMethod(org.apache.bcel.classfile.JavaClass cls, java.lang.String methodName, java.lang.String signature)
static boolean
isPlainStringConvertableClass(java.lang.String className)
private static boolean
isWonkyEclipseSignature(java.lang.String sig, int startIndex)
Eclipse makes weird class signatures.static boolean
similarPackages(java.lang.String packName1, java.lang.String packName2, int depth)
returns whether or not the two packages have the same first 'depth' parts, if they existstatic java.lang.String
stripSignature(java.lang.String signature)
converts a signature, like Ljava/lang/String; into a dotted class name.static java.lang.String
toArraySignature(java.lang.String typeName)
Converts a type name into an array signature.static java.lang.String
trimSignature(java.lang.String signature)
converts a signature, like Ljava/lang/String; into a slashed class name.
-
-
-
Field Detail
-
PRIMITIVE_TYPES
public static final java.util.Set<java.lang.String> PRIMITIVE_TYPES
-
TWO_SLOT_TYPES
private static final java.util.Set<java.lang.String> TWO_SLOT_TYPES
-
CLASS_COMPONENT_DELIMITER
private static final java.util.regex.Pattern CLASS_COMPONENT_DELIMITER
-
ANONYMOUS_COMPONENT
private static final java.util.regex.Pattern ANONYMOUS_COMPONENT
-
ECLIPSE_WEIRD_SIG_CHARS
private static final java.lang.String ECLIPSE_WEIRD_SIG_CHARS
- See Also:
- Constant Field Values
-
PRIMITIVE_NAME_TO_SIG
private static final java.util.Map<java.lang.String,java.lang.String> PRIMITIVE_NAME_TO_SIG
-
-
Method Detail
-
isInheritedMethod
public static boolean isInheritedMethod(org.apache.bcel.classfile.JavaClass cls, java.lang.String methodName, java.lang.String signature) throws java.lang.ClassNotFoundException
- Throws:
java.lang.ClassNotFoundException
-
getPackageName
public static java.lang.String getPackageName(java.lang.String className)
parses the package name from a fully qualified class name- Parameters:
className
- the class in question- Returns:
- the package of the class
-
similarPackages
public static boolean similarPackages(java.lang.String packName1, java.lang.String packName2, int depth)
returns whether or not the two packages have the same first 'depth' parts, if they exist- Parameters:
packName1
- the first package to checkpackName2
- the second package to checkdepth
- the number of package parts to check- Returns:
- if they are similar
-
getTypeCodeSignature
public static java.lang.String getTypeCodeSignature(int typeCode)
converts a primitive type code to a signature- Parameters:
typeCode
- the raw JVM type value- Returns:
- the signature of the type
-
findInheritedMethod
@Nullable private static org.apache.bcel.classfile.JavaClass findInheritedMethod(org.apache.bcel.classfile.JavaClass[] classes, java.lang.String methodName, java.lang.String signature)
-
getParameterSlotAndSignatures
public static java.util.Map<java.lang.Integer,java.lang.String> getParameterSlotAndSignatures(boolean methodIsStatic, java.lang.String methodSignature)
returns a Map that represents the type of the parameter in slot x- Parameters:
methodIsStatic
- if the method is static, causes where to start counting from, slot 0 or 1methodSignature
- the signature of the method to parse- Returns:
- a map of parameter types (expect empty slots when doubles/longs are used
-
getParameterSignatures
public static java.util.List<java.lang.String> getParameterSignatures(java.lang.String methodSignature)
returns a List of parameter signatures- Parameters:
methodSignature
- the signature of the method to parse- Returns:
- a list of parameter signatures
-
getReturnSignature
public static java.lang.String getReturnSignature(java.lang.String methodSig)
gets the return type signature from a method signature- Parameters:
methodSig
- the signature of the method- Returns:
- the signature of the return type, or ? if a bogus method signature is given
-
getNumParameters
public static int getNumParameters(java.lang.String methodSignature)
returns the number of parameters in this method signature- Parameters:
methodSignature
- the method signature to parse- Returns:
- the number of parameters
-
getFirstRegisterSlot
public static int getFirstRegisterSlot(org.apache.bcel.classfile.Method m)
returns the first open register slot after parameters- Parameters:
m
- the method for which you want the parameters- Returns:
- the first available register slot
-
compareGenericSignature
public static boolean compareGenericSignature(java.lang.String genericSignature, java.lang.String regularSignature)
-
getSignatureSize
public static int getSignatureSize(java.lang.String signature)
-
stripSignature
@DottedClassName public static java.lang.String stripSignature(java.lang.String signature)
converts a signature, like Ljava/lang/String; into a dotted class name.- Parameters:
signature
- a class signature, must not be null- Returns:
- the dotted class name
-
trimSignature
@SlashedClassName public static java.lang.String trimSignature(java.lang.String signature)
converts a signature, like Ljava/lang/String; into a slashed class name.- Parameters:
signature
- the class signature- Returns:
- the slashed class name
-
classToSignature
@Nullable public static java.lang.String classToSignature(java.lang.String className)
returns a slashed or dotted class name into a signature, like java/lang/String -- Ljava/lang/String; Primitives and arrays are accepted.- Parameters:
className
- the class name to convert- Returns:
- the signature format of the class
-
toArraySignature
@Nullable public static java.lang.String toArraySignature(java.lang.String typeName)
Converts a type name into an array signature. Accepts slashed or dotted classnames, or type signatures.- Parameters:
typeName
- the class name to generate an array signature from- Returns:
- the array signature
-
getNonAnonymousPortion
public static java.lang.String getNonAnonymousPortion(java.lang.String className)
- Parameters:
className
- the name of the class- Returns:
- the class name, discarding any anonymous component
-
isPlainStringConvertableClass
public static boolean isPlainStringConvertableClass(@SlashedClassName java.lang.String className)
-
isWonkyEclipseSignature
private static boolean isWonkyEclipseSignature(java.lang.String sig, int startIndex)
Eclipse makes weird class signatures.- Parameters:
sig
- the signature in type tablestartIndex
- the index into the signature where the wonkyness begins- Returns:
- if this signature has eclipse meta chars
-
-