| java.lang.Object com.sun.source.util.TreeScanner
TreeScanner | public class TreeScanner implements TreeVisitor<R, P>(Code) | | A TreeVisitor that visits all the child tree nodes.
To visit nodes of a particular type, just override the
corresponding visitXYZ method.
Inside your method, call super.visitXYZ to visit descendant
nodes.
The default implementation of the visitXYZ methods will determine
a result as follows:
- If the node being visited has no children, the result will be null.
- If the node being visited has one child, the result will be the
result of calling
scan on that child. The child may be a simple node
or itself a list of nodes.
- If the node being visited has more than one child, the result will
be determined by calling
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
TreeScanner.reduce 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 {
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);
}
}
author: Peter von der Ahé author: Jonathan Gibbons since: 1.6 |
Method Summary | |
public R | reduce(R r1, R r2) Reduces two results into a combined result. | public R | scan(Tree node, P p) Scan a single node. | public R | scan(Iterable<? extends Tree> nodes, P p) Scan a list of nodes. | public R | visitAnnotation(AnnotationTree node, P p) | public R | visitArrayAccess(ArrayAccessTree node, P p) | public R | visitArrayType(ArrayTypeTree node, P p) | public R | visitAssert(AssertTree node, P p) | public R | visitAssignment(AssignmentTree node, P p) | public R | visitBinary(BinaryTree node, P p) | public R | visitBlock(BlockTree node, P p) | public R | visitBreak(BreakTree node, P p) | public R | visitCase(CaseTree node, P p) | public R | visitCatch(CatchTree node, P p) | public R | visitClass(ClassTree node, P p) | public R | visitCompilationUnit(CompilationUnitTree node, P p) | public R | visitCompoundAssignment(CompoundAssignmentTree node, P p) | public R | visitConditionalExpression(ConditionalExpressionTree node, P p) | public R | visitContinue(ContinueTree node, P p) | public R | visitDoWhileLoop(DoWhileLoopTree node, P p) | public R | visitEmptyStatement(EmptyStatementTree node, P p) | public R | visitEnhancedForLoop(EnhancedForLoopTree node, P p) | public R | visitErroneous(ErroneousTree node, P p) | public R | visitExpressionStatement(ExpressionStatementTree node, P p) | public R | visitForLoop(ForLoopTree node, P p) | public R | visitIdentifier(IdentifierTree node, P p) | public R | visitIf(IfTree node, P p) | public R | visitImport(ImportTree node, P p) | public R | visitInstanceOf(InstanceOfTree node, P p) | public R | visitLabeledStatement(LabeledStatementTree node, P p) | public R | visitLiteral(LiteralTree node, P p) | public R | visitMemberSelect(MemberSelectTree node, P p) | public R | visitMethod(MethodTree node, P p) | public R | visitMethodInvocation(MethodInvocationTree node, P p) | public R | visitModifiers(ModifiersTree node, P p) | public R | visitNewArray(NewArrayTree node, P p) | public R | visitNewClass(NewClassTree node, P p) | public R | visitOther(Tree node, P p) | public R | visitParameterizedType(ParameterizedTypeTree node, P p) | public R | visitParenthesized(ParenthesizedTree node, P p) | public R | visitPrimitiveType(PrimitiveTypeTree node, P p) | public R | visitReturn(ReturnTree node, P p) | public R | visitSwitch(SwitchTree node, P p) | public R | visitSynchronized(SynchronizedTree node, P p) | public R | visitThrow(ThrowTree node, P p) | public R | visitTry(TryTree node, P p) | public R | visitTypeCast(TypeCastTree node, P p) | public R | visitTypeParameter(TypeParameterTree node, P p) | public R | visitUnary(UnaryTree node, P p) | public R | visitVariable(VariableTree node, P p) | public R | visitWhileLoop(WhileLoopTree node, P p) | public R | visitWildcard(WildcardTree node, P p) |
reduce | public R reduce(R r1, R r2)(Code) | | Reduces two results into a combined result.
The default implementation is to return the first parameter.
The general contract of the method is that it may take any action whatsoever.
|
scan | public R scan(Tree node, P p)(Code) | | Scan a single node.
|
visitOther | public R visitOther(Tree node, P p)(Code) | | |
|
|