Class SwitchNode

All Implemented Interfaces:
Matchers, InlineNode, RootNode

public class SwitchNode extends AbstractNode implements InlineNode
List of conditional cases {code} if (a) { ... someStatements if a == true.. } else if (b) { ... someStatements if b == true.. } else { ... someStatements in other cases ... }
  • Constructor Details

    • SwitchNode

      public SwitchNode()
  • 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
      oldNode - old RootNode
      newNode - new RootNode
      a true if `oldNode` was found in this RootNode or it's children and replaced by `newNode` false if `oldNode` was not found
    • addCase

      public void addCase(PrimitiveMatcher vrOfExpression, RootNode statement)
      Adds another case into this switch statement
      vrOfExpression - if value of this parameter is true then statement has to be used. If vrOfExpression is null, then statement is always used
      statement - optional statement
    • 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
      generator - Generator which drives generation process
      result - holder for the generated objects
      parameters - a ImmutableMap holding 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
      consumer - the receiver of pairs of ParameterInfo and RootNode
    • matchTargets

      public TobeMatched matchTargets(TobeMatched targets, Matchers nextMatchers)
      Specified by:
      matchTargets in interface RootNode
      targets - to be matched target nodes and input parameters
      nextMatchers - Chain of matchers which has to be processed after this RootNode
      new parameters and container with remaining targets
    • 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
      generator - a to be used Generator
      result - holder of the result
      parameters - a ImmutableMap with current parameters