R
- the return type of this visitor's methods. Use Void
for visitors that do not need to return results.P
- the type of the additional parameter to this visitor's
methods. Use Void
for visitors that do not need an
additional parameter.public class TreeScanner<R,P> extends Object implements TreeVisitor<R,P>
The default implementation of the visitXYZ methods will determine a result as follows:
null
.
scan
on that child. The child may be a simple node
or itself a list of nodes.
scan
each child in turn, and then combining the
result of each scan after the first with the cumulative result
so far, as determined by the reduce(R, R)
method. Each child may be either
a simple node of a list of nodes. The default behavior of the reduce
method is such that the result of the visitXYZ method will be the result of
the last child scanned.
Here is an example to count the number of identifier nodes in a tree:
class CountIdentifiers extends TreeScanner<Integer,Void> { @Override public Integer visitIdentifier(IdentifierTree node, Void p) { return 1; } @Override public Integer reduce(Integer r1, Integer r2) { return (r1 == null ? 0 : r1) + (r2 == null ? 0 : r2); } }
Constructor and Description |
---|
TreeScanner() |
Modifier and Type | Method and Description |
---|---|
R |
reduce(R r1,
R r2)
Reduces two results into a combined result.
|
R |
scan(Tree tree,
P p)
Scans a single node.
|
R |
scan(Iterable<? extends Tree> nodes,
P p)
Scans a sequence of nodes.
|
R |
visitAnnotatedType(AnnotatedTypeTree node,
P p)
Visits an AnnotatedTypeTree node.
|
R |
visitAnnotation(AnnotationTree node,
P p)
Visits an AnnotatedTree node.
|
R |
visitArrayAccess(ArrayAccessTree node,
P p)
Visits an ArrayAccessTree node.
|
R |
visitArrayType(ArrayTypeTree node,
P p)
Visits an ArrayTypeTree node.
|
R |
visitAssert(AssertTree node,
P p)
Visits an AssertTree node.
|
R |
visitAssignment(AssignmentTree node,
P p)
Visits an AssignmentTree node.
|
R |
visitBinary(BinaryTree node,
P p)
Visits a BinaryTree node.
|
R |
visitBlock(BlockTree node,
P p)
Visits a BlockTree node.
|
R |
visitBreak(BreakTree node,
P p)
Visits a BreakTree node.
|
R |
visitCase(CaseTree node,
P p)
Visits a CaseTree node.
|
R |
visitCatch(CatchTree node,
P p)
Visits a CatchTree node.
|
R |
visitClass(ClassTree node,
P p)
Visits a ClassTree node.
|
R |
visitCompilationUnit(CompilationUnitTree node,
P p)
Visits a CompilationUnitTree node.
|
R |
visitCompoundAssignment(CompoundAssignmentTree node,
P p)
Visits a CompoundAssignmentTree node.
|
R |
visitConditionalExpression(ConditionalExpressionTree node,
P p)
Visits a ConditionalExpressionTree node.
|
R |
visitContinue(ContinueTree node,
P p)
Visits a ContinueTree node.
|
R |
visitDoWhileLoop(DoWhileLoopTree node,
P p)
Visits a DoWhileTree node.
|
R |
visitEmptyStatement(EmptyStatementTree node,
P p)
Visits an EmptyStatementTree node.
|
R |
visitEnhancedForLoop(EnhancedForLoopTree node,
P p)
Visits an EnhancedForLoopTree node.
|
R |
visitErroneous(ErroneousTree node,
P p)
Visits an ErroneousTree node.
|
R |
visitExpressionStatement(ExpressionStatementTree node,
P p)
Visits an ExpressionStatementTree node.
|
R |
visitForLoop(ForLoopTree node,
P p)
Visits a ForLoopTree node.
|
R |
visitIdentifier(IdentifierTree node,
P p)
Visits an IdentifierTree node.
|
R |
visitIf(IfTree node,
P p)
Visits an IfTree node.
|
R |
visitImport(ImportTree node,
P p)
Visits an ImportTree node.
|
R |
visitInstanceOf(InstanceOfTree node,
P p)
Visits an InstanceOfTree node.
|
R |
visitIntersectionType(IntersectionTypeTree node,
P p)
Visits an IntersectionTypeTree node.
|
R |
visitLabeledStatement(LabeledStatementTree node,
P p)
Visits a LabeledStatementTree node.
|
R |
visitLambdaExpression(LambdaExpressionTree node,
P p)
Visits a LambdaExpressionTree node.
|
R |
visitLiteral(LiteralTree node,
P p)
Visits a LiteralTree node.
|
R |
visitMemberReference(MemberReferenceTree node,
P p)
Visits a MemberReferenceTree node.
|
R |
visitMemberSelect(MemberSelectTree node,
P p)
Visits a MemberSelectTree node.
|
R |
visitMethod(MethodTree node,
P p)
Visits a MethodTree node.
|
R |
visitMethodInvocation(MethodInvocationTree node,
P p)
Visits a MethodInvocationTree node.
|
R |
visitModifiers(ModifiersTree node,
P p)
Visits a ModifiersTree node.
|
R |
visitNewArray(NewArrayTree node,
P p)
Visits a NewArrayTree node.
|
R |
visitNewClass(NewClassTree node,
P p)
Visits a NewClassTree node.
|
R |
visitOther(Tree node,
P p)
Visits an unknown type of Tree node.
|
R |
visitPackage(PackageTree node,
P p)
Visits a PackageTree node.
|
R |
visitParameterizedType(ParameterizedTypeTree node,
P p)
Visits a ParameterizedTypeTree node.
|
R |
visitParenthesized(ParenthesizedTree node,
P p)
Visits a ParenthesizedTree node.
|
R |
visitPrimitiveType(PrimitiveTypeTree node,
P p)
Visits a PrimitiveTypeTree node.
|
R |
visitReturn(ReturnTree node,
P p)
Visits a ReturnTree node.
|
R |
visitSwitch(SwitchTree node,
P p)
Visits a SwitchTree node.
|
R |
visitSynchronized(SynchronizedTree node,
P p)
Visits a SynchronizedTree node.
|
R |
visitThrow(ThrowTree node,
P p)
Visits a ThrowTree node.
|
R |
visitTry(TryTree node,
P p)
Visits a TryTree node.
|
R |
visitTypeCast(TypeCastTree node,
P p)
Visits a TypeCastTree node.
|
R |
visitTypeParameter(TypeParameterTree node,
P p)
Visits a TypeParameterTree node.
|
R |
visitUnary(UnaryTree node,
P p)
Visits a UnaryTree node.
|
R |
visitUnionType(UnionTypeTree node,
P p)
Visits a UnionTypeTree node.
|
R |
visitVariable(VariableTree node,
P p)
Visits a VariableTree node.
|
R |
visitWhileLoop(WhileLoopTree node,
P p)
Visits a WhileLoopTree node.
|
R |
visitWildcard(WildcardTree node,
P p)
Visits a WildcardTypeTree node.
|
public R scan(Tree tree, P p)
tree
- the node to be scannedp
- a parameter value passed to the visit methodpublic R scan(Iterable<? extends Tree> nodes, P p)
nodes
- the nodes to be scannedp
- a parameter value to be passed to the visit method for each nodereduce
method.public R reduce(R r1, R r2)
r1
- the first of the values to be combinedr2
- the second of the values to be combinedpublic R visitCompilationUnit(CompilationUnitTree node, P p)
visitCompilationUnit
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitPackage(PackageTree node, P p)
visitPackage
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitImport(ImportTree node, P p)
visitImport
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitClass(ClassTree node, P p)
visitClass
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitMethod(MethodTree node, P p)
visitMethod
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitVariable(VariableTree node, P p)
visitVariable
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitEmptyStatement(EmptyStatementTree node, P p)
null
.visitEmptyStatement
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitBlock(BlockTree node, P p)
visitBlock
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitDoWhileLoop(DoWhileLoopTree node, P p)
visitDoWhileLoop
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitWhileLoop(WhileLoopTree node, P p)
visitWhileLoop
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitForLoop(ForLoopTree node, P p)
visitForLoop
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitEnhancedForLoop(EnhancedForLoopTree node, P p)
visitEnhancedForLoop
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitLabeledStatement(LabeledStatementTree node, P p)
visitLabeledStatement
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitSwitch(SwitchTree node, P p)
visitSwitch
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitCase(CaseTree node, P p)
visitCase
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitSynchronized(SynchronizedTree node, P p)
visitSynchronized
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitTry(TryTree node, P p)
visitTry
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitCatch(CatchTree node, P p)
visitCatch
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitConditionalExpression(ConditionalExpressionTree node, P p)
visitConditionalExpression
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitIf(IfTree node, P p)
visitIf
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitExpressionStatement(ExpressionStatementTree node, P p)
visitExpressionStatement
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitBreak(BreakTree node, P p)
null
.visitBreak
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitContinue(ContinueTree node, P p)
null
.visitContinue
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitReturn(ReturnTree node, P p)
visitReturn
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitThrow(ThrowTree node, P p)
visitThrow
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitAssert(AssertTree node, P p)
visitAssert
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitMethodInvocation(MethodInvocationTree node, P p)
visitMethodInvocation
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitNewClass(NewClassTree node, P p)
visitNewClass
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitNewArray(NewArrayTree node, P p)
visitNewArray
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitLambdaExpression(LambdaExpressionTree node, P p)
visitLambdaExpression
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitParenthesized(ParenthesizedTree node, P p)
visitParenthesized
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitAssignment(AssignmentTree node, P p)
visitAssignment
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitCompoundAssignment(CompoundAssignmentTree node, P p)
visitCompoundAssignment
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitUnary(UnaryTree node, P p)
visitUnary
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitBinary(BinaryTree node, P p)
visitBinary
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitTypeCast(TypeCastTree node, P p)
visitTypeCast
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitInstanceOf(InstanceOfTree node, P p)
visitInstanceOf
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitArrayAccess(ArrayAccessTree node, P p)
visitArrayAccess
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitMemberSelect(MemberSelectTree node, P p)
visitMemberSelect
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitMemberReference(MemberReferenceTree node, P p)
visitMemberReference
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitIdentifier(IdentifierTree node, P p)
null
.visitIdentifier
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitLiteral(LiteralTree node, P p)
null
.visitLiteral
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitPrimitiveType(PrimitiveTypeTree node, P p)
null
.visitPrimitiveType
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitArrayType(ArrayTypeTree node, P p)
visitArrayType
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitParameterizedType(ParameterizedTypeTree node, P p)
visitParameterizedType
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitUnionType(UnionTypeTree node, P p)
visitUnionType
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitIntersectionType(IntersectionTypeTree node, P p)
visitIntersectionType
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitTypeParameter(TypeParameterTree node, P p)
visitTypeParameter
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitWildcard(WildcardTree node, P p)
visitWildcard
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitModifiers(ModifiersTree node, P p)
visitModifiers
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitAnnotation(AnnotationTree node, P p)
visitAnnotation
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitAnnotatedType(AnnotatedTypeTree node, P p)
visitAnnotatedType
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitOther(Tree node, P p)
Tree
hierarchy. This implementation returns null
.visitOther
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter valuepublic R visitErroneous(ErroneousTree node, P p)
null
.visitErroneous
in interface TreeVisitor<R,P>
node
- the node being visitedp
- a parameter value
Copyright © 2005, 2016, Oracle and/or its affiliates. All rights reserved.
DRAFT 9-internal+0-2016-02-27-124400.buildd.src