Class BaseTree
java.lang.Object
org.antlr.runtime.tree.BaseTree
- All Implemented Interfaces:
Tree
- Direct Known Subclasses:
CommonTree, ParseTree, RemoteDebugEventSocketListener.ProxyTree
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
FieldsFields inherited from interface Tree
INVALID_NODE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd t as child of this node.voidaddChildren(List<? extends Tree> kids) Add all elements of kids list as children of this nodeOverride in a subclass to change the impl of children listdeleteChild(int i) voidSet the parent and child index values for all child of tvoidfreshenParentAndChildIndexes(int offset) voidvoidfreshenParentAndChildIndexesDeeply(int offset) getAncestor(int ttype) Walk upwards and get first ancestor with this token type.Return a list of all ancestors of this node.intgetChild(int i) intintBaseTree doesn't track child indexes.Get the children internal List; note that if you directly mess with the list, do so at your own risk.getFirstChildWithType(int type) intgetLine()In case we don't have a token payload, what is the line for errors?BaseTree doesn't track parent pointers.booleanhasAncestor(int ttype) Walk upwards looking for ancestor with this token type.voidinsertChild(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.booleanisNil()Indicates the node is a nil node but may still have children, meaning the tree is a flat list.voidreplaceChildren(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).voidvoidsanityCheckParentAndChildIndexes(Tree parent, int i) voidSet ith child (0..n-1) to t; t must be non-null and non-nil nodevoidsetChildIndex(int index) voidabstract StringtoString()Override to say how a node (not a tree) should look as textPrint out a whole tree not just a nodeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Tree
dupNode, getText, getTokenStartIndex, getTokenStopIndex, getType, setTokenStartIndex, setTokenStopIndex
-
Field Details
-
children
-
-
Constructor Details
-
BaseTree
public BaseTree() -
BaseTree
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 Details
-
getChild
-
getChildren
-
getFirstChildWithType
-
getChildCount
public int getChildCount()- Specified by:
getChildCountin interfaceTree
-
addChild
-
addChildren
-
setChild
-
insertChild
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. -
deleteChild
- Specified by:
deleteChildin interfaceTree
-
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.- Specified by:
replaceChildrenin interfaceTree
-
createChildrenList
-
isNil
-
freshenParentAndChildIndexes
public void freshenParentAndChildIndexes()Set the parent and child index values for all child of t- Specified by:
freshenParentAndChildIndexesin interfaceTree
-
freshenParentAndChildIndexes
public void freshenParentAndChildIndexes(int offset) -
freshenParentAndChildIndexesDeeply
public void freshenParentAndChildIndexesDeeply() -
freshenParentAndChildIndexesDeeply
public void freshenParentAndChildIndexesDeeply(int offset) -
sanityCheckParentAndChildIndexes
public void sanityCheckParentAndChildIndexes() -
sanityCheckParentAndChildIndexes
-
getChildIndex
public int getChildIndex()BaseTree doesn't track child indexes.- Specified by:
getChildIndexin interfaceTree
-
setChildIndex
public void setChildIndex(int index) - Specified by:
setChildIndexin interfaceTree
-
getParent
-
setParent
-
hasAncestor
public boolean hasAncestor(int ttype) Walk upwards looking for ancestor with this token type.- Specified by:
hasAncestorin interfaceTree
-
getAncestor
Walk upwards and get first ancestor with this token type.- Specified by:
getAncestorin interfaceTree
-
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.- Specified by:
getAncestorsin interfaceTree
-
toStringTree
Print out a whole tree not just a node- Specified by:
toStringTreein interfaceTree
-
getLine
-
getCharPositionInLine
public int getCharPositionInLine()- Specified by:
getCharPositionInLinein interfaceTree
-
toString
-