Interface MethodMatchers
-
- All Known Implementing Classes:
MethodMatchersBuilder
,MethodMatchersList
,NoneMethodMatchers
@Beta public interface MethodMatchers
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
-
MethodMatchers.TypeBuilder.ofSubTypes(String...)
-
MethodMatchers.TypeBuilder.ofTypes(String...)
-
TypeBuilder#ofType(Predicate
) -
MethodMatchers.TypeBuilder.ofAnyType()
// same as ofType(type -> true)
-
- a method name
-
MethodMatchers.NameBuilder.names(String...)
-
MethodMatchers.NameBuilder.constructor()
-
NameBuilder#name(Predicate
) -
MethodMatchers.NameBuilder.anyName()
// same as name(name -> true)
-
- 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...)
-
ParametersBuilder#addParametersMatcher(Predicate
- >)
-
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 Classes Modifier and Type Interface Description static interface
MethodMatchers.NameBuilder
static interface
MethodMatchers.ParametersBuilder
static interface
MethodMatchers.TypeBuilder
-
Field Summary
Fields Modifier and Type Field Description static String
ANY
static String
CONSTRUCTOR
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static MethodMatchers.TypeBuilder
create()
boolean
matches(Symbol symbol)
boolean
matches(MethodInvocationTree mit)
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 Detail
-
ANY
static final String ANY
- See Also:
- Constant Field Values
-
CONSTRUCTOR
static final String CONSTRUCTOR
- See Also:
- Constant Field Values
-
-
Method Detail
-
matches
boolean matches(NewClassTree newClassTree)
-
matches
boolean matches(MethodInvocationTree mit)
-
matches
boolean matches(MethodTree methodTree)
-
matches
boolean matches(MethodReferenceTree methodReferenceTree)
-
matches
boolean matches(Symbol symbol)
-
create
static MethodMatchers.TypeBuilder create()
-
or
static MethodMatchers or(MethodMatchers... matchers)
Combine multiple method matcher. The matcher will match any of the given matcher.
-
or
static MethodMatchers or(List<? extends MethodMatchers> matchers)
-
none
static MethodMatchers none()
-
-