Top Description Fields Constructors Methods
org.antlr.runtime.tree

public abstract Class BaseTree

extends Object
implements Tree
Class Inheritance
All Implemented Interfaces
org.antlr.runtime.tree.Tree
Known Direct Subclasses
org.antlr.runtime.tree.CommonTree, org.antlr.runtime.tree.ParseTree, org.antlr.runtime.debug.RemoteDebugEventSocketListener.ProxyTree
Imports
java.util.ArrayList, .List

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

Modifier and TypeField and Description
protected List<Object>

Constructor Summary

AccessConstructor and Description
public
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 Summary

Modifier and TypeMethod and Description
public void
addChild(Tree t)

Implements org.antlr.runtime.tree.Tree.addChild.

Add t as child of this node.
public void
addChildren(List<? extends Tree> kids)

Add all elements of kids list as children of this node

protected List<Object>
createChildrenList()

Override in a subclass to change the impl of children list

public Object
public void
freshenParentAndChildIndexes()

Implements org.antlr.runtime.tree.Tree.freshenParentAndChildIndexes.

Set the parent and child index values for all child of t
public void
public void
public void
public Tree
getAncestor(int ttype)

Implements org.antlr.runtime.tree.Tree.getAncestor.

Walk upwards and get first ancestor with this token type.
public List<? extends Tree>
getAncestors()

Implements org.antlr.runtime.tree.Tree.getAncestors.

Return a list of all ancestors of this node.
public int
public Tree
public int
public int
getChildIndex()

Implements org.antlr.runtime.tree.Tree.getChildIndex.

BaseTree doesn't track child indexes.
public List<? extends Object>
getChildren()

Get the children internal List; note that if you directly mess with the list, do so at your own risk.

public Tree
public int
getLine()

Implements org.antlr.runtime.tree.Tree.getLine.

In case we don't have a token payload, what is the line for errors?
public Tree
getParent()

Implements org.antlr.runtime.tree.Tree.getParent.

BaseTree doesn't track parent pointers.
public boolean
hasAncestor(int ttype)

Implements org.antlr.runtime.tree.Tree.hasAncestor.

Walk upwards looking for ancestor with this token type.
public void
insertChild(int i, Object t)

Insert child t at child position i (0..n-1) by shifting children i+1..n-1 to the right one position.

public boolean
isNil()

Implements org.antlr.runtime.tree.Tree.isNil.

Indicates the node is a nil node but may still have children, meaning the tree is a flat list.
public void
replaceChildren(int startChildIndex, int stopChildIndex, Object t)

Implements org.antlr.runtime.tree.Tree.replaceChildren.

Delete children from start to stop and replace with t even if t is a list (nil-root tree).
public void
public void
public void
setChild(int i, Tree t)

Implements org.antlr.runtime.tree.Tree.setChild.

Set ith child (0..n-1) to t; t must be non-null and non-nil node
public void
public void
public abstract String
toString()

Redeclares org.antlr.runtime.tree.Tree.toString.

Overrides java.lang.Object.toString.

Override to say how a node (not a tree) should look as text
public String
toStringTree()

Implements org.antlr.runtime.tree.Tree.toStringTree.

Print out a whole tree not just a node
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

childrenback to summary
protected List<Object> children

Constructor Detail

BaseTreeback to summary
public BaseTree()
BaseTreeback to summary
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

addChildback to summary
public void addChild(Tree t)

Implements org.antlr.runtime.tree.Tree.addChild.

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.

Annotations
@Override
addChildrenback to summary
public void addChildren(List<? extends Tree> kids)

Add all elements of kids list as children of this node

createChildrenListback to summary
protected List<Object> createChildrenList()

Override in a subclass to change the impl of children list

deleteChildback to summary
public Object deleteChild(int i)

Implements org.antlr.runtime.tree.Tree.deleteChild.

Annotations
@Override
freshenParentAndChildIndexesback to summary
public void freshenParentAndChildIndexes()

Implements org.antlr.runtime.tree.Tree.freshenParentAndChildIndexes.

Set the parent and child index values for all child of t

Annotations
@Override
freshenParentAndChildIndexesback to summary
public void freshenParentAndChildIndexes(int offset)
freshenParentAndChildIndexesDeeplyback to summary
public void freshenParentAndChildIndexesDeeply()
freshenParentAndChildIndexesDeeplyback to summary
public void freshenParentAndChildIndexesDeeply(int offset)
getAncestorback to summary
public Tree getAncestor(int ttype)

Implements org.antlr.runtime.tree.Tree.getAncestor.

Walk upwards and get first ancestor with this token type.

Annotations
@Override
getAncestorsback to summary
public List<? extends Tree> getAncestors()

Implements org.antlr.runtime.tree.Tree.getAncestors.

Return a list of all ancestors of this node. The first node of list is the root and the last is the parent of this node.

Annotations
@Override
getCharPositionInLineback to summary
public int getCharPositionInLine()

Implements org.antlr.runtime.tree.Tree.getCharPositionInLine.

Annotations
@Override
getChildback to summary
public Tree getChild(int i)

Implements org.antlr.runtime.tree.Tree.getChild.

Annotations
@Override
getChildCountback to summary
public int getChildCount()

Implements org.antlr.runtime.tree.Tree.getChildCount.

Annotations
@Override
getChildIndexback to summary
public int getChildIndex()

Implements org.antlr.runtime.tree.Tree.getChildIndex.

BaseTree doesn't track child indexes.

Annotations
@Override
getChildrenback to summary
public List<? extends Object> getChildren()

Get the children internal List; note that if you directly mess with the list, do so at your own risk.

getFirstChildWithTypeback to summary
public Tree getFirstChildWithType(int type)
getLineback to summary
public int getLine()

Implements org.antlr.runtime.tree.Tree.getLine.

Doc from org.antlr.runtime.tree.Tree.getLine.

In case we don't have a token payload, what is the line for errors?

Annotations
@Override
getParentback to summary
public Tree getParent()

Implements org.antlr.runtime.tree.Tree.getParent.

BaseTree doesn't track parent pointers.

Annotations
@Override
hasAncestorback to summary
public boolean hasAncestor(int ttype)

Implements org.antlr.runtime.tree.Tree.hasAncestor.

Walk upwards looking for ancestor with this token type.

Annotations
@Override
insertChildback to summary
public void insertChild(int i, Object t)

Insert child t at child position i (0..n-1) by shifting children i+1..n-1 to the right one position. Set parent / indexes properly but does NOT collapse nil-rooted t's that come in here like addChild.

isNilback to summary
public boolean isNil()

Implements org.antlr.runtime.tree.Tree.isNil.

Doc from org.antlr.runtime.tree.Tree.isNil.

Indicates the node is a nil node but may still have children, meaning the tree is a flat list.

Annotations
@Override
replaceChildrenback to summary
public void replaceChildren(int startChildIndex, int stopChildIndex, Object t)

Implements org.antlr.runtime.tree.Tree.replaceChildren.

Delete children from start to stop and replace with t even if t is a list (nil-root tree). num of children can increase or decrease. For huge child lists, inserting children can force walking rest of children to set their childindex; could be slow.

Annotations
@Override
sanityCheckParentAndChildIndexesback to summary
public void sanityCheckParentAndChildIndexes()
sanityCheckParentAndChildIndexesback to summary
public void sanityCheckParentAndChildIndexes(Tree parent, int i)
setChildback to summary
public void setChild(int i, Tree t)

Implements org.antlr.runtime.tree.Tree.setChild.

Doc from org.antlr.runtime.tree.Tree.setChild.

Set ith child (0..n-1) to t; t must be non-null and non-nil node

Annotations
@Override
setChildIndexback to summary
public void setChildIndex(int index)

Implements org.antlr.runtime.tree.Tree.setChildIndex.

Annotations
@Override
setParentback to summary
public void setParent(Tree t)

Implements org.antlr.runtime.tree.Tree.setParent.

Annotations
@Override
toStringback to summary
public abstract String toString()

Redeclares org.antlr.runtime.tree.Tree.toString.

Overrides java.lang.Object.toString.

Override to say how a node (not a tree) should look as text

Returns:String

Doc from java.lang.Object.toString.

a string representation of the object.

Annotations
@Override
toStringTreeback to summary
public String toStringTree()

Implements org.antlr.runtime.tree.Tree.toStringTree.

Print out a whole tree not just a node

Annotations
@Override