Class ForEachNode

java.lang.Object
spoon.pattern.internal.node.AbstractNode
spoon.pattern.internal.node.ForEachNode
All Implemented Interfaces:
Matchers, InlineNode, RepeatableMatcher, RootNode

public class ForEachNode extends AbstractNode implements InlineNode
Pattern node of multiple occurrences of the same model, just with different parameters. Example with three occurrences of model `System.out.println(_x_)`, with parameter `_x_`

 System.out.println("a")
 System.out.println("b")
 System.out.println(getStringOf(p1, p2))
 
where parameter values are _x_ = ["a", "b", getStringOf(p1, p2)]
  • Constructor Details

    • ForEachNode

      public ForEachNode()
  • Method Details

    • replaceNode

      public boolean replaceNode(RootNode oldNode, RootNode newNode)
      Description copied from interface: RootNode
      Call it to modify Pattern structure. It is actually called mainly by PatternBuilder. TODO: May be we can move this method into some internal interface?
      Specified by:
      replaceNode in interface RootNode
      Parameters:
      oldNode - old RootNode
      newNode - new RootNode
      Returns:
      a true if `oldNode` was found in this RootNode or it's children and replaced by `newNode` false if `oldNode` was not found
    • generateTargets

      public <T> void generateTargets(DefaultGenerator generator, ResultHolder<T> result, ImmutableMap parameters)
      Description copied from interface: RootNode
      Generates zero, one or more target depending on kind of this RootNode, expected `result` and input `parameters`
      Specified by:
      generateTargets in interface RootNode
      Parameters:
      generator - Generator which drives generation process
      result - holder for the generated objects
      parameters - a ImmutableMap holding parameters
    • getMatchingStrategy

      public Quantifier getMatchingStrategy()
      Description copied from interface: RepeatableMatcher
      If two RepeatableMatchers in a list are matching the same element, then returned Quantifier defines how resolve this conflict
      Specified by:
      getMatchingStrategy in interface RepeatableMatcher
      Returns:
      Quantifier
    • matchAllWith

      public TobeMatched matchAllWith(TobeMatched tobeMatched)
      Description copied from interface: Matchers
      Matches all matchers of this Matchers instance with `targets`
      Specified by:
      matchAllWith in interface Matchers
      Specified by:
      matchAllWith in interface RootNode
      Parameters:
      tobeMatched - to be matched target nodes and input parameters
      Returns:
      TobeMatched with targets which remained after all RootNodes were matched + matched parameters
    • forEachParameterInfo

      public void forEachParameterInfo(BiConsumer<ParameterInfo,​RootNode> consumer)
      Description copied from interface: RootNode
      Calls consumer for each pair of parameter definition (ParameterInfo) and RootNode, which uses it
      Specified by:
      forEachParameterInfo in interface RootNode
      Parameters:
      consumer - the receiver of pairs of ParameterInfo and RootNode
    • setNestedModel

      public void setNestedModel(RootNode valueResolver)
    • setIterableParameter

      public void setIterableParameter(PrimitiveMatcher substRequestOfIterable)
    • setLocalParameter

      public void setLocalParameter(ParameterInfo parameterInfo)
    • isRepeatable

      public boolean isRepeatable()
      Specified by:
      isRepeatable in interface RepeatableMatcher
      Returns:
      true if this matcher can be applied more then once in the same container of targets Note: even if false, it may be applied again to another container and to match EQUAL value
    • isMandatory

      public boolean isMandatory(ImmutableMap parameters)
      Specified by:
      isMandatory in interface RepeatableMatcher
      Parameters:
      parameters - matching parameters
      Returns:
      true if this ValueResolver MUST match with next target in the state defined by current `parameters`. false if match is optional
    • isTryNextMatch

      public boolean isTryNextMatch(ImmutableMap parameters)
      Specified by:
      isTryNextMatch in interface RepeatableMatcher
      Parameters:
      parameters - matching parameters
      Returns:
      true if this ValueResolver should be processed again to match next target in the state defined by current `parameters`.
    • generateInlineTargets

      public <T> void generateInlineTargets(DefaultGenerator generator, ResultHolder<T> result, ImmutableMap parameters)
      Description copied from interface: InlineNode
      Generates inline statements of this inline RootNode. This method is used when sources of pattern have to be printed
      Specified by:
      generateInlineTargets in interface InlineNode
      Parameters:
      generator - a to be used Generator
      result - holder of the result
      parameters - a ImmutableMap with current parameters
    • matchTargets

      public TobeMatched matchTargets(TobeMatched targets, Matchers next)
      Specified by:
      matchTargets in interface RootNode
      Parameters:
      targets - to be matched target nodes and input parameters
      next - Chain of matchers which has to be processed after this RootNode
      Returns:
      new parameters and container with remaining targets