Class SignatureParser


  • public class SignatureParser
    extends Object
    Parses type signature strings used to identify methods and constructors in input.
    • Field Detail

      • DOT_DELIMITED_IDS

        public static final String DOT_DELIMITED_IDS
        Regex to match a sequence of identifiers (or <init>) separated by periods. Corresponds to package names, fully-qualified classnames, or method names with fully-qualified classname.
        See Also:
        Constant Field Values
      • SIGNATURE_PATTERN

        private static final Pattern SIGNATURE_PATTERN
        Naive regex to match a method signature consisting of a fully-qualified method name followed by anything in parentheses. The parentheses are expected to contain argument types, but the pattern permits anything.

        Capturing group 1 matches the fully-qualified method name, and capturing group 2 matches the contents of the parentheses.

    • Constructor Detail

      • SignatureParser

        public SignatureParser()
    • Method Detail

      • parse

        public static AccessibleObject parse​(String signature,
                                             AccessibilityPredicate accessibility,
                                             ReflectionPredicate reflectionPredicate)
                                      throws SignatureParseException,
                                             FailedPredicateException
        Parses a fully-qualified signature and returns the corresponding java.lang.reflect.AccessibleObject.

        A signature is expected to have the form

        • package-name.classname.method-name(argument-list) for a method,
        • package-name.classname.<init>(argument-list) or package-name.classname(argument-list) for a constructor.

        where package-name is a period-separated list of identifiers, and argument-list is a comma-separated (spaces-allowed) list of fully-qualified Java raw types. Array types have the format element-type[].

        Parameters:
        signature - the string to parse: a signature string for a method or constructor, in the above format
        accessibility - the predicate for determining whether the method or constructor is accessible
        reflectionPredicate - the predicate for checking reflection policy
        Returns:
        the AccessibleObject for the method or constructor represented by the string
        Throws:
        IllegalArgumentException - if the string does not have the format of a signature
        SignatureParseException - if the signature is not fully-qualified, or the class, an argument type, or the method or constructor is not found using reflection
        FailedPredicateException - if the accessibility or reflection predicate returns false on the class or the method or constructor