Class SignatureUtils

java.lang.Object
com.mebigfatguy.fbcontrib.utils.SignatureUtils

public final class SignatureUtils extends Object
a collection of static methods for parsing signatures to find information out about them
  • Field Details

    • PRIMITIVE_TYPES

      public static final Set<String> PRIMITIVE_TYPES
    • TWO_SLOT_TYPES

      private static final Set<String> TWO_SLOT_TYPES
    • CLASS_COMPONENT_DELIMITER

      private static final Pattern CLASS_COMPONENT_DELIMITER
    • ANONYMOUS_COMPONENT

      private static final Pattern ANONYMOUS_COMPONENT
    • ECLIPSE_WEIRD_SIG_CHARS

      private static final String ECLIPSE_WEIRD_SIG_CHARS
      See Also:
    • PRIMITIVE_NAME_TO_SIG

      private static final Map<String,String> PRIMITIVE_NAME_TO_SIG
  • Constructor Details

    • SignatureUtils

      private SignatureUtils()
      private to reinforce the helper status of the class
  • Method Details

    • isInheritedMethod

      public static boolean isInheritedMethod(org.apache.bcel.classfile.JavaClass cls, String methodName, String signature) throws ClassNotFoundException
      Throws:
      ClassNotFoundException
    • getPackageName

      public static String getPackageName(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(String packName1, 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 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, String methodName, String signature)
    • getParameterSlotAndSignatures

      public static Map<Integer,String> getParameterSlotAndSignatures(boolean methodIsStatic, 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 List<String> getParameterSignatures(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 String getReturnSignature(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(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(String genericSignature, String regularSignature)
    • getSignatureSize

      public static int getSignatureSize(String signature)
    • stripSignature

      @DottedClassName public static String stripSignature(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 String trimSignature(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 String classToSignature(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 String toArraySignature(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 String getNonAnonymousPortion(String className)
      Parameters:
      className - the name of the class
      Returns:
      the class name, discarding any anonymous component
    • isPlainStringConvertableClass

      public static boolean isPlainStringConvertableClass(@SlashedClassName String className)
    • isWonkyEclipseSignature

      private static boolean isWonkyEclipseSignature(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