Class DoWhileStmt

  • All Implemented Interfaces:
    ASTNode, Statement

    public final class DoWhileStmt
    extends Object
    implements Statement
    A do-while loop with an optional label; the body executes before the condition is tested.
    • Constructor Detail

      • DoWhileStmt

        public DoWhileStmt​(Statement body,
                           Expression condition,
                           String label,
                           SourceLocation location)
        Creates a do-while loop and parents the body and condition to it.
        Parameters:
        body - the loop body
        condition - the loop condition
        label - loop label, or null for none
        location - source location, or null for unknown
        Throws:
        NullPointerException - if body or condition is null
      • DoWhileStmt

        public DoWhileStmt​(Statement body,
                           Expression condition,
                           String label)
        Creates a do-while loop with an unknown location.
        Parameters:
        body - the loop body
        condition - the loop condition
        label - loop label, or null for none
        Throws:
        NullPointerException - if body or condition is null
      • DoWhileStmt

        public DoWhileStmt​(Statement body,
                           Expression condition)
        Creates an unlabeled do-while loop with an unknown location.
        Parameters:
        body - the loop body
        condition - the loop condition
        Throws:
        NullPointerException - if body or condition is null
    • Method Detail

      • getBody

        public Statement getBody()
        Returns:
        the body
      • setBody

        public void setBody​(Statement body)
        Replaces the loop body, reparenting old and new nodes.
        Parameters:
        body - the new body
      • getCondition

        public Expression getCondition()
        Returns:
        the condition
      • setCondition

        public void setCondition​(Expression condition)
        Replaces the loop condition, reparenting old and new nodes.
        Parameters:
        condition - the new condition
      • setLabel

        public void setLabel​(String label)
        Sets the loop label.
        Parameters:
        label - the new label, or null for none
      • 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
      • getLabel

        public String getLabel()
        Description copied from interface: Statement
        Gets the label for this statement, if any.
        Specified by:
        getLabel in interface Statement
        Returns:
        the label, or null if not labeled
      • withBody

        public DoWhileStmt withBody​(Statement body)
        Replaces the loop body, reparenting old and new nodes.
        Parameters:
        body - the new body
        Returns:
        this statement
      • withCondition

        public DoWhileStmt withCondition​(Expression condition)
        Replaces the loop condition, reparenting old and new nodes.
        Parameters:
        condition - the new condition
        Returns:
        this statement
      • withLabel

        public DoWhileStmt withLabel​(String label)
        Sets the loop label.
        Parameters:
        label - the new label, or null for none
        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