TreePathScanner (Compiler Tree API )
Keywords: com.sun.source.util.TreePathScanner class
Date: 2026-04-22

com.sun.source.util

## Class TreePathScanner<R,P>

- java.lang.Object
- - com.sun.source.util.TreeScanner<R,P>
  - - com.sun.source.util.TreePathScanner<R,P>

- All Implemented Interfaces:
    TreeVisitor<R,P>

      @Exported
      public class TreePathScanner<R,P>
      extends TreeScanner<R,P>

  A TreeVisitor that visits all the child tree nodes, and provides support for maintaining a path for the parent nodes. To visit nodes of a particular type, just override the corresponding visitorXYZ method. Inside your method, call super.visitXYZ to visit descendant nodes.
  Since:
    1.6

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `TreePathScanner()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `TreePath` | `getCurrentPath()` Get the current path for the node, as built up by the currently active set of scan calls.
    `R` | `scan(Tree tree, P p)` Scan a single node.
    `R` | `scan(TreePath path, P p)` Scan a tree from a position identified by a TreePath.

    - ### Methods inherited from class com.sun.source.util.TreeScanner

      `reduce, scan, visitAnnotatedType, visitAnnotation, visitArrayAccess, visitArrayType, visitAssert, visitAssignment, visitBinary, visitBlock, visitBreak, visitCase, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitEnhancedForLoop, visitErroneous, visitExpressionStatement, visitForLoop, visitIdentifier, visitIf, visitImport, visitInstanceOf, visitIntersectionType, visitLabeledStatement, visitLambdaExpression, visitLiteral, visitMemberReference, visitMemberSelect, visitMethod, visitMethodInvocation, visitModifiers, visitNewArray, visitNewClass, visitOther, visitParameterizedType, visitParenthesized, visitPrimitiveType, visitReturn, visitSwitch, visitSynchronized, visitThrow, visitTry, visitTypeCast, visitTypeParameter, visitUnary, visitUnionType, visitVariable, visitWhileLoop, visitWildcard`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### TreePathScanner

          public TreePathScanner()

  - ### Method Detail

    - #### scan

          public R scan(TreePath path,
                        P p)

      Scan a tree from a position identified by a TreePath.

    - #### scan

          public R scan(Tree tree,
                        P p)

      Scan a single node. The current path is updated for the duration of the scan.
      Overrides:
        `scan` in class `TreeScanner<R,P>`

    - #### getCurrentPath

          public TreePath getCurrentPath()

      Get the current path for the node, as built up by the currently active set of scan calls.

Copyright © 2005, 2026, Oracle and/or its affiliates. All rights reserved.