Class BlockStmt

  • All Implemented Interfaces:
    ASTNode, Statement

    public final class BlockStmt
    extends Object
    implements Statement
    A brace-delimited sequence of statements.
    • Constructor Detail

      • BlockStmt

        public BlockStmt​(List<Statement> statements,
                         SourceLocation location)
        Creates a block containing the given statements, skipping null entries.
        Parameters:
        statements - initial statements, or null for none
        location - source location, or null for unknown
      • BlockStmt

        public BlockStmt​(List<Statement> statements)
        Creates a block containing the given statements with an unknown location.
        Parameters:
        statements - initial statements, or null for none
      • BlockStmt

        public BlockStmt()
        Creates an empty block.
    • Method Detail

      • 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
      • addStatement

        public void addStatement​(Statement stmt)
        Appends a statement to this block, ignoring null.
        Parameters:
        stmt - the statement to append
      • insertStatement

        public void insertStatement​(int index,
                                    Statement stmt)
        Inserts a statement at the given index, ignoring null.
        Parameters:
        index - position at which to insert
        stmt - the statement to insert
      • removeStatement

        public boolean removeStatement​(Statement stmt)
        Removes a statement from this block.
        Parameters:
        stmt - the statement to remove
        Returns:
        true if the statement was present
      • isEmpty

        public boolean isEmpty()
        Returns:
        true if this block has no statements
      • size

        public int size()
        Returns:
        the number of statements in this block
      • 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