Class TobeMatched

java.lang.Object
spoon.pattern.internal.matcher.TobeMatched

public class TobeMatched extends Object
Describes what next has to be matched. It consists of current `parameters` represented by ImmutableMap and by a to be matched target elements. See children of TobeMatched for supported collections of target elements.
  • Method Details

    • create

      public static TobeMatched create(ImmutableMap parameters, ContainerKind containerKind, Object target)
      Parameters:
      parameters - to be matched parameters
      containerKind - the type of container in `target` value
      target - the to be matched target data. List, Set, Map or single value
      Returns:
      new instance of TobeMatched, which contains `parameters` and `target` mapped using containerKind
    • getParameters

      public ImmutableMap getParameters()
      Returns:
      parameters of last successful match.
    • getTargets

      public List<?> getTargets()
      Returns:
      List of to be matched targets, which A) have to be matched by current matching step B) remained after matching of all template nodes
    • getMatchedTargets

      public List<?> getMatchedTargets(TobeMatched tobeMatchedTargets)
      Parameters:
      tobeMatchedTargets - TobeMatched with targets, which didn't matched yet. These which has to be matched next.
      Returns:
      matched targets. It means these targets, which are not contained in `notMatchedTargets`
    • hasTargets

      public boolean hasTargets()
      Returns:
      true if there is anything to match.
    • copyAndSetParams

      public TobeMatched copyAndSetParams(ImmutableMap newParams)
      Makes a copy of this match context with the same targets, but with new `parameters`
      Parameters:
      newParams - to be used parameters
      Returns:
      copy of TobeMatched with new parameters
    • matchNext

      public @Nullable TobeMatched matchNext(BiFunction<Object,​ImmutableMap,​ImmutableMap> matcher)
      Calls matcher algorithm to match target item
      Parameters:
      matcher - a matching algorithm
      Returns:
      TobeMatched with List of remaining (to be matched) targets or null if there is no match
    • getMatchedParameters

      public static @Nullable ImmutableMap getMatchedParameters(TobeMatched remainingMatch)
      Parameters:
      remainingMatch - the TobeMatched whose parameters has to be returned
      Returns:
      parameters from `remainingMatch`, if it exists. Else returns null
    • removeTarget

      public TobeMatched removeTarget(int idxOfTobeRemovedTarget)
      Parameters:
      idxOfTobeRemovedTarget - index of to be removed target
      Returns:
      new TobeMatched without the target on the index `idxOfTobeRemovedTarget`
    • removeTarget

      public TobeMatched removeTarget(ImmutableMap parameters, int idxOfTobeRemovedTarget)
    • toString

      public String toString()
      Overrides:
      toString in class Object