Class DynamicMatcher<C>

java.lang.Object
eu.bandm.tools.util.DynamicMatcher<C>

public abstract class DynamicMatcher<C> extends Object
An abstract base class for reflection-based type case distinctions. Subclasses should specify a method name and overload it with methods B rewrite(A x) to match objects of class A, and return objects of class B. Methods of subclasses will only be considered as matches for an input if they have
  • Field Details

    • phaseNames

      protected final String[] phaseNames
  • Constructor Details

    • DynamicMatcher

      protected DynamicMatcher(String[] phaseNames)
  • Method Details

    • getMatchFor

      protected Method getMatchFor(int phase, Class sourceClass)
    • match

      public <R> R match(int phase, Class<R> targetClass, C x, boolean total)
      Finds the best-matching rewrite method for the dynamic type of a given object and invokes it.
      Parameters:
      targetClass - the expected class of the result.
      x - the input object.
      Throws:
      IllegalArgumentException - if the matching method throws an exception or cannot be invoked for some reason, or if no match is found.
      ClassCastException - if the result cannot be cast to the class targetClass.
      NullPointerException - if x is null.