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
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
FieldsModifier and TypeFieldDescriptionint
What index is this node in the child list? Range: 0..n-1Who is the parent node of this node; if null, implies node is rootprotected int
What token indexes bracket all tokens associated with this node and below?protected int
What token indexes bracket all tokens associated with this node and below?A single token is the payloadFields inherited from interface org.antlr.runtime.tree.Tree
INVALID_NODE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondupNode()
int
int
BaseTree doesn't track child indexes.int
getLine()
In case we don't have a token payload, what is the line for errors?BaseTree doesn't track parent pointers.getText()
getToken()
int
What is the smallest token index (indexing from 0) for this node and its children?int
What is the largest token index (indexing from 0) for this node and its children?int
getType()
Return a token type; needed for tree parsingboolean
isNil()
Indicates the node is a nil node but may still have children, meaning the tree is a flat list.void
setChildIndex
(int index) void
void
setTokenStartIndex
(int index) void
setTokenStopIndex
(int index) void
For every node in this subtree, make sure it's start/stop token's are set.toString()
Override to say how a node (not a tree) should look as textMethods 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 Details
-
token
A single token is the payload -
startIndex
protected int startIndexWhat token indexes bracket all tokens associated with this node and below? -
stopIndex
protected int stopIndexWhat token indexes bracket all tokens associated with this node and below? -
parent
Who is the parent node of this node; if null, implies node is root -
childIndex
public int childIndexWhat index is this node in the child list? Range: 0..n-1
-
-
Constructor Details
-
CommonTree
public CommonTree() -
CommonTree
-
CommonTree
-
-
Method Details
-
getToken
-
dupNode
-
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. -
getType
public int getType()Description copied from interface:Tree
Return a token type; needed for tree parsing -
getText
-
getLine
public int getLine()Description copied from interface:Tree
In case we don't have a token payload, what is the line for errors? -
getCharPositionInLine
public int getCharPositionInLine()- Specified by:
getCharPositionInLine
in interfaceTree
- Overrides:
getCharPositionInLine
in classBaseTree
-
getTokenStartIndex
public int getTokenStartIndex()Description copied from interface:Tree
What 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:Tree
What 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:BaseTree
BaseTree doesn't track child indexes.- Specified by:
getChildIndex
in interfaceTree
- Overrides:
getChildIndex
in classBaseTree
-
getParent
Description copied from class:BaseTree
BaseTree doesn't track parent pointers. -
setParent
-
setChildIndex
public void setChildIndex(int index) - Specified by:
setChildIndex
in interfaceTree
- Overrides:
setChildIndex
in classBaseTree
-
toString
Description copied from class:BaseTree
Override to say how a node (not a tree) should look as text
-