Top Description Fields Methods
org.antlr.runtime.tree

public Interface Tree

Known Direct Implementers
org.antlr.runtime.tree.BaseTree
Imports
org.antlr.runtime.Token, java.util.List

What does a tree look like? ANTLR has a number of support classes such as CommonTreeNodeStream that work on these kinds of trees. You don't have to make your trees implement this interface, but if you do, you'll be able to use more support code.

Note

When constructing trees, ANTLR can build any kind of tree; it can even use Token objects as trees if you add a child list to your tokens. This is a tree node without any payload; just navigation and factory stuff.

Field Summary

Modifier and TypeField and Description
public static final Tree

Method Summary

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

Add t as a child to this node.

public Object
deleteChild(int i)

public Tree
public void
freshenParentAndChildIndexes()

Set the parent and child index values for all children

public Tree
getAncestor(int ttype)

Walk upwards and get first ancestor with this token type.

public List<?>
getAncestors()

Return a list of all ancestors of this node.

public int
public Tree
getChild(int i)

public int
public int
getChildIndex()

This node is what child index?

public int
getLine()

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

public Tree
public String
public int
getTokenStartIndex()

What is the smallest token index (indexing from 0) for this node and its children?

public int
getTokenStopIndex()

What is the largest token index (indexing from 0) for this node and its children?

public int
getType()

Return a token type; needed for tree parsing

public boolean
hasAncestor(int ttype)

Is there is a node above with token type ttype?

public boolean
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)

Delete children from start to stop and replace with t even if t is a list (nil-root tree).

public void
setChild(int i, Tree t)

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

public void
setChildIndex(int index)

public void
public void
setTokenStartIndex(int index)

public void
setTokenStopIndex(int index)

public String
public String

Field Detail

INVALID_NODEback to summary
public static final Tree INVALID_NODE

Method Detail

addChildback to summary
public void addChild(Tree t)

Add t as a child to this node. If t is null, do nothing. If t is nil, add all children of t to this' children.

deleteChildback to summary
public Object deleteChild(int i)
dupNodeback to summary
public Tree dupNode()
freshenParentAndChildIndexesback to summary
public void freshenParentAndChildIndexes()

Set the parent and child index values for all children

getAncestorback to summary
public Tree getAncestor(int ttype)

Walk upwards and get first ancestor with this token type.

getAncestorsback to summary
public List<?> 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.

getCharPositionInLineback to summary
public int getCharPositionInLine()
getChildback to summary
public Tree getChild(int i)
getChildCountback to summary
public int getChildCount()
getChildIndexback to summary
public int getChildIndex()

This node is what child index? 0..n-1

getLineback to summary
public int getLine()

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

getParentback to summary
public Tree getParent()
getTextback to summary
public String getText()
getTokenStartIndexback to summary
public int getTokenStartIndex()

What is the smallest token index (indexing from 0) for this node and its children?

getTokenStopIndexback to summary
public int getTokenStopIndex()

What is the largest token index (indexing from 0) for this node and its children?

getTypeback to summary
public int getType()

Return a token type; needed for tree parsing

hasAncestorback to summary
public boolean hasAncestor(int ttype)

Is there is a node above with token type ttype?

isNilback to summary
public boolean isNil()

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

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

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.

setChildback to summary
public void setChild(int i, Tree t)

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

setChildIndexback to summary
public void setChildIndex(int index)
setParentback to summary
public void setParent(Tree t)
setTokenStartIndexback to summary
public void setTokenStartIndex(int index)
setTokenStopIndexback to summary
public void setTokenStopIndex(int index)
toStringback to summary
public String toString()
Annotations
@Override
toStringTreeback to summary
public String toStringTree()