public final class MethodMatchers extends Object
MethodMatcher
implementations.
This class is not meant to be instantiated but is usually imported statically in order to allow for improving the readability of code.
Modifier and Type | Method and Description |
---|---|
static JunctionMethodMatcher |
any()
Returns a method matcher that matches any method.
|
static JunctionMethodMatcher |
canThrow(Class<? extends Throwable> exceptionType)
Selects a method depending on whether they can throw a specific exception.
|
static JunctionMethodMatcher |
canThrow(TypeDescription exceptionType)
Selects a method depending on whether they can throw a specific exception.
|
static JunctionMethodMatcher |
hasSameByteCodeSignatureAs(Constructor<?> constructor)
Selects methods with identical signature to the given method description where the return type
is considered to be part of the signature.
|
static JunctionMethodMatcher |
hasSameByteCodeSignatureAs(Method method)
Selects methods with identical signature to the given method description where the return type
is considered to be part of the signature.
|
static JunctionMethodMatcher |
hasSameByteCodeSignatureAs(MethodDescription methodDescription)
Selects methods with identical signature to the given method description where the return type
is considered to be part of the signature.
|
static JunctionMethodMatcher |
hasSameJavaCompilerSignatureAs(Constructor<?> constructor)
Checks if a method has a Java compiler equal signature to another method which includes the name of the method
and the exact types and order of its parameters.
|
static JunctionMethodMatcher |
hasSameJavaCompilerSignatureAs(Method method)
Checks if a method has a Java compiler equal signature to another method which includes the name of the method
and the exact types and order of its parameters.
|
static JunctionMethodMatcher |
hasSameJavaCompilerSignatureAs(MethodDescription methodDescription)
Checks if a method has a Java compiler equal signature to another method which includes the name of the method
and the exact types and order of its parameters.
|
static JunctionMethodMatcher |
is(Constructor<?> constructor)
Selects an exact constructor.
|
static JunctionMethodMatcher |
is(Method method)
Selects an exact method.
|
static JunctionMethodMatcher |
is(MethodDescription methodDescription)
A method matcher that matches a given method description.
|
static JunctionMethodMatcher |
isAnnotatedBy(Class<? extends Annotation> annotationType)
Checks if a method is annotated by a given parameter.
|
static JunctionMethodMatcher |
isBridge()
Selects a method when it is marked as a bridge method.
|
static JunctionMethodMatcher |
isBridgeMethodCompatibleTo(Method method)
Determines if a method could be the target of the given method for a compile time bridge.
|
static JunctionMethodMatcher |
isBridgeMethodCompatibleTo(MethodDescription methodDescription)
Determines if a method could be the target of the given method for a compile time bridge.
|
static JunctionMethodMatcher |
isConstructor()
Selects methods that are constructors.
|
static JunctionMethodMatcher |
isDeclaredBy(Class<?> type)
Selects method that are declared by a given type.
|
static JunctionMethodMatcher |
isDeclaredBy(TypeDescription type)
Selects method that are declared by a given type.
|
static JunctionMethodMatcher |
isDeclaredByAny(Class<?>... typeDescription)
Creates a method matcher that matches any method that is declared by any of the given types.
|
static JunctionMethodMatcher |
isDeclaredByAny(TypeDescription... typeDescription)
Creates a method matcher that matches any method that is declared by any of the given types.
|
static JunctionMethodMatcher |
isDeclaredBySubtypeOf(Class<?> type)
Selects methods that are declared by any subtype of the given type.
|
static JunctionMethodMatcher |
isDeclaredBySubtypeOf(TypeDescription type)
Selects methods that are declared by any subtype of the given type.
|
static JunctionMethodMatcher |
isDeclaredBySuperTypeOf(Class<?> type)
Selects methods that are declared by any subtype of the given type.
|
static JunctionMethodMatcher |
isDeclaredBySuperTypeOf(TypeDescription type)
Selects methods that are declared by any super type of the given type.
|
static JunctionMethodMatcher |
isDefaultFinalizer()
Only matches the default finalizer method as declared in
Object.finalize() but not methods that
override this method. |
static JunctionMethodMatcher |
isEquals()
Matches the
Object.equals(Object) } method, independently of the method being overridden. |
static JunctionMethodMatcher |
isFinal()
Selects a method when it is
final . |
static JunctionMethodMatcher |
isFinalizer()
Matches a method for being a finalizer method which is declared by any class.
|
static JunctionMethodMatcher |
isGetter()
Matches methods that represent a Java bean getter, i.e.
|
static JunctionMethodMatcher |
isGetter(Class<?> type)
Matches methods that represent a Java bean getter, i.e.
|
static JunctionMethodMatcher |
isGetter(TypeDescription type)
Matches methods that represent a Java bean getter, i.e.
|
static JunctionMethodMatcher |
isHashCode()
Matches the
Object.hashCode() method, independently of the method being overridden. |
static JunctionMethodMatcher |
isMethod()
Selects methods that are not constructors or type initializers.
|
static JunctionMethodMatcher |
isNative()
Selects a method when it is
native . |
static JunctionMethodMatcher |
isOverridable()
Selects methods that are overridable, i.e.
|
static JunctionMethodMatcher |
isPackagePrivate()
Selects a method when it is package private, i.e.
|
static JunctionMethodMatcher |
isPrivate()
Selects a method when it is
private . |
static JunctionMethodMatcher |
isProtected()
Selects a method when it is
protected . |
static JunctionMethodMatcher |
isPublic()
Selects a method when it is
public . |
static JunctionMethodMatcher |
isSetter()
Matches methods that represent a Java bean setter, i.e.
|
static JunctionMethodMatcher |
isSetter(Class<?> type)
Matches methods that represent a Java bean setter, i.e.
|
static JunctionMethodMatcher |
isSetter(TypeDescription type)
Matches methods that represent a Java bean setter, i.e.
|
static JunctionMethodMatcher |
isStatic()
Selects a method when it is
static . |
static JunctionMethodMatcher |
isStrict()
Selects a method when it is
strictfp . |
static JunctionMethodMatcher |
isSynchronized()
Selects a method when it is
synchronized . |
static JunctionMethodMatcher |
isSynthetic()
Selects a method when it is
synthetic . |
static JunctionMethodMatcher |
isToString()
Matches the
Object.toString() method, independently of the method being overridden. |
static JunctionMethodMatcher |
isTypeInitializer()
Checks if a method is representing a type initializer.
|
static JunctionMethodMatcher |
isVarArgs()
Selects a method when it is defined using a var args argument.
|
static JunctionMethodMatcher |
isVisibilityBridge()
Matches methods that represent a so-called visibility bridge.
|
static JunctionMethodMatcher |
isVisibleTo(Class<?> typeDescription)
Checks if a method is visible for a given type.
|
static JunctionMethodMatcher |
isVisibleTo(TypeDescription typeDescription)
Checks if a method is visible for a given type.
|
static JunctionMethodMatcher |
nameContains(String infix)
Selects a method by its exact name infix.
|
static JunctionMethodMatcher |
nameContainsIgnoreCase(String infix)
Selects a method by its case insensitive exact name infix.
|
static JunctionMethodMatcher |
named(String name)
Selects a method by its exact name.
|
static JunctionMethodMatcher |
namedIgnoreCase(String name)
Selects a method by its case insensitive, exact name.
|
static JunctionMethodMatcher |
nameEndsWith(String suffix)
Selects a method by its exact name suffix.
|
static JunctionMethodMatcher |
nameEndsWithIgnoreCase(String suffix)
Selects a method by its case insensitive exact name suffix.
|
static JunctionMethodMatcher |
nameMatches(String regex)
Selects a method by its name matching a regular expression.
|
static JunctionMethodMatcher |
nameStartsWith(String prefix)
Selects a method by its exact name prefix.
|
static JunctionMethodMatcher |
nameStartsWithIgnoreCase(String prefix)
Selects a method by its case insensitive exact name prefix.
|
static JunctionMethodMatcher |
none()
Returns a method matcher that matches no method.
|
static JunctionMethodMatcher |
not(MethodMatcher methodMatcher)
Inverts another method matcher.
|
static JunctionMethodMatcher |
returns(Class<?> type)
Selects a method by its exact return type.
|
static JunctionMethodMatcher |
returns(TypeDescription type)
Selects a method by its exact return type.
|
static JunctionMethodMatcher |
returnsSubtypeOf(Class<?> type)
Selects a method by its return type where only methods are matched that return a subtype of the given
type, including the given type itself.
|
static JunctionMethodMatcher |
returnsSubtypeOf(TypeDescription type)
Selects a method by its return type where only methods are matched that return a subtype of the given
type, including the given type itself.
|
static JunctionMethodMatcher |
returnsSupertypeOf(Class<?> type)
Selects a method by its return type where only methods are matched that return a super type of the given
type, including the given type itself.
|
static JunctionMethodMatcher |
returnsSupertypeOf(TypeDescription type)
Selects a method by its return type where only methods are matched that return a super type of the given
type, including the given type itself.
|
static JunctionMethodMatcher |
takesArguments(Class<?>... types)
Selects a method by its exact parameter types in their exact order.
|
static JunctionMethodMatcher |
takesArguments(int number)
Selects a method by the number of its parameters.
|
static JunctionMethodMatcher |
takesArguments(List<? extends TypeDescription> types)
Selects a method by its exact parameter types in their exact order.
|
static JunctionMethodMatcher |
takesArguments(TypeDescription... types)
Selects a method by its exact parameter types in their exact order.
|
static JunctionMethodMatcher |
takesArgumentsAsSubtypesOf(Class<?>... types)
Selects a method by its parameter types in their exact order where only parameter types are matched
that are subtypes of the given types, including the given type.
|
static JunctionMethodMatcher |
takesArgumentsAsSubtypesOf(List<? extends TypeDescription> types)
Selects a method by its parameter types in their exact order where only parameter types are matched
that are subtypes of the given types, including the given type.
|
static JunctionMethodMatcher |
takesArgumentsAsSubtypesOf(TypeDescription... types)
Selects a method by its parameter types in their exact order where only parameter types are matched
that are subtypes of the given types, including the given type.
|
static JunctionMethodMatcher |
takesArgumentsAsSuperTypesOf(Class<?>... types)
Selects a method by its parameter types in their exact order where only parameter types are matched
that are super types of the given types, including the given type.
|
static JunctionMethodMatcher |
takesArgumentsAsSuperTypesOf(List<? extends TypeDescription> types)
Selects a method by its parameter types in their exact order where only parameter types are matched
that are super types of the given types, including the given type.
|
static JunctionMethodMatcher |
takesArgumentsAsSuperTypesOf(TypeDescription... types)
Selects a method by its parameter types in their exact order where only parameter types are matched
that are super types of the given types, including the given type.
|
public static JunctionMethodMatcher named(String name)
name("foo")
will match foo
but not bar
or FOO
.name
- The name to be matched.public static JunctionMethodMatcher namedIgnoreCase(String name)
namedIgnoreCase("foo")
will match
foo
and FOO
but not bar
.name
- The name to be matched.public static JunctionMethodMatcher nameStartsWith(String prefix)
nameStartsWith("foo")
will match
foo
and foobar
but not bar
and FOO
.prefix
- The name prefix to be matched.public static JunctionMethodMatcher nameStartsWithIgnoreCase(String prefix)
nameStartsWithIgnoreCase("foo")
will match foo
, foobar
and FOO
but not bar
.prefix
- The name prefix to be matched.public static JunctionMethodMatcher nameEndsWith(String suffix)
nameEndsWith("bar")
will match bar
and
foobar
but not BAR
and foo
.suffix
- The name suffix to be matched.public static JunctionMethodMatcher nameEndsWithIgnoreCase(String suffix)
nameEndsWithIgnoreCase("bar")
will match bar
, foobar
and BAR
but not foo
.suffix
- The name suffix to be matched.public static JunctionMethodMatcher nameContains(String infix)
nameContains("a")
will
match bar
, foobar
and BaR
but not foo
and BAR
.infix
- The name infix to be matched.public static JunctionMethodMatcher nameContainsIgnoreCase(String infix)
nameContainsIgnoreCase("a")
will match bar
, foobar
, BAR
and BAR
but not foo
.infix
- The name infix to be matched.public static JunctionMethodMatcher nameMatches(String regex)
matches("f(o){2}.*")
will
match foo
, foobar
but not Foo
or bar
.regex
- The regular expression to be matched.public static JunctionMethodMatcher isPublic()
public
.public static JunctionMethodMatcher isProtected()
protected
.public static JunctionMethodMatcher isPackagePrivate()
public static JunctionMethodMatcher isPrivate()
private
.public static JunctionMethodMatcher isFinal()
final
.public static JunctionMethodMatcher isStatic()
static
.public static JunctionMethodMatcher isSynchronized()
synchronized
.public static JunctionMethodMatcher isNative()
native
.public static JunctionMethodMatcher isStrict()
strictfp
.public static JunctionMethodMatcher isVarArgs()
public static JunctionMethodMatcher isSynthetic()
synthetic
.public static JunctionMethodMatcher isBridge()
public static JunctionMethodMatcher returns(Class<?> type)
type
- The return type of the method.type
.public static JunctionMethodMatcher returns(TypeDescription type)
type
- A description of the return type of the method.type
.public static JunctionMethodMatcher returnsSubtypeOf(Class<?> type)
type
- The return type that should be matched for the given method.type
.public static JunctionMethodMatcher returnsSubtypeOf(TypeDescription type)
type
- The description of the return type that should be matched for the given method.type
.public static JunctionMethodMatcher returnsSupertypeOf(Class<?> type)
type
- The return type that should be matched for the given method.type
.public static JunctionMethodMatcher returnsSupertypeOf(TypeDescription type)
type
- The description of the return type that should be matched for the given method.type
.public static JunctionMethodMatcher takesArguments(Class<?>... types)
types
- The parameter types of the method.types
.public static JunctionMethodMatcher takesArguments(TypeDescription... types)
types
- The parameter types of the method.types
.public static JunctionMethodMatcher takesArguments(List<? extends TypeDescription> types)
types
- A list of parameter types of the method. The list will not be copied.types
.public static JunctionMethodMatcher takesArguments(int number)
number
- The number of parameters of any matching method.number
parameters.public static JunctionMethodMatcher takesArgumentsAsSubtypesOf(Class<?>... types)
types
- The parameter types to match against.types
.public static JunctionMethodMatcher takesArgumentsAsSubtypesOf(TypeDescription... types)
types
- The parameter types to match against.types
.public static JunctionMethodMatcher takesArgumentsAsSubtypesOf(List<? extends TypeDescription> types)
types
- The parameter types to match against.types
.public static JunctionMethodMatcher takesArgumentsAsSuperTypesOf(Class<?>... types)
types
- The parameter types to match against.types
.public static JunctionMethodMatcher takesArgumentsAsSuperTypesOf(TypeDescription... types)
types
- The parameter types to match against.types
.public static JunctionMethodMatcher takesArgumentsAsSuperTypesOf(List<? extends TypeDescription> types)
types
- The parameter types to match against.types
.public static JunctionMethodMatcher canThrow(Class<? extends Throwable> exceptionType)
Error
or RuntimeException
can always be thrown.exceptionType
- The exception type to be thrown.exceptionType
.public static JunctionMethodMatcher canThrow(TypeDescription exceptionType)
Error
or RuntimeException
can always be thrown.exceptionType
- The exception type to be thrown.exceptionType
.public static JunctionMethodMatcher is(Method method)
method
- The method to match.public static JunctionMethodMatcher is(Constructor<?> constructor)
constructor
- The constructor to match.public static JunctionMethodMatcher is(MethodDescription methodDescription)
methodDescription
- The method description to be matched.public static JunctionMethodMatcher isMethod()
public static JunctionMethodMatcher isConstructor()
public static JunctionMethodMatcher isTypeInitializer()
DynamicType.Builder.invokable(MethodMatcher)
.public static JunctionMethodMatcher isVisibleTo(Class<?> typeDescription)
typeDescription
- The type to which a method should be visible.public static JunctionMethodMatcher isVisibleTo(TypeDescription typeDescription)
typeDescription
- The type to which a method should be visible.public static JunctionMethodMatcher isDeclaredBy(TypeDescription type)
type
- The type to match the method declaration against.public static JunctionMethodMatcher isDeclaredBy(Class<?> type)
type
- The type to match the method declaration against.public static JunctionMethodMatcher isDeclaredBySubtypeOf(TypeDescription type)
type
- The type to be matched against all declaring types of a method.public static JunctionMethodMatcher isDeclaredBySubtypeOf(Class<?> type)
type
- The type to be matched against all declaring types of a method.public static JunctionMethodMatcher isDeclaredBySuperTypeOf(TypeDescription type)
type
- The type to be matched against all declaring types of a method.public static JunctionMethodMatcher isDeclaredBySuperTypeOf(Class<?> type)
type
- The type to be matched against all declaring types of a method.public static JunctionMethodMatcher isDeclaredByAny(Class<?>... typeDescription)
typeDescription
- A list of types to match.public static JunctionMethodMatcher isDeclaredByAny(TypeDescription... typeDescription)
typeDescription
- A list of types to match.public static JunctionMethodMatcher isSetter()
void set...(T type)
.public static JunctionMethodMatcher isSetter(Class<?> type)
void set...(T type)
where T
represents type
.type
- The type of the setter.public static JunctionMethodMatcher isSetter(TypeDescription type)
void set...(T type)
where T
represents type
.type
- The type of the setter.public static JunctionMethodMatcher isGetter()
T is...()
or T get...()
.public static JunctionMethodMatcher isGetter(Class<?> type)
T is...()
or T get...()
where T
represents type
.type
- The type of the getter.public static JunctionMethodMatcher isGetter(TypeDescription type)
T is...()
or T get...()
where T
represents type
.type
- The type of the getter.public static JunctionMethodMatcher hasSameByteCodeSignatureAs(Method method)
method
- The method to match against.methodDescription
.public static JunctionMethodMatcher hasSameByteCodeSignatureAs(Constructor<?> constructor)
constructor
- The constructor to match against.methodDescription
.public static JunctionMethodMatcher hasSameByteCodeSignatureAs(MethodDescription methodDescription)
methodDescription
- The method to match against.methodDescription
.public static JunctionMethodMatcher hasSameJavaCompilerSignatureAs(Method method)
method
- The method to be matched against.public static JunctionMethodMatcher hasSameJavaCompilerSignatureAs(Constructor<?> constructor)
constructor
- The constructor to be matched against.public static JunctionMethodMatcher hasSameJavaCompilerSignatureAs(MethodDescription methodDescription)
methodDescription
- A description of the method signature to be matched against.public static JunctionMethodMatcher isBridgeMethodCompatibleTo(Method method)
method
- The bridge method to match against.public static JunctionMethodMatcher isAnnotatedBy(Class<? extends Annotation> annotationType)
annotationType
- The annotation type of interest.public static JunctionMethodMatcher isBridgeMethodCompatibleTo(MethodDescription methodDescription)
methodDescription
- A description of the bridge method to match against.public static JunctionMethodMatcher isVisibilityBridge()
public static JunctionMethodMatcher isOverridable()
public static JunctionMethodMatcher isDefaultFinalizer()
Object.finalize()
but not methods that
override this method.public static JunctionMethodMatcher isFinalizer()
public static JunctionMethodMatcher isHashCode()
Object.hashCode()
method, independently of the method being overridden.hashCode
method.public static JunctionMethodMatcher isEquals()
Object.equals(Object)
} method, independently of the method being overridden.equals
method.public static JunctionMethodMatcher isToString()
Object.toString()
method, independently of the method being overridden.toString
method.public static JunctionMethodMatcher not(MethodMatcher methodMatcher)
methodMatcher
- The method matcher to be inverted.true
if the methodMatcher
returns false
.public static JunctionMethodMatcher any()
true
.public static JunctionMethodMatcher none()
false
.Copyright © 2014. All rights reserved.