public abstract class ReflectionPatterns extends Object
| Modifier and Type | Method and Description |
|---|---|
static <A,B extends A> |
forInstancesOf(Class<? extends A> src,
Class<? extends B> tgt) |
static <B> Motif<B,Object> |
forInstancesOf(Class<? extends B> cls) |
static <A,B extends A> |
forInstancesOf(Class<? extends B> cls,
Pattern<? super B> body)
Returns a pattern that delegates to a given pattern after dynamic
type checking.
|
static Pattern<Object> |
isInstanceOf(Class<?>... cls)
Deprecated.
|
static Pattern<Object> |
isInstanceOf(Class<?> cls)
Returns a pattern that matches objects of a given class.
|
static <A extends Annotation> |
matchAnnotation(Class<? extends A> cls,
Pattern<? super A> body)
Returns a pattern that matches a given pattern against an annotation
of the target object.
|
static <A> Pattern<A> |
matchClass(Pattern<? super Class<? extends A>> p)
Returns a pattern that matches a given pattern against the class
of the target object.
|
static Pattern<Object> |
matchField(Field field,
Pattern<Object> body)
Returns a pattern that matches a given pattern against the value
of a field of the target object.
|
static Pattern<Object> |
matchMethod(Method method,
Pattern<Object> body,
Object... args)
Returns a pattern that matches a given pattern against the
return value of a method of the target object.
|
public static Pattern<Object> isInstanceOf(Class<?> cls)
A pattern returned by this method is deterministic and binds no variables.
cls - the class of objects to match.cls,
determined as if by invoking Class.isInstance(Object).NullPointerException - if cls is null.forInstancesOf(Class, Pattern)@Deprecated public static Pattern<Object> isInstanceOf(Class<?>... cls)
public static <A,B extends A> Pattern<A> forInstancesOf(Class<? extends B> cls, Pattern<? super B> body)
cls - the class to be checked against.body - the pattern to match against objects of the class.body
matches, but only if the target object is an instance of cls, determined as if by successfully invoking Class.cast(java.lang.Object).NullPointerException - if cls is null.NullPointerException - if body is null.isInstanceOf(Class)public static <A,B extends A> Motif<B,A> forInstancesOf(Class<? extends A> src, Class<? extends B> tgt)
public static Pattern<Object> matchField(Field field, Pattern<Object> body)
Exceptions raised by the reflection machinery cause the pattern to fail silently.
field - the field to match against.body - the pattern to match against the field.NullPointerException - if field is null.NullPointerException - if body is null.Field.get(Object)public static Pattern<Object> matchMethod(Method method, Pattern<Object> body, Object... args)
Exceptions raised by the reflection machinery cause the pattern to fail silently.
method - the method to invoke for the match.body - the pattern to match against the method's return value.args - the arguments to invoke the method with.IllegalArgumentException - if field is null.IllegalArgumentException - if body is null.IllegalArgumentException - if args is null.Method.invoke(Object, Object...)public static <A> Pattern<A> matchClass(Pattern<? super Class<? extends A>> p)
p - the pattern to match against the class.Object.getClass()public static <A extends Annotation> Pattern<AnnotatedElement> matchAnnotation(Class<? extends A> cls, Pattern<? super A> body)
If no such annotation is present on the target object, the
match fails silently. The absence of an annotation can
be matched negatively by matchAnnotation(cls,
Pattern.any()).noMatch().
IllegalArgumentException - if cls is null.AnnotatedElement.getAnnotation(Class)see also the complete user documentation .