Package eu.bandm.tools.paisley
Class ReflectionPatterns
java.lang.Object
eu.bandm.tools.paisley.ReflectionPatterns
@Generated(generator="eu.bandm.tools.expander",
version="",
timestamp="2025-12-18T16:24:38")
public abstract class ReflectionPatterns
extends Object
Static factory methods for creating patterns for runtime type
information.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA function that extracts data from a target object by reflection. -
Method Summary
Modifier and TypeMethodDescriptionstatic <A,B extends A>
Motif<B, A> forInstancesOf(Class<? extends A> src, Class<? extends B> tgt) Returns a motif that delegates to the hole after dynamic type checking.forInstancesOf(Class<? extends B> cls) Returns a motif that delegates to the hole after dynamic type checking.static <A,B extends A>
Pattern<A> forInstancesOf(Class<? extends B> cls, Pattern<? super B> body) Returns a pattern that delegates to a given pattern after dynamic type checking.isInstanceOf(Class<?> cls) Returns a pattern that matches objects of a given class.static <A extends Annotation>
Pattern<AnnotatedElement> 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>> body) Returns a pattern that matches a given pattern against the class of the target 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.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.
-
Method Details
-
isInstanceOf
Returns a pattern that matches objects of a given class.A pattern returned by this method is deterministic and binds no variables.
- Parameters:
cls- the class of objects to match.- Returns:
- a pattern that matches objects of type
cls, determined as if by invokingClass.isInstance(Object). - Throws:
NullPointerException- ifclsis null- See Also:
-
forInstancesOf
public static <A,B extends A> Pattern<A> forInstancesOf(Class<? extends B> cls, Pattern<? super B> body) Returns a pattern that delegates to a given pattern after dynamic type checking.- Type Parameters:
A- the target type of objects to match againstB- the subtype to check for- Parameters:
cls- the class to be checked against.body- the pattern to match against objects of the class.- Returns:
- a pattern that matches whatever the pattern
bodymatches, but only if the target object is an instance ofcls, determined as if by successfully invokingClass.cast(java.lang.Object). - Throws:
NullPointerException- ifclsorbodyis null- See Also:
-
forInstancesOf
public static <A,B extends A> Motif<B,A> forInstancesOf(Class<? extends A> src, Class<? extends B> tgt) Returns a motif that delegates to the hole after dynamic type checking.- Type Parameters:
A- the target type of objects to match againstB- the subtype to check for- Parameters:
src- the target type of objects to match againsttgt- the class to be checked against- Returns:
- a motif that matches the hole pattern against its target, but only if
the target object is an instance of
tgt, determined as if by successfully invokingClass.cast(java.lang.Object). - Throws:
NullPointerException- ifsrcortgtis null- See Also:
-
forInstancesOf
Returns a motif that delegates to the hole after dynamic type checking.- Type Parameters:
B- the subtype to check for- Parameters:
cls- the class to be checked against- Returns:
- a motif that matches the hole pattern against its target, but only if
the target object is an instance of
tgt, determined as if by successfully invokingClass.cast(java.lang.Object). - Throws:
NullPointerException- ifclsis null- See Also:
-
matchField
Returns a pattern that matches a given pattern against the value of a field of the target object.Exceptions raised by the reflection machinery cause the pattern to fail silently.
- Parameters:
field- the field to match against.body- the pattern to match against the field.- Returns:
- a pattern that matches
bodyagainst the value of the fieldfieldof the target - Throws:
NullPointerException- iffieldorbodyis null- See Also:
-
matchMethod
Returns a pattern that matches a given pattern against the return value of a method of the target object.Exceptions raised by the reflection machinery cause the pattern to fail silently.
- Parameters:
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.- Returns:
- a pattern that matches
bodyagainst the return value ofmethod.invoke(target, args) - Throws:
NullPointerException- iffield,bodyorargsis null- See Also:
-
matchClass
Returns a pattern that matches a given pattern against the class of the target object.- Type Parameters:
A- the target type of objects to match against- Parameters:
body- the pattern to match against the class- Returns:
- a pattern that matches
bodyagainst the class of its target object - See Also:
-
matchAnnotation
public static <A extends Annotation> Pattern<AnnotatedElement> matchAnnotation(Class<? extends A> cls, Pattern<? super A> body) Returns a pattern that matches a given pattern against an annotation of the target object.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().- Type Parameters:
A- the target type of annotations to match against- Parameters:
cls- the type of annotations to matchbody- the pattern to match against annotations- Returns:
- a pattern that matches
bodyagainst an annotation of typeclson its target object - Throws:
NullPointerException- ifclsorbodyis null- See Also:
-