Class SwitchStatement

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

public class SwitchStatement extends Scope
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 Details

    • SwitchStatement

      public SwitchStatement()
    • SwitchStatement

      public SwitchStatement(int pos)
  • Method Details

    • 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: Jump
      Jumps are only used directly during code generation, and do not support this interface.
      Overrides:
      toSource in class Scope
      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 Scope
      Parameters:
      v - the object to call with this node and its children