Class LabeledStmt

  • All Implemented Interfaces:
    ASTNode, Statement

    public final class LabeledStmt
    extends Object
    implements Statement
    A statement prefixed with a label, the target of labeled breaks and continues.
    • Constructor Detail

      • LabeledStmt

        public LabeledStmt​(String label,
                           Statement statement,
                           SourceLocation location)
        Creates a labeled statement and parents the wrapped statement to it.
        Parameters:
        label - the label name
        statement - the labeled statement
        location - source location, or null for unknown
        Throws:
        NullPointerException - if label or statement is null
      • LabeledStmt

        public LabeledStmt​(String label,
                           Statement statement)
        Creates a labeled statement with an unknown location.
        Parameters:
        label - the label name
        statement - the labeled statement
        Throws:
        NullPointerException - if label or statement is null
    • Method Detail

      • getStatement

        public Statement getStatement()
        Returns:
        the statement
      • setStatement

        public void setStatement​(Statement statement)
        Replaces the labeled statement, reparenting old and new nodes.
        Parameters:
        statement - the new statement
      • 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
      • withStatement

        public LabeledStmt withStatement​(Statement statement)
        Replaces the labeled statement, reparenting old and new nodes.
        Parameters:
        statement - the new statement
        Returns:
        this statement
        Throws:
        NullPointerException - if statement is null
      • 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
      • 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