Package randoop.reflection
Class SignatureParser
- java.lang.Object
-
- randoop.reflection.SignatureParser
-
public class SignatureParser extends Object
Parses type signature strings used to identify methods and constructors in input.
-
-
Field Summary
Fields Modifier and Type Field Description static String
DOT_DELIMITED_IDS
Regex to match a sequence of identifiers (or<init>
) separated by periods.static String
ID_STRING
Regex for Java identifiers.private static Pattern
SIGNATURE_PATTERN
Naive regex to match a method signature consisting of a fully-qualified method name followed by anything in parentheses.
-
Constructor Summary
Constructors Constructor Description SignatureParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static AccessibleObject
parse(String signature, AccessibilityPredicate accessibility, ReflectionPredicate reflectionPredicate)
Parses a fully-qualified signature and returns the correspondingjava.lang.reflect.AccessibleObject
.
-
-
-
Field Detail
-
ID_STRING
public static final String ID_STRING
Regex for Java identifiers.- See Also:
- Constant Field Values
-
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.
-
-
Method Detail
-
parse
public static AccessibleObject parse(String signature, AccessibilityPredicate accessibility, ReflectionPredicate reflectionPredicate) throws SignatureParseException, FailedPredicateException
Parses a fully-qualified signature and returns the correspondingjava.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)
orpackage-name.classname(argument-list)
for a constructor.
where
package-name
is a period-separated list of identifiers, andargument-list
is a comma-separated (spaces-allowed) list of fully-qualified Java raw types. Array types have the formatelement-type[]
.- Parameters:
signature
- the string to parse: a signature string for a method or constructor, in the above formataccessibility
- the predicate for determining whether the method or constructor is accessiblereflectionPredicate
- 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 signatureSignatureParseException
- if the signature is not fully-qualified, or the class, an argument type, or the method or constructor is not found using reflectionFailedPredicateException
- if the accessibility or reflection predicate returns false on the class or the method or constructor
-
-