Class TreeNode

    • Constructor Detail

      • TreeNode

        public TreeNode()
    • Method Detail

      • getParent

        public TreeNode getParent()
        Returns the parent of this node.
        Returns:
        the parent node, or null if this is the root node
      • getChild

        public TreeNode getChild​(int index)
        Returns the child at given index. Note: The average time complexity of this method is O(n).
        Parameters:
        index - the index, starting at 0
        Returns:
        the child node
      • getChildren

        public java.util.List<TreeNode> getChildren()
        Returns all children of this node. A copy of the collection is returned to allow children removal and insertion during the iteration.
        Returns:
        the iterable collection of all children
      • childCount

        public int childCount()
        Returns the number of all direct children of this node.
        Returns:
        the child count
      • addChild

        public TreeNode addChild​(TreeNode child)
        Adds a child to this node, placing it on the end.
        Parameters:
        child - the child node
        Returns:
        this
      • addChildren

        public TreeNode addChildren​(TreeNode... children)
        Adds multiple children to this node, placing them on the end.
        Parameters:
        children - the child nodes
        Returns:
        this
      • addChildren

        public TreeNode addChildren​(java.util.List<TreeNode> children)
      • shallowCopy

        public abstract TreeNode shallowCopy()
      • remove

        public void remove()
        Removes this node from the tree. This can be described as "tearing off" the node. The link between this node and the parent one is removed bilaterally.
      • accept

        public void accept​(Visitor visitor)
                    throws SemanticException
        Calls the appropriate visitor method. Subclasses should override this method in order to support the visitor design pattern properly.
        Parameters:
        visitor - the visitor object
        Throws:
        SemanticException - depends on situation
      • getLine

        public java.lang.Integer getLine()
        Returns the starting line number in the source file from which this node was generated.
        Returns:
        the line number; null if no line was associated with this node
      • setLine

        public void setLine​(java.lang.Integer line)
        Sets the starting source line number of this node. It is the starting position of one of the tokens from which this tree node was generated (usually the first one).
        Parameters:
        line - the line number
      • dump

        public void dump​(java.io.PrintStream outStream)
        Prints the whole tree recursively.
        Parameters:
        outStream - the stream to write to
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object