Interface RootNode

All Superinterfaces:
Matchers
All Known Subinterfaces:
InlineNode, PrimitiveMatcher, RepeatableMatcher
All Known Implementing Classes:
AbstractNode, ConstantNode, ElementNode, ForEachNode, ListOfNodes, MapEntryNode, ParameterNode, StringNode, SwitchNode

public interface RootNode extends Matchers
Represents a parameterized Pattern ValueResolver, which can be used
  • to generate a zero, one or more copies of model using provided parameters
  • to match zero, one or more instances of model and deliver a matching parameters
  • Field Details

    • MATCH_ALL

      static final Matchers MATCH_ALL
      The special implementation of Matchers, which is used as last RootNode in case when ALL target nodes must match with all template nodes
    • MATCH_PART

      static final Matchers MATCH_PART
      The special implementation of Matchers, which is used as last RootNode in case when SOME target nodes must match with all template nodes
  • Method Details

    • forEachParameterInfo

      void forEachParameterInfo(BiConsumer<ParameterInfo,​RootNode> consumer)
      Calls consumer for each pair of parameter definition (ParameterInfo) and RootNode, which uses it
      Parameters:
      consumer - the receiver of pairs of ParameterInfo and RootNode
    • generateTargets

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

      boolean isSimplifyGenerated()
      Returns:
      true if generated result has to be evaluated to apply simplifications. e.g. ("a" + "b") id simplified to "ab"
    • setSimplifyGenerated

      void setSimplifyGenerated(boolean simplifyGenerated)
      Parameters:
      simplifyGenerated - true if generated result of this RootNode has to be evaluated to apply simplifications.
    • matchTargets

      TobeMatched matchTargets(TobeMatched targets, Matchers nextMatchers)
      Parameters:
      targets - to be matched target nodes and input parameters
      nextMatchers - Chain of matchers which has to be processed after this RootNode
      Returns:
      new parameters and container with remaining targets
    • matchAllWith

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

      boolean replaceNode(RootNode oldNode, RootNode newNode)
      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?
      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