Package org.antlr.runtime.tree
Class CommonTree
- java.lang.Object
-
- org.antlr.runtime.tree.BaseTree
-
- org.antlr.runtime.tree.CommonTree
-
- All Implemented Interfaces:
Tree
- Direct Known Subclasses:
CommonErrorNode,TreeWizard.TreePattern
public class CommonTree extends BaseTree
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
Fields Modifier and Type Field Description intchildIndexWhat index is this node in the child list? Range: 0..n-1CommonTreeparentWho is the parent node of this node; if null, implies node is rootprotected intstartIndexWhat token indexes bracket all tokens associated with this node and below?protected intstopIndexWhat token indexes bracket all tokens associated with this node and below?TokentokenA single token is the payload-
Fields inherited from interface org.antlr.runtime.tree.Tree
INVALID_NODE
-
-
Constructor Summary
Constructors Constructor Description CommonTree()CommonTree(Token t)CommonTree(CommonTree node)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TreedupNode()intgetCharPositionInLine()intgetChildIndex()BaseTree doesn't track child indexes.intgetLine()In case we don't have a token payload, what is the line for errors?TreegetParent()BaseTree doesn't track parent pointers.StringgetText()TokengetToken()intgetTokenStartIndex()What is the smallest token index (indexing from 0) for this node and its children?intgetTokenStopIndex()What is the largest token index (indexing from 0) for this node and its children?intgetType()Return a token type; needed for tree parsingbooleanisNil()Indicates the node is a nil node but may still have children, meaning the tree is a flat list.voidsetChildIndex(int index)voidsetParent(Tree t)voidsetTokenStartIndex(int index)voidsetTokenStopIndex(int index)voidsetUnknownTokenBoundaries()For every node in this subtree, make sure it's start/stop token's are set.StringtoString()Override to say how a node (not a tree) should look as text-
Methods inherited from class org.antlr.runtime.tree.BaseTree
addChild, addChildren, createChildrenList, deleteChild, freshenParentAndChildIndexes, freshenParentAndChildIndexes, freshenParentAndChildIndexesDeeply, freshenParentAndChildIndexesDeeply, getAncestor, getAncestors, getChild, getChildCount, getChildren, getFirstChildWithType, hasAncestor, insertChild, replaceChildren, sanityCheckParentAndChildIndexes, sanityCheckParentAndChildIndexes, setChild, toStringTree
-
-
-
-
Field Detail
-
token
public Token token
A single token is the payload
-
startIndex
protected int startIndex
What token indexes bracket all tokens associated with this node and below?
-
stopIndex
protected int stopIndex
What token indexes bracket all tokens associated with this node and below?
-
parent
public CommonTree parent
Who is the parent node of this node; if null, implies node is root
-
childIndex
public int childIndex
What index is this node in the child list? Range: 0..n-1
-
-
Constructor Detail
-
CommonTree
public CommonTree()
-
CommonTree
public CommonTree(CommonTree node)
-
CommonTree
public CommonTree(Token t)
-
-
Method Detail
-
getToken
public Token getToken()
-
dupNode
public Tree dupNode()
-
isNil
public boolean isNil()
Description copied from interface:TreeIndicates the node is a nil node but may still have children, meaning the tree is a flat list.
-
getType
public int getType()
Description copied from interface:TreeReturn a token type; needed for tree parsing
-
getText
public String getText()
-
getLine
public int getLine()
Description copied from interface:TreeIn case we don't have a token payload, what is the line for errors?
-
getCharPositionInLine
public int getCharPositionInLine()
- Specified by:
getCharPositionInLinein interfaceTree- Overrides:
getCharPositionInLinein classBaseTree
-
getTokenStartIndex
public int getTokenStartIndex()
Description copied from interface:TreeWhat is the smallest token index (indexing from 0) for this node and its children?
-
setTokenStartIndex
public void setTokenStartIndex(int index)
-
getTokenStopIndex
public int getTokenStopIndex()
Description copied from interface:TreeWhat is the largest token index (indexing from 0) for this node and its children?
-
setTokenStopIndex
public void setTokenStopIndex(int index)
-
setUnknownTokenBoundaries
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.
-
getChildIndex
public int getChildIndex()
Description copied from class:BaseTreeBaseTree doesn't track child indexes.- Specified by:
getChildIndexin interfaceTree- Overrides:
getChildIndexin classBaseTree
-
getParent
public Tree getParent()
Description copied from class:BaseTreeBaseTree doesn't track parent pointers.
-
setParent
public void setParent(Tree t)
-
setChildIndex
public void setChildIndex(int index)
- Specified by:
setChildIndexin interfaceTree- Overrides:
setChildIndexin classBaseTree
-
-