org.antlr.runtime.tree
Class BaseTree

java.lang.Object
  extended by org.antlr.runtime.tree.BaseTree
All Implemented Interfaces:
Tree
Direct Known Subclasses:
CommonTree, DoubleLinkTree, ParseTree

public abstract class BaseTree
extends java.lang.Object
implements Tree

A generic tree implementation with no payload. You must subclass to actually have any user data. ANTLR v3 uses a list of children approach instead of the child-sibling approach in v2. A flat tree (a list) is an empty node whose children represent the list. An empty, but non-null node is called "nil".


Field Summary
protected  java.util.List children
           
 
Fields inherited from interface org.antlr.runtime.tree.Tree
INVALID_NODE
 
Constructor Summary
BaseTree()
           
BaseTree(Tree node)
          Create a new node from an existing node does nothing for BaseTree as there are no fields other than the children list, which cannot be copied as the children are not considered part of this node.
 
Method Summary
 void addChild(Tree t)
          Add t as child of this node.
 void addChildren(java.util.List kids)
          Add all elements of kids list as children of this node
protected  java.util.List createChildrenList()
          Override in a subclass to change the impl of children list
 BaseTree deleteChild(int i)
           
 Tree dupTree()
          Recursively walk this tree, dup'ing nodes until you have copy of this tree.
 int getCharPositionInLine()
           
 Tree getChild(int i)
           
 int getChildCount()
           
 Tree getFirstChildWithType(int type)
           
 int getLine()
          In case we don't have a token payload, what is the line for errors?
 boolean isNil()
          Indicates the node is a nil node but may still have children, meaning the tree is a flat list.
 void setChild(int i, BaseTree t)
           
abstract  java.lang.String toString()
          Override to say how a node (not a tree) should look as text
 java.lang.String toStringTree()
          Print out a whole tree not just a node
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.antlr.runtime.tree.Tree
dupNode, getText, getTokenStartIndex, getTokenStopIndex, getType, setTokenStartIndex, setTokenStopIndex
 

Field Detail

children

protected java.util.List children
Constructor Detail

BaseTree

public BaseTree()

BaseTree

public BaseTree(Tree node)
Create a new node from an existing node does nothing for BaseTree as there are no fields other than the children list, which cannot be copied as the children are not considered part of this node.

Method Detail

getChild

public Tree getChild(int i)
Specified by:
getChild in interface Tree

getFirstChildWithType

public Tree getFirstChildWithType(int type)

getChildCount

public int getChildCount()
Specified by:
getChildCount in interface Tree

addChild

public void addChild(Tree t)
Add t as child of this node. Warning: if t has no children, but child does and child isNil then this routine moves children to t via t.children = child.children; i.e., without copying the array.

Specified by:
addChild in interface Tree

addChildren

public void addChildren(java.util.List kids)
Add all elements of kids list as children of this node


setChild

public void setChild(int i,
                     BaseTree t)

deleteChild

public BaseTree deleteChild(int i)

createChildrenList

protected java.util.List createChildrenList()
Override in a subclass to change the impl of children list


isNil

public boolean isNil()
Description copied from interface: Tree
Indicates the node is a nil node but may still have children, meaning the tree is a flat list.

Specified by:
isNil in interface Tree

dupTree

public Tree dupTree()
Recursively walk this tree, dup'ing nodes until you have copy of this tree. This method should work for all subclasses as long as they override dupNode().

Specified by:
dupTree in interface Tree

toStringTree

public java.lang.String toStringTree()
Print out a whole tree not just a node

Specified by:
toStringTree in interface Tree

getLine

public int getLine()
Description copied from interface: Tree
In case we don't have a token payload, what is the line for errors?

Specified by:
getLine in interface Tree

getCharPositionInLine

public int getCharPositionInLine()
Specified by:
getCharPositionInLine in interface Tree

toString

public abstract java.lang.String toString()
Override to say how a node (not a tree) should look as text

Specified by:
toString in interface Tree
Overrides:
toString in class java.lang.Object