Class SignatureUtils


  • public final class SignatureUtils
    extends java.lang.Object
    a collection of static methods for parsing signatures to find information out about them
    • 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 parameters
      static java.lang.String getNonAnonymousPortion​(java.lang.String className)  
      static int getNumParameters​(java.lang.String methodSignature)
      returns the number of parameters in this method signature
      static java.lang.String getPackageName​(java.lang.String className)
      parses the package name from a fully qualified class name
      static java.util.List<java.lang.String> getParameterSignatures​(java.lang.String methodSignature)
      returns a List of parameter signatures
      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
      static java.lang.String getReturnSignature​(java.lang.String methodSig)
      gets the return type signature from a method signature
      static int getSignatureSize​(java.lang.String signature)  
      static java.lang.String getTypeCodeSignature​(int typeCode)
      converts a primitive type code to a signature
      static 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 exist
      static 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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
    • Constructor Detail

      • SignatureUtils

        private SignatureUtils()
        private to reinforce the helper status of the class
    • 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 check
        packName2 - the second package to check
        depth - 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 1
        methodSignature - 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 table
        startIndex - the index into the signature where the wonkyness begins
        Returns:
        if this signature has eclipse meta chars