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

public Class CommonTree

extends BaseTree
Class Inheritance
Known Direct Subclasses
org.antlr.runtime.tree.TreeWizard.TreePattern, org.antlr.runtime.tree.CommonErrorNode
Imports
org.antlr.runtime.Token

A tree node that is wrapper for a Token object. After 3.0 release while building tree rewrite stuff, it became clear that computing parent and child index is very difficult and cumbersome. Better to spend the space in every tree node. If you don't want these extra fields, it's easy to cut them out in your own BaseTree subclass.

Field Summary

Modifier and TypeField and Description
public int
childIndex

What index is this node in the child list?

public CommonTree
parent

Who is the parent node of this node; if null, implies node is root

protected int
startIndex

What token indexes bracket all tokens associated with this node and below?

protected int
stopIndex

What token indexes bracket all tokens associated with this node and below?

public Token
token

A single token is the payload

Inherited from org.antlr.runtime.tree.BaseTree:
children

Constructor Summary

AccessConstructor and Description
public
public
public

Method Summary

Modifier and TypeMethod and Description
public Tree
public int
public int
public int
getLine()

Overrides org.antlr.runtime.tree.BaseTree.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()

Overrides org.antlr.runtime.tree.BaseTree.getParent.

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

BaseTree doesn't track parent pointers.
public String
public Token
public int
getTokenStartIndex()

Implements org.antlr.runtime.tree.Tree.getTokenStartIndex.

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

Implements org.antlr.runtime.tree.Tree.getTokenStopIndex.

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

Implements org.antlr.runtime.tree.Tree.getType.

Return a token type; needed for tree parsing
public boolean
isNil()

Overrides org.antlr.runtime.tree.BaseTree.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
public void
public void
public void
public void
setUnknownTokenBoundaries()

For every node in this subtree, make sure it's start/stop token's are set.

public String
toString()

Implements abstract org.antlr.runtime.tree.BaseTree.toString.

Implements org.antlr.runtime.tree.Tree.toString.

Override to say how a node (not a tree) should look as text
Inherited from org.antlr.runtime.tree.BaseTree:
addChildaddChildrencreateChildrenListdeleteChildfreshenParentAndChildIndexesfreshenParentAndChildIndexesfreshenParentAndChildIndexesDeeplyfreshenParentAndChildIndexesDeeplygetAncestorgetAncestorsgetChildgetChildCountgetChildrengetFirstChildWithTypehasAncestorinsertChildreplaceChildrensanityCheckParentAndChildIndexessanityCheckParentAndChildIndexessetChildtoStringTree

Field Detail

childIndexback to summary
public int childIndex

What index is this node in the child list? Range: 0..n-1

parentback to summary
public CommonTree parent

Who is the parent node of this node; if null, implies node is root

startIndexback to summary
protected int startIndex

What token indexes bracket all tokens associated with this node and below?

stopIndexback to summary
protected int stopIndex

What token indexes bracket all tokens associated with this node and below?

tokenback to summary
public Token token

A single token is the payload

Constructor Detail

CommonTreeback to summary
public CommonTree()
CommonTreeback to summary
public CommonTree(CommonTree node)
CommonTreeback to summary
public CommonTree(Token t)

Method Detail

dupNodeback to summary
public Tree dupNode()

Implements org.antlr.runtime.tree.Tree.dupNode.

Annotations
@Override
getCharPositionInLineback to summary
public int getCharPositionInLine()

Overrides org.antlr.runtime.tree.BaseTree.getCharPositionInLine.

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

Annotations
@Override
getChildIndexback to summary
public int getChildIndex()

Overrides org.antlr.runtime.tree.BaseTree.getChildIndex.

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

Doc from org.antlr.runtime.tree.BaseTree.getChildIndex.

BaseTree doesn't track child indexes.

Annotations
@Override
getLineback to summary
public int getLine()

Overrides org.antlr.runtime.tree.BaseTree.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()

Overrides org.antlr.runtime.tree.BaseTree.getParent.

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

Doc from org.antlr.runtime.tree.BaseTree.getParent.

BaseTree doesn't track parent pointers.

Annotations
@Override
getTextback to summary
public String getText()

Implements org.antlr.runtime.tree.Tree.getText.

Annotations
@Override
getTokenback to summary
public Token getToken()
getTokenStartIndexback to summary
public int getTokenStartIndex()

Implements org.antlr.runtime.tree.Tree.getTokenStartIndex.

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

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

Annotations
@Override
getTokenStopIndexback to summary
public int getTokenStopIndex()

Implements org.antlr.runtime.tree.Tree.getTokenStopIndex.

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

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

Annotations
@Override
getTypeback to summary
public int getType()

Implements org.antlr.runtime.tree.Tree.getType.

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

Return a token type; needed for tree parsing

Annotations
@Override
isNilback to summary
public boolean isNil()

Overrides org.antlr.runtime.tree.BaseTree.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
setChildIndexback to summary
public void setChildIndex(int index)

Overrides org.antlr.runtime.tree.BaseTree.setChildIndex.

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

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

Overrides org.antlr.runtime.tree.BaseTree.setParent.

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

Annotations
@Override
setTokenStartIndexback to summary
public void setTokenStartIndex(int index)

Implements org.antlr.runtime.tree.Tree.setTokenStartIndex.

Annotations
@Override
setTokenStopIndexback to summary
public void setTokenStopIndex(int index)

Implements org.antlr.runtime.tree.Tree.setTokenStopIndex.

Annotations
@Override
setUnknownTokenBoundariesback to summary
public void setUnknownTokenBoundaries()

For every node in this subtree, make sure it's start/stop token's are set. Walk depth first, visit bottom up. Only updates nodes with at least one token index < 0.

toStringback to summary
public String toString()

Implements abstract org.antlr.runtime.tree.BaseTree.toString.

Implements org.antlr.runtime.tree.Tree.toString.

Doc from org.antlr.runtime.tree.BaseTree.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