Interface MethodMatchers
- All Known Implementing Classes:
MethodMatchersBuilder
,MethodMatchersList
,NoneMethodMatchers
Immutable helper interface to help to identify method with given a Type, Name and Parameters.
The starting point to define a MethodMatchers is create()
.
It is required to provide the following:
- a type definition
- a method name
- a list of parameters, 1 or more call to:
(It is possible to define several parameters matcher, to match several method signatures)
-
MethodMatchers.ParametersBuilder.addWithoutParametersMatcher()
-
MethodMatchers.ParametersBuilder.addParametersMatcher(String...)
-
MethodMatchers.ParametersBuilder.addParametersMatcher(Predicate<List<Type>>)
-
MethodMatchers.ParametersBuilder.withAnyParameters()
// same as addParametersMatcher((Listparameters) -> true)
-
Examples:
- match method "a" and "b" from any type, and without parameters: MethodMatchers.create().ofAnyType().names("a", "b").addWithoutParametersMatcher().build(); - match method "a" and "b" from (subtype) of A, and "b" and "c" from B, with any parameters: MethodMatchers.or( MethodMatchers.create().ofSubTypes("A").names("a", "b").withAnyParameters().build(), MethodMatchers.create().ofSubTypes("B").names("b", "c").withAnyParameters().build()); - match method "f" with any type and with: MethodMatchers.create().ofAnyType().names("f") - one parameter of type either int or long .addParametersMatcher("int").addParametersMatcher("long"); - one parameter of type int or one parameter of type long with any other number of parameters .addParametersMatcher("int").addParametersMatcher(params -> params.size() >= 1 && params.get(0).is("long")); .build() - match any method with any type, with parameter int, any, int: MethodMatchers.create().ofAnyType().anyName().addParametersMatcher("int", ANY, "int").build(); - match any type AND method name "a" OR "b" AND parameter int OR long: MethodMatchers.create().ofAnyType().names("a", "b").addParametersMatcher("int").addParametersMatcher("long").build()
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
static interface
static interface
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic MethodMatchers.TypeBuilder
create()
boolean
boolean
boolean
matches
(MethodReferenceTree methodReferenceTree) boolean
matches
(MethodTree methodTree) boolean
matches
(NewClassTree newClassTree) static MethodMatchers
none()
static MethodMatchers
or
(List<? extends MethodMatchers> matchers) static MethodMatchers
or
(MethodMatchers... matchers) Combine multiple method matcher.
-
Field Details
-
ANY
- See Also:
-
CONSTRUCTOR
- See Also:
-
-
Method Details
-
matches
-
matches
-
matches
-
matches
-
matches
-
create
-
or
Combine multiple method matcher. The matcher will match any of the given matcher. -
or
-
none
-