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

public Class CommonTreeAdaptor

extends BaseTreeAdaptor
Class Inheritance
Known Direct Subclasses
org.antlr.runtime.tree.TreeWizard.TreePatternTreeAdaptor
Imports
org.antlr.runtime.CommonToken, .Token

A TreeAdaptor that works with any Tree implementation. It provides really just factory methods; all the work is done by BaseTreeAdaptor. If you would like to have different tokens created than ClassicToken objects, you need to override this and then set the parser tree adaptor to use your subclass. To get your parser to build nodes of a different type, override create(Token), errorNode(), and to be safe, YourTreeClass.dupNode(). dupNode is called to duplicate nodes during rewrite operations.

Field Summary

Inherited from org.antlr.runtime.tree.BaseTreeAdaptor:
treeToUniqueIDMapuniqueNodeID

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object
create(Token payload)

Implements org.antlr.runtime.tree.TreeAdaptor.create.

Create a tree node from Token object; for CommonTree type trees, then the token just becomes the payload.
public Token
createToken(int tokenType, String text)

Implements abstract org.antlr.runtime.tree.BaseTreeAdaptor.createToken.

Tell me how to create a token for use with imaginary token nodes.
public Token
createToken(Token fromToken)

Implements abstract org.antlr.runtime.tree.BaseTreeAdaptor.createToken.

Tell me how to create a token for use with imaginary token nodes.
public Object
public Object
public int
public int
getChildIndex(Object t)

Implements org.antlr.runtime.tree.TreeAdaptor.getChildIndex.

What index is this node in the child list?
public Object
getParent(Object t)

Implements org.antlr.runtime.tree.TreeAdaptor.getParent.

Who is the parent node of this node; if null, implies node is root.
public String
public Token
getToken(Object t)

Implements org.antlr.runtime.tree.TreeAdaptor.getToken.

What is the Token associated with this node?
public int
getTokenStartIndex(Object t)

Implements org.antlr.runtime.tree.TreeAdaptor.getTokenStartIndex.

Get the token start index for this subtree; return -1 if no such index
public int
getTokenStopIndex(Object t)

Implements org.antlr.runtime.tree.TreeAdaptor.getTokenStopIndex.

Get the token stop index for this subtree; return -1 if no such index
public int
getType(Object t)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.getType.

Implements org.antlr.runtime.tree.TreeAdaptor.getType.

For tree parsing, I need to know the token type of a node
public void
replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t)

Implements org.antlr.runtime.tree.TreeAdaptor.replaceChildren.

Replace from start to stop child index of parent with t, which might be a list.
public void
public void
public void
setTokenBoundaries(Object t, Token startToken, Token stopToken)

Implements org.antlr.runtime.tree.TreeAdaptor.setTokenBoundaries.

Track start/stop token for subtree root created for a rule.
Inherited from org.antlr.runtime.tree.BaseTreeAdaptor:
addChildbecomeRootbecomeRootcreatecreatecreatedeleteChilddupTreedupTreeerrorNodegetUniqueIDisNilnilrulePostProcessingsetChildsetTextsetType

Constructor Detail

CommonTreeAdaptorback to summary
public CommonTreeAdaptor()

Method Detail

createback to summary
public Object create(Token payload)

Implements org.antlr.runtime.tree.TreeAdaptor.create.

Doc from org.antlr.runtime.tree.TreeAdaptor.create.

Create a tree node from Token object; for CommonTree type trees, then the token just becomes the payload. This is the most common create call. Override if you want another kind of node to be built.

Annotations
@Override
createTokenback to summary
public Token createToken(int tokenType, String text)

Implements abstract org.antlr.runtime.tree.BaseTreeAdaptor.createToken.

Tell me how to create a token for use with imaginary token nodes. For example, there is probably no input symbol associated with imaginary token DECL, but you need to create it as a payload or whatever for the DECL node as in ^(DECL type ID). If you care what the token payload objects' type is, you should override this method and any other createToken variant.

Annotations
@Override
createTokenback to summary
public Token createToken(Token fromToken)

Implements abstract org.antlr.runtime.tree.BaseTreeAdaptor.createToken.

Tell me how to create a token for use with imaginary token nodes. For example, there is probably no input symbol associated with imaginary token DECL, but you need to create it as a payload or whatever for the DECL node as in ^(DECL type ID). This is a variant of createToken where the new token is derived from an actual real input token. Typically this is for converting '{' tokens to BLOCK etc... You'll see r : lc='{' ID+ '}' -> ^(BLOCK[$lc] ID+) ; If you care what the token payload objects' type is, you should override this method and any other createToken variant.

Annotations
@Override
dupNodeback to summary
public Object dupNode(Object t)

Implements org.antlr.runtime.tree.TreeAdaptor.dupNode.

Duplicate a node. This is part of the factory; override if you want another kind of node to be built. I could use reflection to prevent having to override this but reflection is slow.

Annotations
@Override
getChildback to summary
public Object getChild(Object t, int i)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.getChild.

Implements org.antlr.runtime.tree.TreeAdaptor.getChild.

Doc from org.antlr.runtime.tree.TreeAdaptor.getChild.

Get a child 0..n-1 node

Annotations
@Override
getChildCountback to summary
public int getChildCount(Object t)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.getChildCount.

Implements org.antlr.runtime.tree.TreeAdaptor.getChildCount.

Doc from org.antlr.runtime.tree.TreeAdaptor.getChildCount.

How many children? If 0, then this is a leaf node

Annotations
@Override
getChildIndexback to summary
public int getChildIndex(Object t)

Implements org.antlr.runtime.tree.TreeAdaptor.getChildIndex.

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

What index is this node in the child list? Range: 0..n-1 If your node type doesn't handle this, it's ok but the tree rewrites in tree parsers need this functionality.

Annotations
@Override
getParentback to summary
public Object getParent(Object t)

Implements org.antlr.runtime.tree.TreeAdaptor.getParent.

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

Who is the parent node of this node; if null, implies node is root. If your node type doesn't handle this, it's ok but the tree rewrites in tree parsers need this functionality.

Annotations
@Override
getTextback to summary
public String getText(Object t)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.getText.

Implements org.antlr.runtime.tree.TreeAdaptor.getText.

Annotations
@Override
getTokenback to summary
public Token getToken(Object t)

Implements org.antlr.runtime.tree.TreeAdaptor.getToken.

What is the Token associated with this node? If you are not using CommonTree, then you must override this in your own adaptor.

Annotations
@Override
getTokenStartIndexback to summary
public int getTokenStartIndex(Object t)

Implements org.antlr.runtime.tree.TreeAdaptor.getTokenStartIndex.

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

Get the token start index for this subtree; return -1 if no such index

Annotations
@Override
getTokenStopIndexback to summary
public int getTokenStopIndex(Object t)

Implements org.antlr.runtime.tree.TreeAdaptor.getTokenStopIndex.

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

Get the token stop index for this subtree; return -1 if no such index

Annotations
@Override
getTypeback to summary
public int getType(Object t)

Overrides org.antlr.runtime.tree.BaseTreeAdaptor.getType.

Implements org.antlr.runtime.tree.TreeAdaptor.getType.

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

For tree parsing, I need to know the token type of a node

Annotations
@Override
replaceChildrenback to summary
public void replaceChildren(Object parent, int startChildIndex, int stopChildIndex, Object t)

Implements org.antlr.runtime.tree.TreeAdaptor.replaceChildren.

Doc from org.antlr.runtime.tree.TreeAdaptor.replaceChildren.

Replace from start to stop child index of parent with t, which might be a list. Number of children may be different after this call. If parent is null, don't do anything; must be at root of overall tree. Can't replace whatever points to the parent externally. Do nothing.

Annotations
@Override
setChildIndexback to summary
public void setChildIndex(Object t, int index)

Implements org.antlr.runtime.tree.TreeAdaptor.setChildIndex.

Annotations
@Override
setParentback to summary
public void setParent(Object t, Object parent)

Implements org.antlr.runtime.tree.TreeAdaptor.setParent.

Annotations
@Override
setTokenBoundariesback to summary
public void setTokenBoundaries(Object t, Token startToken, Token stopToken)

Implements org.antlr.runtime.tree.TreeAdaptor.setTokenBoundaries.

Track start/stop token for subtree root created for a rule. Only works with Tree nodes. For rules that match nothing, seems like this will yield start=i and stop=i-1 in a nil node. Might be useful info so I'll not force to be i..i.

Annotations
@Override