Class BaseMatcher<T extends Member, M extends BaseMatcher<T,M>>

java.lang.Object
dev.derklaro.reflexion.matcher.BaseMatcher<T,M>
Type Parameters:
T - the type of the class member matched by this matcher.
M - the type of the matcher itself.
All Implemented Interfaces:
Predicate<T>
Direct Known Subclasses:
ConstructorMatcher, FieldMatcher, MethodMatcher

public abstract class BaseMatcher<T extends Member, M extends BaseMatcher<T,M>> extends Object implements Predicate<T>
The base for all matcher which can match some kind of member in a class.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected Predicate<T>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    and(@NotNull Predicate<? super T> other)
    Composes the current matching predicate with the supplied one using an AND operation.
    denyModifier(int mod)
    Checks if the given member doesn't have the given modifier.
    denyModifiers(int... mods)
    Checks if the given member doesn't have all the given modifiers.
    derivedType(@NotNull Function<T,Class<?>> typeReader, @NotNull Class<?> expectedType)
    Checks if the supplied type from the reader function is a derived instance of the given type (input instanceof expected).
    derivedTypeAt(@NotNull Function<T, Class<?>[]> reader, @NotNull Class<?> expectedType, int idx)
    Checks if the type array extracted from the target member has the given type at the given index (input instanceof expected).
    derivedTypes(@NotNull Function<T, Class<?>[]> reader, @NotNull Class<?>... expectedTypes)
    Checks if all types supplied by the given type reader match the given types.
    exactType(@NotNull Function<T,Class<?>> typeReader, @NotNull Class<?> expectedType)
    Checks if the supplied type from the reader function is exactly the given expected type.
    exactTypeAt(@NotNull Function<T, Class<?>[]> typesReader, @NotNull Class<?> expectedType, int idx)
    Checks if the type array extracted from the target member has the given type at the given index.
    exactTypes(@NotNull Function<T, Class<?>[]> typesReader, @NotNull Class<?>... expectedTypes)
    Checks if all types supplied by the given type reader match the given types.
    hasMatchingName(@NotNull String name, int... flags)
    Checks if the member has a name which matches the given regexp.
    hasModifier(int mod)
    Checks if the member has the given modifier.
    hasModifiers(int... mods)
    Checks if the member has all the given modifiers.
    hasName(@NotNull String name)
    Checks if the member has the exact name which was supplied.
    Negates the current matching predicate.
    or(@NotNull Predicate<? super T> other)
    Composes the current matching predicate with the supplied one using an OR operation.
    superType(@NotNull Function<T,Class<?>> typeReader, @NotNull Class<?> expectedType)
    Checks if the supplied type from the reader function is an instance of the expected type (expected instanceof input).
    superTypeAt(@NotNull Function<T, Class<?>[]> typesReader, @NotNull Class<?> expectedType, int idx)
    Checks if the type array extracted from the target member has the given type at the given index (expected instanceof input).
    superTypes(@NotNull Function<T, Class<?>[]> typesReader, @NotNull Class<?>... expectedTypes)
    Checks if all types supplied by the given type reader match the given types.
    boolean
    test(T t)

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • BaseMatcher

      public BaseMatcher()
  • Method Details

    • hasName

      @NotNull public M hasName(@NotNull @NotNull String name)
      Checks if the member has the exact name which was supplied.
      Parameters:
      name - the name the member must have.
      Returns:
      the same instance as used to call the method, for chaining.
      Throws:
      NullPointerException - if the given name is null.
    • hasMatchingName

      @NotNull public M hasMatchingName(@NotNull @Language("RegExp") @NotNull String name, @MagicConstant(flagsFromClass=Pattern.class) int... flags)
      Checks if the member has a name which matches the given regexp.
      Parameters:
      name - the regexp for the member name.
      flags - the match flags to supply to the pattern.
      Returns:
      the same instance as used to call the method, for chaining.
      Throws:
      NullPointerException - if the given name is null.
      IllegalArgumentException - if illegal match flags were supplied.
      PatternSyntaxException - if the given regexp is invalid.
    • hasModifier

      @NotNull public M hasModifier(int mod)
      Checks if the member has the given modifier.
      Parameters:
      mod - the modifier which the member should have.
      Returns:
      the same instance as used to call the method, for chaining.
    • hasModifiers

      @NotNull public M hasModifiers(int... mods)
      Checks if the member has all the given modifiers.
      Parameters:
      mods - the modifiers which the member should have.
      Returns:
      the same instance as used to call the method, for chaining.
    • denyModifier

      @NotNull public M denyModifier(int mod)
      Checks if the given member doesn't have the given modifier.
      Parameters:
      mod - the modifier which the given member shouldn't have.
      Returns:
      the same instance as used to call the method, for chaining.
    • denyModifiers

      @NotNull public M denyModifiers(int... mods)
      Checks if the given member doesn't have all the given modifiers.
      Parameters:
      mods - the modifiers which the member shouldn't have.
      Returns:
      the same instance as used to call the method, for chaining.
    • exactType

      @NotNull public M exactType(@NotNull @NotNull Function<T,Class<?>> typeReader, @NotNull @NotNull Class<?> expectedType)
      Checks if the supplied type from the reader function is exactly the given expected type.
      Parameters:
      typeReader - the type extractor from the target member.
      expectedType - the type which is expected.
      Returns:
      the same instance as used to call the method, for chaining.
      Throws:
      NullPointerException - if the given reader function or expected type is null.
    • superType

      @NotNull public M superType(@NotNull @NotNull Function<T,Class<?>> typeReader, @NotNull @NotNull Class<?> expectedType)
      Checks if the supplied type from the reader function is an instance of the expected type (expected instanceof input).
      Parameters:
      typeReader - the type extractor from the target member.
      expectedType - the type which is being matched.
      Returns:
      the same instance as used to call the method, for chaining.
      Throws:
      NullPointerException - if the given reader function or expected type is null.
    • derivedType

      @NotNull public M derivedType(@NotNull @NotNull Function<T,Class<?>> typeReader, @NotNull @NotNull Class<?> expectedType)
      Checks if the supplied type from the reader function is a derived instance of the given type (input instanceof expected).
      Parameters:
      typeReader - the type extractor from the target member.
      expectedType - the type which is being matched.
      Returns:
      the same instance as used to call the method, for chaining.
      Throws:
      NullPointerException - if the given type extractor or expected type is null.
    • exactTypes

      @NotNull public M exactTypes(@NotNull @NotNull Function<T, Class<?>[]> typesReader, @NotNull @NotNull Class<?>... expectedTypes)
      Checks if all types supplied by the given type reader match the given types.
      Parameters:
      typesReader - the extractor of the types from the target member.
      expectedTypes - the types which are expected.
      Returns:
      the same instance as used to call the method, for chaining.
      Throws:
      NullPointerException - if the given extractor or expected type array is null.
    • superTypes

      @NotNull public M superTypes(@NotNull @NotNull Function<T, Class<?>[]> typesReader, @NotNull @NotNull Class<?>... expectedTypes)
      Checks if all types supplied by the given type reader match the given types. (expected instanceof input).
      Parameters:
      typesReader - the extractor of the types from the target member.
      expectedTypes - the types which are expected.
      Returns:
      the same instance as used to call the method, for chaining.
      Throws:
      NullPointerException - if the given extractor or expected type array is null.
    • derivedTypes

      @NotNull public M derivedTypes(@NotNull @NotNull Function<T, Class<?>[]> reader, @NotNull @NotNull Class<?>... expectedTypes)
      Checks if all types supplied by the given type reader match the given types. (input instanceof expected).
      Parameters:
      reader - the extractor of the types from the target member.
      expectedTypes - the types which are expected.
      Returns:
      the same instance as used to call the method, for chaining.
      Throws:
      NullPointerException - if the given extractor or expected type array is null.
    • exactTypeAt

      @NotNull public M exactTypeAt(@NotNull @NotNull Function<T, Class<?>[]> typesReader, @NotNull @NotNull Class<?> expectedType, int idx)
      Checks if the type array extracted from the target member has the given type at the given index. This matcher will also not match if the given index either underflow the array length (< 0) or overflows the array length.
      Parameters:
      typesReader - the extractor of the types from the target member.
      expectedType - the type which is expected at the given position.
      idx - the position to check the type of.
      Returns:
      the same instance as used to call the method, for chaining.
      Throws:
      NullPointerException - if the given type reader or expected type is null.
    • superTypeAt

      @NotNull public M superTypeAt(@NotNull @NotNull Function<T, Class<?>[]> typesReader, @NotNull @NotNull Class<?> expectedType, int idx)
      Checks if the type array extracted from the target member has the given type at the given index (expected instanceof input). This matcher will also not match if the given index either underflow the array length (< 0) or overflows the array length.
      Parameters:
      typesReader - the extractor of the types from the target member.
      expectedType - the type which is expected at the given position.
      idx - the position to check the type of.
      Returns:
      the same instance as used to call the method, for chaining.
      Throws:
      NullPointerException - if the given type reader or expected type is null.
    • derivedTypeAt

      @NotNull public M derivedTypeAt(@NotNull @NotNull Function<T, Class<?>[]> reader, @NotNull @NotNull Class<?> expectedType, int idx)
      Checks if the type array extracted from the target member has the given type at the given index (input instanceof expected). This matcher will also not match if the given index either underflow the array length (< 0) or overflows the array length.
      Parameters:
      reader - the extractor of the types from the target member.
      expectedType - the type which is expected at the given position.
      idx - the position to check the type of.
      Returns:
      the same instance as used to call the method, for chaining.
      Throws:
      NullPointerException - if the given type reader or expected type is null.
    • test

      public boolean test(T t)
      Specified by:
      test in interface Predicate<T extends Member>
    • and

      @NotNull public M and(@NotNull @NotNull Predicate<? super T> other)
      Composes the current matching predicate with the supplied one using an AND operation. Note: other than the super method this method mutates this object rather than returning a new matcher object.
      Specified by:
      and in interface Predicate<T extends Member>
      Parameters:
      other - the other predicate which must match.
      Returns:
      the same instance as used to call the method, for chaining.
      Throws:
      NullPointerException - if the other predicate is null.
    • or

      @NotNull public M or(@NotNull @NotNull Predicate<? super T> other)
      Composes the current matching predicate with the supplied one using an OR operation. Note: other than the super method this method mutates this object rather than returning a new matcher object.
      Specified by:
      or in interface Predicate<T extends Member>
      Parameters:
      other - the other predicate which must match.
      Returns:
      the same instance as used to call the method, for chaining.
      Throws:
      NullPointerException - if the other predicate is null.
    • negate

      @NotNull public M negate()
      Negates the current matching predicate. Note: other than the super method this method mutates this object rather than returning a new matcher object.
      Specified by:
      negate in interface Predicate<T extends Member>
      Returns:
      the same instance as used to call the method, for chaining.