@Exported public class TreeScanner<R,P> extends Object implements TreeVisitor<R,P>
The default implementation of the visitXYZ methods will determine a result as follows:
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() |
public R reduce(R r1, R r2)
public R visitCompilationUnit(CompilationUnitTree node, P p)
visitCompilationUnit
in interface TreeVisitor<R,P>
public R visitImport(ImportTree node, P p)
visitImport
in interface TreeVisitor<R,P>
public R visitClass(ClassTree node, P p)
visitClass
in interface TreeVisitor<R,P>
public R visitMethod(MethodTree node, P p)
visitMethod
in interface TreeVisitor<R,P>
public R visitVariable(VariableTree node, P p)
visitVariable
in interface TreeVisitor<R,P>
public R visitEmptyStatement(EmptyStatementTree node, P p)
visitEmptyStatement
in interface TreeVisitor<R,P>
public R visitBlock(BlockTree node, P p)
visitBlock
in interface TreeVisitor<R,P>
public R visitDoWhileLoop(DoWhileLoopTree node, P p)
visitDoWhileLoop
in interface TreeVisitor<R,P>
public R visitWhileLoop(WhileLoopTree node, P p)
visitWhileLoop
in interface TreeVisitor<R,P>
public R visitForLoop(ForLoopTree node, P p)
visitForLoop
in interface TreeVisitor<R,P>
public R visitEnhancedForLoop(EnhancedForLoopTree node, P p)
visitEnhancedForLoop
in interface TreeVisitor<R,P>
public R visitLabeledStatement(LabeledStatementTree node, P p)
visitLabeledStatement
in interface TreeVisitor<R,P>
public R visitSwitch(SwitchTree node, P p)
visitSwitch
in interface TreeVisitor<R,P>
public R visitCase(CaseTree node, P p)
visitCase
in interface TreeVisitor<R,P>
public R visitSynchronized(SynchronizedTree node, P p)
visitSynchronized
in interface TreeVisitor<R,P>
public R visitCatch(CatchTree node, P p)
visitCatch
in interface TreeVisitor<R,P>
public R visitConditionalExpression(ConditionalExpressionTree node, P p)
visitConditionalExpression
in interface TreeVisitor<R,P>
public R visitExpressionStatement(ExpressionStatementTree node, P p)
visitExpressionStatement
in interface TreeVisitor<R,P>
public R visitBreak(BreakTree node, P p)
visitBreak
in interface TreeVisitor<R,P>
public R visitContinue(ContinueTree node, P p)
visitContinue
in interface TreeVisitor<R,P>
public R visitReturn(ReturnTree node, P p)
visitReturn
in interface TreeVisitor<R,P>
public R visitThrow(ThrowTree node, P p)
visitThrow
in interface TreeVisitor<R,P>
public R visitAssert(AssertTree node, P p)
visitAssert
in interface TreeVisitor<R,P>
public R visitMethodInvocation(MethodInvocationTree node, P p)
visitMethodInvocation
in interface TreeVisitor<R,P>
public R visitNewClass(NewClassTree node, P p)
visitNewClass
in interface TreeVisitor<R,P>
public R visitNewArray(NewArrayTree node, P p)
visitNewArray
in interface TreeVisitor<R,P>
public R visitLambdaExpression(LambdaExpressionTree node, P p)
visitLambdaExpression
in interface TreeVisitor<R,P>
public R visitParenthesized(ParenthesizedTree node, P p)
visitParenthesized
in interface TreeVisitor<R,P>
public R visitAssignment(AssignmentTree node, P p)
visitAssignment
in interface TreeVisitor<R,P>
public R visitCompoundAssignment(CompoundAssignmentTree node, P p)
visitCompoundAssignment
in interface TreeVisitor<R,P>
public R visitUnary(UnaryTree node, P p)
visitUnary
in interface TreeVisitor<R,P>
public R visitBinary(BinaryTree node, P p)
visitBinary
in interface TreeVisitor<R,P>
public R visitTypeCast(TypeCastTree node, P p)
visitTypeCast
in interface TreeVisitor<R,P>
public R visitInstanceOf(InstanceOfTree node, P p)
visitInstanceOf
in interface TreeVisitor<R,P>
public R visitArrayAccess(ArrayAccessTree node, P p)
visitArrayAccess
in interface TreeVisitor<R,P>
public R visitMemberSelect(MemberSelectTree node, P p)
visitMemberSelect
in interface TreeVisitor<R,P>
public R visitMemberReference(MemberReferenceTree node, P p)
visitMemberReference
in interface TreeVisitor<R,P>
public R visitIdentifier(IdentifierTree node, P p)
visitIdentifier
in interface TreeVisitor<R,P>
public R visitLiteral(LiteralTree node, P p)
visitLiteral
in interface TreeVisitor<R,P>
public R visitPrimitiveType(PrimitiveTypeTree node, P p)
visitPrimitiveType
in interface TreeVisitor<R,P>
public R visitArrayType(ArrayTypeTree node, P p)
visitArrayType
in interface TreeVisitor<R,P>
public R visitParameterizedType(ParameterizedTypeTree node, P p)
visitParameterizedType
in interface TreeVisitor<R,P>
public R visitUnionType(UnionTypeTree node, P p)
visitUnionType
in interface TreeVisitor<R,P>
public R visitIntersectionType(IntersectionTypeTree node, P p)
visitIntersectionType
in interface TreeVisitor<R,P>
public R visitTypeParameter(TypeParameterTree node, P p)
visitTypeParameter
in interface TreeVisitor<R,P>
public R visitWildcard(WildcardTree node, P p)
visitWildcard
in interface TreeVisitor<R,P>
public R visitModifiers(ModifiersTree node, P p)
visitModifiers
in interface TreeVisitor<R,P>
public R visitAnnotation(AnnotationTree node, P p)
visitAnnotation
in interface TreeVisitor<R,P>
public R visitAnnotatedType(AnnotatedTypeTree node, P p)
visitAnnotatedType
in interface TreeVisitor<R,P>
public R visitOther(Tree node, P p)
visitOther
in interface TreeVisitor<R,P>
public R visitErroneous(ErroneousTree node, P p)
visitErroneous
in interface TreeVisitor<R,P>
Copyright © 2005, 2023, Oracle and/or its affiliates. All rights reserved.