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.
  • Method Details

    • isInstanceOf

      public static Pattern<Object> isInstanceOf(Class<?> cls)
      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 invoking Class.isInstance(Object).
      Throws:
      NullPointerException - if cls is 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 against
      B - 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 body matches, but only if the target object is an instance of cls, determined as if by successfully invoking Class.cast(java.lang.Object).
      Throws:
      NullPointerException - if cls or body is 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 against
      B - the subtype to check for
      Parameters:
      src - the target type of objects to match against
      tgt - 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 invoking Class.cast(java.lang.Object).
      Throws:
      NullPointerException - if src or tgt is null
      See Also:
    • forInstancesOf

      public static <B> Motif<B,Object> forInstancesOf(Class<? extends B> cls)
      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 invoking Class.cast(java.lang.Object).
      Throws:
      NullPointerException - if cls is null
      See Also:
    • matchField

      public 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.

      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 body against the value of the field field of the target
      Throws:
      NullPointerException - if field or body is null
      See Also:
    • matchMethod

      public 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.

      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 body against the return value of method.invoke(target, args)
      Throws:
      NullPointerException - if field, body or args is null
      See Also:
    • matchClass

      public 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.
      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 body against 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 match
      body - the pattern to match against annotations
      Returns:
      a pattern that matches body against an annotation of type cls on its target object
      Throws:
      NullPointerException - if cls or body is null
      See Also: