Class SwitchStatement

  • All Implemented Interfaces:
    Comparable<AstNode>, Iterable<Node>

    public class SwitchStatement
    extends Jump
    Switch statement AST node type. Node type is Token.SWITCH.

    SwitchStatement :
            switch ( Expression ) CaseBlock
     CaseBlock :
            { [CaseClauses] }
            { [CaseClauses] DefaultClause [CaseClauses] }
     CaseClauses :
            CaseClause
            CaseClauses CaseClause
     CaseClause :
            case Expression : [StatementList]
     DefaultClause :
            default : [StatementList]
    • Constructor Detail

      • SwitchStatement

        public SwitchStatement()
      • SwitchStatement

        public SwitchStatement​(int pos)
      • SwitchStatement

        public SwitchStatement​(int pos,
                               int len)
    • Method Detail

      • getExpression

        public AstNode getExpression()
        Returns the switch discriminant expression
      • setExpression

        public void setExpression​(AstNode expression)
        Sets the switch discriminant expression, and sets its parent to this node.
        Throws:
        IllegalArgumentException - } if expression is null
      • getCases

        public List<SwitchCase> getCases()
        Returns case statement list. If there are no cases, returns an immutable empty list.
      • setCases

        public void setCases​(List<SwitchCase> cases)
        Sets case statement list, and sets the parent of each child case to this node.
        Parameters:
        cases - list, which may be null to remove all the cases
      • addCase

        public void addCase​(SwitchCase switchCase)
        Adds a switch case statement to the end of the list.
        Throws:
        IllegalArgumentException - } if switchCase is null
      • getLp

        public int getLp()
        Returns left paren position, -1 if missing
      • setLp

        public void setLp​(int lp)
        Sets left paren position
      • getRp

        public int getRp()
        Returns right paren position, -1 if missing
      • setRp

        public void setRp​(int rp)
        Sets right paren position
      • setParens

        public void setParens​(int lp,
                              int rp)
        Sets both paren positions
      • toSource

        public String toSource​(int depth)
        Description copied from class: AstNode
        Emits source code for this node. Callee is responsible for calling this function recursively on children, incrementing indent as appropriate.

        Note: if the parser was in error-recovery mode, some AST nodes may have null children that are expected to be non-null when no errors are present. In this situation, the behavior of the toSource method is undefined: toSource implementations may assume that the AST node is error-free, since it is intended to be invoked only at runtime after a successful parse.

        Overrides:
        toSource in class Jump
        Parameters:
        depth - the current recursion depth, typically beginning at 0 when called on the root node.
      • visit

        public void visit​(NodeVisitor v)
        Visits this node, then the switch-expression, then the cases in lexical order.
        Overrides:
        visit in class Jump
        Parameters:
        v - the object to call with this node and its children