java.lang.Object
com.sun.source.util.TreeScanner<R,P>
- Type Parameters:
- R- the return type of this visitor's methods. Use- Voidfor visitors that do not need to return results.
- P- the type of the additional parameter to this visitor's methods. Use- Voidfor visitors that do not need an additional parameter.
- All Implemented Interfaces:
- TreeVisitor<R,P>
- Direct Known Subclasses:
- TreePathScanner
public class TreeScanner<R,P> extends Object implements TreeVisitor<R,P>
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 scanon 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 scaneach child in turn, and then combining the result of each scan after the first with the cumulative result so far, as determined by thereduce(R, R)method. Each child may be either a simple node of a list of nodes. The default behavior of thereducemethod 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);
      }
   }
 - Since:
- 1.6
- 
Constructor SummaryConstructors Constructor Description TreeScanner()
- 
Method SummaryModifier and Type Method Description Rreduce(R r1, R r2)Reduces two results into a combined result.Rscan(Tree tree, P p)Scans a single node.Rscan(Iterable<? extends Tree> nodes, P p)Scans a sequence of nodes.RvisitAnnotatedType(AnnotatedTypeTree node, P p)Visits an AnnotatedTypeTree node.RvisitAnnotation(AnnotationTree node, P p)Visits an AnnotatedTree node.RvisitArrayAccess(ArrayAccessTree node, P p)Visits an ArrayAccessTree node.RvisitArrayType(ArrayTypeTree node, P p)Visits an ArrayTypeTree node.RvisitAssert(AssertTree node, P p)Visits an AssertTree node.RvisitAssignment(AssignmentTree node, P p)Visits an AssignmentTree node.RvisitBinary(BinaryTree node, P p)Visits a BinaryTree node.RvisitBindingPattern(BindingPatternTree node, P p)Associated with pattern matching for instanceof, a preview feature of the Java language.
 Visits an BindingPattern node.RvisitBlock(BlockTree node, P p)Visits a BlockTree node.RvisitBreak(BreakTree node, P p)Visits a BreakTree node.RvisitCase(CaseTree node, P p)Visits a CaseTree node.RvisitCatch(CatchTree node, P p)Visits a CatchTree node.RvisitClass(ClassTree node, P p)Visits a ClassTree node.RvisitCompilationUnit(CompilationUnitTree node, P p)Visits a CompilationUnitTree node.RvisitCompoundAssignment(CompoundAssignmentTree node, P p)Visits a CompoundAssignmentTree node.RvisitConditionalExpression(ConditionalExpressionTree node, P p)Visits a ConditionalExpressionTree node.RvisitContinue(ContinueTree node, P p)Visits a ContinueTree node.RvisitDoWhileLoop(DoWhileLoopTree node, P p)Visits a DoWhileTree node.RvisitEmptyStatement(EmptyStatementTree node, P p)Visits an EmptyStatementTree node.RvisitEnhancedForLoop(EnhancedForLoopTree node, P p)Visits an EnhancedForLoopTree node.RvisitErroneous(ErroneousTree node, P p)Visits an ErroneousTree node.RvisitExpressionStatement(ExpressionStatementTree node, P p)Visits an ExpressionStatementTree node.RvisitForLoop(ForLoopTree node, P p)Visits a ForLoopTree node.RvisitIdentifier(IdentifierTree node, P p)Visits an IdentifierTree node.RvisitIf(IfTree node, P p)Visits an IfTree node.RvisitImport(ImportTree node, P p)Visits an ImportTree node.RvisitInstanceOf(InstanceOfTree node, P p)Visits an InstanceOfTree node.RvisitIntersectionType(IntersectionTypeTree node, P p)Visits an IntersectionTypeTree node.RvisitLabeledStatement(LabeledStatementTree node, P p)Visits a LabeledStatementTree node.RvisitLambdaExpression(LambdaExpressionTree node, P p)Visits a LambdaExpressionTree node.RvisitLiteral(LiteralTree node, P p)Visits a LiteralTree node.RvisitMemberReference(MemberReferenceTree node, P p)Visits a MemberReferenceTree node.RvisitMemberSelect(MemberSelectTree node, P p)Visits a MemberSelectTree node.RvisitMethod(MethodTree node, P p)Visits a MethodTree node.RvisitMethodInvocation(MethodInvocationTree node, P p)Visits a MethodInvocationTree node.RvisitModifiers(ModifiersTree node, P p)Visits a ModifiersTree node.RvisitNewArray(NewArrayTree node, P p)Visits a NewArrayTree node.RvisitNewClass(NewClassTree node, P p)Visits a NewClassTree node.RvisitOther(Tree node, P p)Visits an unknown type of Tree node.RvisitPackage(PackageTree node, P p)Visits a PackageTree node.RvisitParameterizedType(ParameterizedTypeTree node, P p)Visits a ParameterizedTypeTree node.RvisitParenthesized(ParenthesizedTree node, P p)Visits a ParenthesizedTree node.RvisitPrimitiveType(PrimitiveTypeTree node, P p)Visits a PrimitiveTypeTree node.RvisitReturn(ReturnTree node, P p)Visits a ReturnTree node.RvisitSwitch(SwitchTree node, P p)Visits a SwitchTree node.RvisitSwitchExpression(SwitchExpressionTree node, P p)Visits a SwitchExpressionTree node.RvisitSynchronized(SynchronizedTree node, P p)Visits a SynchronizedTree node.RvisitThrow(ThrowTree node, P p)Visits a ThrowTree node.RvisitTry(TryTree node, P p)Visits a TryTree node.RvisitTypeCast(TypeCastTree node, P p)Visits a TypeCastTree node.RvisitTypeParameter(TypeParameterTree node, P p)Visits a TypeParameterTree node.RvisitUnary(UnaryTree node, P p)Visits a UnaryTree node.RvisitUnionType(UnionTypeTree node, P p)Visits a UnionTypeTree node.RvisitVariable(VariableTree node, P p)Visits a VariableTree node.RvisitWhileLoop(WhileLoopTree node, P p)Visits a WhileLoopTree node.RvisitWildcard(WildcardTree node, P p)Visits a WildcardTypeTree node.RvisitYield(YieldTree node, P p)Visits a YieldTree node.Methods declared in class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods declared in interface com.sun.source.tree.TreeVisitorvisitExports, visitModule, visitOpens, visitProvides, visitRequires, visitUses
- 
Constructor Details- 
TreeScannerpublic TreeScanner()
 
- 
- 
Method Details- 
scanScans a single node.- Parameters:
- tree- the node to be scanned
- p- a parameter value passed to the visit method
- Returns:
- the result value from the visit method
 
- 
scanScans a sequence of nodes.- Parameters:
- nodes- the nodes to be scanned
- p- a parameter value to be passed to the visit method for each node
- Returns:
- the combined return value from the visit methods.
      The values are combined using the reducemethod.
 
- 
reduceReduces 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.- Parameters:
- r1- the first of the values to be combined
- r2- the second of the values to be combined
- Returns:
- the result of combining the two parameters
 
- 
visitCompilationUnitVisits a CompilationUnitTree node. This implementation scans the children in left to right order.- Specified by:
- visitCompilationUnitin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitPackageVisits a PackageTree node. This implementation scans the children in left to right order.- Specified by:
- visitPackagein interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitImportVisits an ImportTree node. This implementation scans the children in left to right order.- Specified by:
- visitImportin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitClassVisits a ClassTree node. This implementation scans the children in left to right order.- Specified by:
- visitClassin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitMethodVisits a MethodTree node. This implementation scans the children in left to right order.- Specified by:
- visitMethodin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitVariableVisits a VariableTree node. This implementation scans the children in left to right order.- Specified by:
- visitVariablein interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitEmptyStatementVisits an EmptyStatementTree node. This implementation returnsnull.- Specified by:
- visitEmptyStatementin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitBlockVisits a BlockTree node. This implementation scans the children in left to right order.- Specified by:
- visitBlockin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitDoWhileLoopVisits a DoWhileTree node. This implementation scans the children in left to right order.- Specified by:
- visitDoWhileLoopin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitWhileLoopVisits a WhileLoopTree node. This implementation scans the children in left to right order.- Specified by:
- visitWhileLoopin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitForLoopVisits a ForLoopTree node. This implementation scans the children in left to right order.- Specified by:
- visitForLoopin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitEnhancedForLoopVisits an EnhancedForLoopTree node. This implementation scans the children in left to right order.- Specified by:
- visitEnhancedForLoopin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitLabeledStatementVisits a LabeledStatementTree node. This implementation scans the children in left to right order.- Specified by:
- visitLabeledStatementin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitSwitchVisits a SwitchTree node. This implementation scans the children in left to right order.- Specified by:
- visitSwitchin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitSwitchExpressionVisits a SwitchExpressionTree node. This implementation scans the children in left to right order.- Specified by:
- visitSwitchExpressionin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitCaseVisits a CaseTree node. This implementation scans the children in left to right order.- Specified by:
- visitCasein interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitSynchronizedVisits a SynchronizedTree node. This implementation scans the children in left to right order.- Specified by:
- visitSynchronizedin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitTryVisits a TryTree node. This implementation scans the children in left to right order.- Specified by:
- visitTryin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitCatchVisits a CatchTree node. This implementation scans the children in left to right order.- Specified by:
- visitCatchin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitConditionalExpressionVisits a ConditionalExpressionTree node. This implementation scans the children in left to right order.- Specified by:
- visitConditionalExpressionin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitIfVisits an IfTree node. This implementation scans the children in left to right order.- Specified by:
- visitIfin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitExpressionStatementVisits an ExpressionStatementTree node. This implementation scans the children in left to right order.- Specified by:
- visitExpressionStatementin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitBreakVisits a BreakTree node. This implementation returnsnull.- Specified by:
- visitBreakin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitContinueVisits a ContinueTree node. This implementation returnsnull.- Specified by:
- visitContinuein interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitReturnVisits a ReturnTree node. This implementation scans the children in left to right order.- Specified by:
- visitReturnin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitThrowVisits a ThrowTree node. This implementation scans the children in left to right order.- Specified by:
- visitThrowin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitAssertVisits an AssertTree node. This implementation scans the children in left to right order.- Specified by:
- visitAssertin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitMethodInvocationVisits a MethodInvocationTree node. This implementation scans the children in left to right order.- Specified by:
- visitMethodInvocationin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitNewClassVisits a NewClassTree node. This implementation scans the children in left to right order.- Specified by:
- visitNewClassin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitNewArrayVisits a NewArrayTree node. This implementation scans the children in left to right order.- Specified by:
- visitNewArrayin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitLambdaExpressionVisits a LambdaExpressionTree node. This implementation scans the children in left to right order.- Specified by:
- visitLambdaExpressionin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitParenthesizedVisits a ParenthesizedTree node. This implementation scans the children in left to right order.- Specified by:
- visitParenthesizedin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitAssignmentVisits an AssignmentTree node. This implementation scans the children in left to right order.- Specified by:
- visitAssignmentin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitCompoundAssignmentVisits a CompoundAssignmentTree node. This implementation scans the children in left to right order.- Specified by:
- visitCompoundAssignmentin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitUnaryVisits a UnaryTree node. This implementation scans the children in left to right order.- Specified by:
- visitUnaryin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitBinaryVisits a BinaryTree node. This implementation scans the children in left to right order.- Specified by:
- visitBinaryin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitTypeCastVisits a TypeCastTree node. This implementation scans the children in left to right order.- Specified by:
- visitTypeCastin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitInstanceOfVisits an InstanceOfTree node. This implementation scans the children in left to right order.- Specified by:
- visitInstanceOfin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitBindingPatternThis method is associated with pattern matching for instanceof, a preview feature of the Java language. Preview features may be removed in a future release, or upgraded to permanent features of the Java language.
 Visits an BindingPattern node. This implementation scans the children in left to right order.- Specified by:
- visitBindingPatternin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
- Since:
- 14
 
- 
visitArrayAccessVisits an ArrayAccessTree node. This implementation scans the children in left to right order.- Specified by:
- visitArrayAccessin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitMemberSelectVisits a MemberSelectTree node. This implementation scans the children in left to right order.- Specified by:
- visitMemberSelectin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitMemberReferenceVisits a MemberReferenceTree node. This implementation scans the children in left to right order.- Specified by:
- visitMemberReferencein interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitIdentifierVisits an IdentifierTree node. This implementation returnsnull.- Specified by:
- visitIdentifierin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitLiteralVisits a LiteralTree node. This implementation returnsnull.- Specified by:
- visitLiteralin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitPrimitiveTypeVisits a PrimitiveTypeTree node. This implementation returnsnull.- Specified by:
- visitPrimitiveTypein interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitArrayTypeVisits an ArrayTypeTree node. This implementation scans the children in left to right order.- Specified by:
- visitArrayTypein interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitParameterizedTypeVisits a ParameterizedTypeTree node. This implementation scans the children in left to right order.- Specified by:
- visitParameterizedTypein interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitUnionTypeVisits a UnionTypeTree node. This implementation scans the children in left to right order.- Specified by:
- visitUnionTypein interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitIntersectionTypeVisits an IntersectionTypeTree node. This implementation scans the children in left to right order.- Specified by:
- visitIntersectionTypein interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitTypeParameterVisits a TypeParameterTree node. This implementation scans the children in left to right order.- Specified by:
- visitTypeParameterin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitWildcardVisits a WildcardTypeTree node. This implementation scans the children in left to right order.- Specified by:
- visitWildcardin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitModifiersVisits a ModifiersTree node. This implementation scans the children in left to right order.- Specified by:
- visitModifiersin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitAnnotationVisits an AnnotatedTree node. This implementation scans the children in left to right order.- Specified by:
- visitAnnotationin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitAnnotatedTypeVisits an AnnotatedTypeTree node. This implementation scans the children in left to right order.- Specified by:
- visitAnnotatedTypein interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitOtherVisits an unknown type of Tree node. This can occur if the language evolves and new kinds of nodes are added to theTreehierarchy. This implementation returnsnull.- Specified by:
- visitOtherin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitErroneousVisits an ErroneousTree node. This implementation returnsnull.- Specified by:
- visitErroneousin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
- 
visitYieldVisits a YieldTree node. This implementation returnsnull.- Specified by:
- visitYieldin interface- TreeVisitor<R,P>
- Parameters:
- node- the node being visited
- p- a parameter value
- Returns:
- the result of scanning
 
 
-