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 Detail

      • SwitchNode

        public SwitchNode()
    • Method Detail

      • 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
      • 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