Class InvocationMatcher
java.lang.Object
net.sourceforge.pmd.lang.java.types.InvocationMatcher
Matches a method or constructor call against a particular overload.
Use
parse(String) to create one. For example,
java.lang.String#toString() // match calls to toString on String instances
_#toString() // match calls to toString on any receiver
_#_() // match all calls to a method with no parameters
_#toString(_*) // match calls to a "toString" method with any number of parameters
_#eq(_, _) // match calls to an "eq" method that has 2 parameters of unspecified type
_#eq(java.lang.String, _) // like the previous, but the first parameter must be String
java.util.ArrayList#new(int) // match constructor calls of this overload of the ArrayList constructor
The receiver matcher (first half) is matched against the static type of the receiver of the call, and not the declaration site of the method, unless the called method is static, or a constructor.
The parameters are matched against the declared parameters types of the called overload, and not the actual argument types. In particular, for vararg methods, the signature should mention a single parameter, with an array type.
For example Integer.valueOf('0') will be matched by
_#valueOf(int) but not _#valueOf(char), which is
an overload that does not exist (the char is widened to an int,
so the int overload is selected).
Full EBNF grammar
(no whitespace is tolerated anywhere):
sig ::= type '#' method_name param_list
type ::= qname ( '[]' )* | '_'
method_name ::= '_' | ident | 'new'
param_list ::= '(_*)' | '(' type (',' type )* ')'
qname ::= java binary name
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA compound of several matchers (logical OR). -
Method Summary
Modifier and TypeMethodDescriptionbooleanmatchesCall(@Nullable InvocationNode node) Returns true if the call matches this matcher.booleanmatchesCall(@Nullable JavaNode node) static InvocationMatcherParses anInvocationMatcher.Parses aInvocationMatcher.CompoundInvocationMatcherwhich matches any of the provided matchers.
-
Method Details
-
matchesCall
-
matchesCall
Returns true if the call matches this matcher. This means, the called overload is the one identified by the argument matchers, and the actual qualifier type is a subtype of the one mentioned by the qualifier matcher. -
parseAll
Parses aInvocationMatcher.CompoundInvocationMatcherwhich matches any of the provided matchers.- Parameters:
first- First signature, in the format described on this classrest- Other signatures, in the format described on this class- Returns:
- A sig matcher
- Throws:
IllegalArgumentException- If any signature is malformed (see EBNF)NullPointerException- If any signature is null- See Also:
-
parse
Parses anInvocationMatcher.- Parameters:
sig- A signature in the format described on this class- Returns:
- A sig matcher
- Throws:
IllegalArgumentException- If the signature is malformed (see EBNF)NullPointerException- If the signature is null- See Also:
-