Class SwitchStmt

  • All Implemented Interfaces:
    ASTNode, Statement

    public final class SwitchStmt
    extends Object
    implements Statement
    A switch statement over a selector expression and a list of cases.
    • Constructor Detail

      • SwitchStmt

        public SwitchStmt​(Expression selector,
                          List<SwitchCase> cases,
                          SourceLocation location)
        Creates a switch statement and parents the selector to it.
        Parameters:
        selector - the switched-on expression
        cases - initial cases, or null for none
        location - source location, or null for unknown
        Throws:
        NullPointerException - if selector is null
      • SwitchStmt

        public SwitchStmt​(Expression selector,
                          List<SwitchCase> cases)
        Creates a switch statement with an unknown location.
        Parameters:
        selector - the switched-on expression
        cases - initial cases, or null for none
        Throws:
        NullPointerException - if selector is null
      • SwitchStmt

        public SwitchStmt​(Expression selector)
        Creates a switch statement with no cases.
        Parameters:
        selector - the switched-on expression
        Throws:
        NullPointerException - if selector is null
    • Method Detail

      • getSelector

        public Expression getSelector()
        Returns:
        the selector
      • setSelector

        public void setSelector​(Expression selector)
        Replaces the selector expression, reparenting old and new nodes.
        Parameters:
        selector - the new selector
      • getLocation

        public SourceLocation getLocation()
        Description copied from interface: ASTNode
        Gets the source location of this node.
        Specified by:
        getLocation in interface ASTNode
        Returns:
        the location
      • getParent

        public ASTNode getParent()
        Description copied from interface: ASTNode
        Gets the parent node in the AST tree.
        Specified by:
        getParent in interface ASTNode
        Returns:
        the parent
      • setParent

        public void setParent​(ASTNode parent)
        Sets the enclosing AST node.
        Specified by:
        setParent in interface ASTNode
        Parameters:
        parent - the new parent node
      • addCase

        public void addCase​(SwitchCase switchCase)
        Appends a case to this switch.
        Parameters:
        switchCase - the case to append
      • getDefaultCase

        public SwitchCase getDefaultCase()
        Returns:
        the default case, or null if there is none
      • hasDefault

        public boolean hasDefault()
        Returns:
        true if this switch has a default case
      • getCaseCount

        public int getCaseCount()
        Returns:
        the number of cases
      • withSelector

        public SwitchStmt withSelector​(Expression selector)
        Replaces the selector expression, reparenting old and new nodes.
        Parameters:
        selector - the new selector
        Returns:
        this statement
      • getChildren

        public List<ASTNode> getChildren()
        Description copied from interface: ASTNode
        Lists the direct children a node holds, in source order.
        Specified by:
        getChildren in interface ASTNode
        Returns:
        the direct children, empty for a leaf
      • accept

        public <T> T accept​(SourceVisitor<T> visitor)
        Description copied from interface: ASTNode
        Accepts a visitor for this node.
        Specified by:
        accept in interface ASTNode
        Type Parameters:
        T - the return type of the visitor
        Parameters:
        visitor - the visitor to accept
        Returns:
        the result from the visitor