Class SwitchNode

java.lang.Object
spoon.pattern.internal.node.AbstractNode
spoon.pattern.internal.node.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
      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
    • addCase

      public void addCase(PrimitiveMatcher vrOfExpression, RootNode statement)
      Adds another case into this switch statement
      Parameters:
      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
      Parameters:
      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
      Parameters:
      consumer - the receiver of pairs of ParameterInfo and RootNode
    • matchTargets

      public TobeMatched matchTargets(TobeMatched targets, Matchers nextMatchers)
      Specified by:
      matchTargets in interface RootNode
      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
    • 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