APIdia Launch Partner
Top Description Constructors Methods
com.sun.source.util

public Class TreeScanner<R, P>

extends Object
implements TreeVisitor<R, P>
Class Inheritance
All Implemented Interfaces
com.sun.source.tree.TreeVisitor
Known Direct Subclasses
com.sun.tools.javac.parser.ReferenceParser.TypeAnnotationFinder, com.sun.source.util.TreePathScanner
Type Parameters
<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.
Imports
com.sun.source.tree.*

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.

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);
     }
  }

Implementation Specification

The default implementation of the visitXYZ methods will determine a result as follows:

Authors
Peter von der Ahé, Jonathan Gibbons
Since
1.6

Constructor Summary

AccessConstructor and Description
public
TreeScanner()

Constructs a TreeScanner.

Method Summary

Modifier and TypeMethod and Description
public R

Returns:

the result of combining the two parameters
reduce
(R
the first of the values to be combined
r1
,
R
the second of the values to be combined
r2
)

Reduces two results into a combined result.

public R

Returns:

the result value from the visit method
scan
(Tree
the node to be scanned
tree
,
P
a parameter value passed to the visit method
p
)

Scans a single node.

public R

Returns:

the combined return value from the visit methods. The values are combined using the reduce method.
scan
(Iterable<? extends Tree>
the nodes to be scanned
nodes
,
P
a parameter value to be passed to the visit method for each node
p
)

Scans a sequence of nodes.

private R
scanAndReduce(Tree node, P p, R r)

private R
scanAndReduce(Iterable<? extends Tree> nodes, P p, R r)

public R

Returns:

the result of scanning
visitAnnotatedType
(AnnotatedTypeTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitAnnotatedType.

Visits an AnnotatedTypeTree node.

public R

Returns:

the result of scanning
visitAnnotation
(AnnotationTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitAnnotation.

Visits an AnnotatedTree node.

public R

Returns:

the result of scanning
visitAnyPattern
(AnyPatternTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitAnyPattern.

Visits a AnyPatternTree node.

public R

Returns:

the result of scanning
visitArrayAccess
(ArrayAccessTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitArrayAccess.

Visits an ArrayAccessTree node.

public R

Returns:

the result of scanning
visitArrayType
(ArrayTypeTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitArrayType.

Visits an ArrayTypeTree node.

public R

Returns:

the result of scanning
visitAssert
(AssertTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitAssert.

Visits an AssertTree node.

public R

Returns:

the result of scanning
visitAssignment
(AssignmentTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitAssignment.

Visits an AssignmentTree node.

public R

Returns:

the result of scanning
visitBinary
(BinaryTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitBinary.

Visits a BinaryTree node.

public R

Returns:

the result of scanning
visitBindingPattern
(BindingPatternTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitBindingPattern.

Visits a BindingPatternTree node.

public R

Returns:

the result of scanning
visitBlock
(BlockTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitBlock.

Visits a BlockTree node.

public R

Returns:

the result of scanning
visitBreak
(BreakTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitBreak.

Visits a BreakTree node.

public R

Returns:

the result of scanning
visitCase
(CaseTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitCase.

Visits a CaseTree node.

public R

Returns:

the result of scanning
visitCatch
(CatchTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitCatch.

Visits a CatchTree node.

public R

Returns:

the result of scanning
visitClass
(ClassTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitClass.

Visits a ClassTree node.

public R

Returns:

the result of scanning
visitCompilationUnit
(CompilationUnitTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitCompilationUnit.

Visits a CompilationUnitTree node.

public R

Returns:

the result of scanning
visitCompoundAssignment
(CompoundAssignmentTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitCompoundAssignment.

Visits a CompoundAssignmentTree node.

public R

Returns:

the result of scanning
visitConditionalExpression
(ConditionalExpressionTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitConditionalExpression.

Visits a ConditionalExpressionTree node.

public R

Returns:

the result of scanning
visitConstantCaseLabel
(ConstantCaseLabelTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitConstantCaseLabel.

Visits a ConstantCaseLabelTree node.

public R

Returns:

the result of scanning
visitContinue
(ContinueTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitContinue.

Visits a ContinueTree node.

public R

Returns:

the result of scanning
visitDeconstructionPattern
(DeconstructionPatternTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitDeconstructionPattern.

Visits a DeconstructionPatternTree node.

public R

Returns:

the result of scanning
visitDefaultCaseLabel
(DefaultCaseLabelTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitDefaultCaseLabel.

Visits a DefaultCaseLabelTree node.

public R

Returns:

the result of scanning
visitDoWhileLoop
(DoWhileLoopTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitDoWhileLoop.

Visits a DoWhileTree node.

public R

Returns:

the result of scanning
visitEmptyStatement
(EmptyStatementTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitEmptyStatement.

Visits an EmptyStatementTree node.

public R

Returns:

the result of scanning
visitEnhancedForLoop
(EnhancedForLoopTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitEnhancedForLoop.

Visits an EnhancedForLoopTree node.

public R

Returns:

the result of scanning
visitErroneous
(ErroneousTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitErroneous.

Visits an ErroneousTree node.

public R

Returns:

the result of scanning
visitExports
(ExportsTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitExports.

Visits an ExportsTree node.

public R

Returns:

the result of scanning
visitExpressionStatement
(ExpressionStatementTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitExpressionStatement.

Visits an ExpressionStatementTree node.

public R

Returns:

the result of scanning
visitForLoop
(ForLoopTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitForLoop.

Visits a ForLoopTree node.

public R

Returns:

the result of scanning
visitIdentifier
(IdentifierTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitIdentifier.

Visits an IdentifierTree node.

public R

Returns:

the result of scanning
visitIf
(IfTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitIf.

Visits an IfTree node.

public R

Returns:

the result of scanning
visitImport
(ImportTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitImport.

Visits an ImportTree node.

public R

Returns:

the result of scanning
visitInstanceOf
(InstanceOfTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitInstanceOf.

Visits an InstanceOfTree node.

public R

Returns:

the result of scanning
visitIntersectionType
(IntersectionTypeTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitIntersectionType.

Visits an IntersectionTypeTree node.

public R

Returns:

the result of scanning
visitLabeledStatement
(LabeledStatementTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitLabeledStatement.

Visits a LabeledStatementTree node.

public R

Returns:

the result of scanning
visitLambdaExpression
(LambdaExpressionTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitLambdaExpression.

Visits a LambdaExpressionTree node.

public R

Returns:

the result of scanning
visitLiteral
(LiteralTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitLiteral.

Visits a LiteralTree node.

public R

Returns:

the result of scanning
visitMemberReference
(MemberReferenceTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitMemberReference.

Visits a MemberReferenceTree node.

public R

Returns:

the result of scanning
visitMemberSelect
(MemberSelectTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitMemberSelect.

Visits a MemberSelectTree node.

public R

Returns:

the result of scanning
visitMethod
(MethodTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitMethod.

Visits a MethodTree node.

public R

Returns:

the result of scanning
visitMethodInvocation
(MethodInvocationTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitMethodInvocation.

Visits a MethodInvocationTree node.

public R

Returns:

the result of scanning
visitModifiers
(ModifiersTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitModifiers.

Visits a ModifiersTree node.

public R

Returns:

the result of scanning
visitModule
(ModuleTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitModule.

Visits a ModuleTree node.

public R

Returns:

the result of scanning
visitNewArray
(NewArrayTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitNewArray.

Visits a NewArrayTree node.

public R

Returns:

the result of scanning
visitNewClass
(NewClassTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitNewClass.

Visits a NewClassTree node.

public R

Returns:

the result of scanning
visitOpens
(OpensTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitOpens.

Visits an OpensTree node.

public R

Returns:

the result of scanning
visitOther
(Tree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitOther.

Visits an unknown type of Tree node.

public R

Returns:

the result of scanning
visitPackage
(PackageTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitPackage.

Visits a PackageTree node.

public R

Returns:

the result of scanning
visitParameterizedType
(ParameterizedTypeTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitParameterizedType.

Visits a ParameterizedTypeTree node.

public R

Returns:

the result of scanning
visitParenthesized
(ParenthesizedTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitParenthesized.

Visits a ParenthesizedTree node.

public R

Returns:

the result of scanning
visitPatternCaseLabel
(PatternCaseLabelTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitPatternCaseLabel.

Visits a PatternCaseLabelTree node.

public R

Returns:

the result of scanning
visitPrimitiveType
(PrimitiveTypeTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitPrimitiveType.

Visits a PrimitiveTypeTree node.

public R

Returns:

the result of scanning
visitProvides
(ProvidesTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitProvides.

Visits a ProvidesTree node.

public R

Returns:

the result of scanning
visitRequires
(RequiresTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitRequires.

Visits a RequiresTree node.

public R

Returns:

the result of scanning
visitReturn
(ReturnTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitReturn.

Visits a ReturnTree node.

public R

Returns:

the result of scanning
visitSwitch
(SwitchTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitSwitch.

Visits a SwitchTree node.

public R

Returns:

the result of scanning
visitSwitchExpression
(SwitchExpressionTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitSwitchExpression.

Visits a SwitchExpressionTree node.

public R

Returns:

the result of scanning
visitSynchronized
(SynchronizedTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitSynchronized.

Visits a SynchronizedTree node.

public R

Returns:

the result of scanning
visitThrow
(ThrowTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitThrow.

Visits a ThrowTree node.

public R

Returns:

the result of scanning
visitTry
(TryTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitTry.

Visits a TryTree node.

public R

Returns:

the result of scanning
visitTypeCast
(TypeCastTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitTypeCast.

Visits a TypeCastTree node.

public R

Returns:

the result of scanning
visitTypeParameter
(TypeParameterTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitTypeParameter.

Visits a TypeParameterTree node.

public R

Returns:

the result of scanning
visitUnary
(UnaryTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitUnary.

Visits a UnaryTree node.

public R

Returns:

the result of scanning
visitUnionType
(UnionTypeTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitUnionType.

Visits a UnionTypeTree node.

public R

Returns:

the result of scanning
visitUses
(UsesTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitUses.

Visits a UsesTree node.

public R

Returns:

the result of scanning
visitVariable
(VariableTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitVariable.

Visits a VariableTree node.

public R

Returns:

the result of scanning
visitVarType
(VarTypeTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitVarType.

Visits a VarTypeTree node.

public R

Returns:

the result of scanning
visitWhileLoop
(WhileLoopTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitWhileLoop.

Visits a WhileLoopTree node.

public R

Returns:

the result of scanning
visitWildcard
(WildcardTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitWildcard.

Visits a WildcardTypeTree node.

public R

Returns:

the result of scanning
visitYield
(YieldTree node, P p)

Implements com.sun.source.tree.TreeVisitor.visitYield.

Visits a YieldTree node.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait