Top Constructors Methods
org.antlr.v4.runtime.tree

public abstract Class AbstractParseTreeVisitor<T>

extends Object
implements ParseTreeVisitor<T>
Class Inheritance
All Implemented Interfaces
org.antlr.v4.runtime.tree.ParseTreeVisitor

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected T

Returns:

The updated aggregate result.
aggregateResult
(T
The previous aggregate value. In the default implementation, the aggregate value is initialized to defaultResult, which is passed as the aggregate argument to this method after the first child node is visited.
aggregate
,
T
The result of the immediately preceeding call to visit a child node.
nextResult
)

Aggregates the results of visiting multiple children of a node.

protected T

Returns:

The default value returned by visitor methods.
defaultResult
()

Gets the default value returned by visitor methods.

protected boolean

Returns:

true to continue visiting children. Otherwise return false to stop visiting children and immediately return the current aggregate result from visitChildren.
shouldVisitNextChild
(RuleNode
The RuleNode whose children are currently being visited.
node
,
T
The current aggregate result of the children visited to the current point.
currentResult
)

This method is called after visiting each child in visitChildren.

public T
visit(ParseTree
The ParseTree to visit.
tree
)

Implements org.antlr.v4.runtime.tree.ParseTreeVisitor.visit.

Visit a parse tree, and return a user-defined result of the operation.
public T
visitChildren(RuleNode
The RuleNode whose children should be visited.
node
)

Implements org.antlr.v4.runtime.tree.ParseTreeVisitor.visitChildren.

Visit the children of a node, and return a user-defined result of the operation.
public T
visitErrorNode(ErrorNode
The ErrorNode to visit.
node
)

Implements org.antlr.v4.runtime.tree.ParseTreeVisitor.visitErrorNode.

Visit an error node, and return a user-defined result of the operation.
public T
visitTerminal(TerminalNode
The TerminalNode to visit.
node
)

Implements org.antlr.v4.runtime.tree.ParseTreeVisitor.visitTerminal.

Visit a terminal node, and return a user-defined result of the operation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AbstractParseTreeVisitorback to summary
public AbstractParseTreeVisitor()

Method Detail

aggregateResultback to summary
protected T aggregateResult(T aggregate, T nextResult)

Aggregates the results of visiting multiple children of a node. After either all children are visited or shouldVisitNextChild returns false, the aggregate value is returned as the result of visitChildren.

The default implementation returns nextResult, meaning visitChildren will return the result of the last child visited (or return the initial value if the node has no children).

Parameters
aggregate:T

The previous aggregate value. In the default implementation, the aggregate value is initialized to defaultResult, which is passed as the aggregate argument to this method after the first child node is visited.

nextResult:T

The result of the immediately preceeding call to visit a child node.

Returns:T

The updated aggregate result.

defaultResultback to summary
protected T defaultResult()

Gets the default value returned by visitor methods. This value is returned by the default implementations of visitTerminal, visitErrorNode. The default implementation of visitChildren initializes its aggregate result to this value.

The base implementation returns null.

Returns:T

The default value returned by visitor methods.

shouldVisitNextChildback to summary
protected boolean shouldVisitNextChild(RuleNode node, T currentResult)

This method is called after visiting each child in visitChildren. This method is first called before the first child is visited; at that point currentResult will be the initial value (in the default implementation, the initial value is returned by a call to defaultResult. This method is not called after the last child is visited.

The default implementation always returns true, indicating that visitChildren should only return after all children are visited. One reason to override this method is to provide a "short circuit" evaluation option for situations where the result of visiting a single child has the potential to determine the result of the visit operation as a whole.

Parameters
node:RuleNode

The RuleNode whose children are currently being visited.

currentResult:T

The current aggregate result of the children visited to the current point.

Returns:boolean

true to continue visiting children. Otherwise return false to stop visiting children and immediately return the current aggregate result from visitChildren.

visitback to summary
public T visit(ParseTree tree)

Implements org.antlr.v4.runtime.tree.ParseTreeVisitor.visit.

Doc from org.antlr.v4.runtime.tree.ParseTreeVisitor.visit.

Visit a parse tree, and return a user-defined result of the operation.

The default implementation calls ParseTree#accept on the specified tree.

Parameters
tree:ParseTree

The ParseTree to visit.

Returns:T

The result of visiting the parse tree.

Annotations
@Override
visitChildrenback to summary
public T visitChildren(RuleNode node)

Implements org.antlr.v4.runtime.tree.ParseTreeVisitor.visitChildren.

Doc from org.antlr.v4.runtime.tree.ParseTreeVisitor.visitChildren.

Visit the children of a node, and return a user-defined result of the operation.

The default implementation initializes the aggregate result to defaultResult(). Before visiting each child, it calls shouldVisitNextChild; if the result is false no more children are visited and the current aggregate result is returned. After visiting a child, the aggregate result is updated by calling aggregateResult with the previous aggregate result and the result of visiting the child.

The default implementation is not safe for use in visitors that modify the tree structure. Visitors that modify the tree should override this method to behave properly in respect to the specific algorithm in use.

Parameters
node:RuleNode

The RuleNode whose children should be visited.

Returns:T

The result of visiting the children of the node.

Annotations
@Override
visitErrorNodeback to summary
public T visitErrorNode(ErrorNode node)

Implements org.antlr.v4.runtime.tree.ParseTreeVisitor.visitErrorNode.

Doc from org.antlr.v4.runtime.tree.ParseTreeVisitor.visitErrorNode.

Visit an error node, and return a user-defined result of the operation.

The default implementation returns the result of defaultResult.

Parameters
node:ErrorNode

The ErrorNode to visit.

Returns:T

The result of visiting the node.

Annotations
@Override
visitTerminalback to summary
public T visitTerminal(TerminalNode node)

Implements org.antlr.v4.runtime.tree.ParseTreeVisitor.visitTerminal.

Doc from org.antlr.v4.runtime.tree.ParseTreeVisitor.visitTerminal.

Visit a terminal node, and return a user-defined result of the operation.

The default implementation returns the result of defaultResult.

Parameters
node:TerminalNode

The TerminalNode to visit.

Returns:T

The result of visiting the node.

Annotations
@Override