Class WhileStmt

    • Constructor Detail

      • WhileStmt

        public WhileStmt​(Expression condition,
                         Statement body,
                         String label,
                         SourceLocation location)
        Creates a while loop, adopting the condition and body as children.
        Parameters:
        condition - the loop condition
        body - the loop body
        label - the loop label, or null
        location - the source location, or null for unknown
        Throws:
        NullPointerException - if the condition or body is null
      • WhileStmt

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

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

      • getCondition

        public Expression getCondition()
        Returns:
        the condition
      • setCondition

        public void setCondition​(Expression condition)
        Replaces the loop condition, reparenting it and releasing the previous one.
        Parameters:
        condition - the new condition
      • getBody

        public Statement getBody()
        Returns:
        the body
      • setBody

        public void setBody​(Statement body)
        Replaces the loop body, reparenting it and releasing the previous one.
        Parameters:
        body - the new body
      • setLabel

        public void setLabel​(String label)
        Sets the label targeted by labeled break and continue.
        Parameters:
        label - the new label, or null to drop it
      • 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 node this statement hangs from.
        Specified by:
        setParent in interface ASTNode
        Parameters:
        parent - the enclosing 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
      • withCondition

        public WhileStmt withCondition​(Expression condition)
        Replaces the loop condition in place, reparenting it and releasing the previous one.
        Parameters:
        condition - the new condition, may be null
        Returns:
        this statement
      • withBody

        public WhileStmt withBody​(Statement body)
        Replaces the loop body in place, reparenting it and releasing the previous one.
        Parameters:
        body - the new body, may be null
        Returns:
        this statement
      • withLabel

        public WhileStmt withLabel​(String label)
        Sets the label in place.
        Parameters:
        label - the new label, or null to drop it
        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