Class TreePathCacher

java.lang.Object
com.sun.source.util.TreeScanner<com.sun.source.util.TreePath,com.sun.source.tree.Tree>
org.checkerframework.framework.util.TreePathCacher
All Implemented Interfaces:
com.sun.source.tree.TreeVisitor<com.sun.source.util.TreePath,com.sun.source.tree.Tree>

public class TreePathCacher extends com.sun.source.util.TreeScanner<com.sun.source.util.TreePath,com.sun.source.tree.Tree>
TreePathCacher is a TreeScanner that creates and caches a TreePath for a target Tree.

This class replicates some logic from TreePath.getPath but also adds caching to all intermediate TreePaths that are generated. The intermediate TreePaths are reused when other targets have overlapping paths.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addPath(com.sun.source.tree.Tree target, com.sun.source.util.TreePath path)
    Adds the given key and value to the cache.
    void
     
    @Nullable com.sun.source.util.TreePath
    getPath(com.sun.source.tree.CompilationUnitTree root, com.sun.source.tree.Tree target)
    Return the TreePath for a Tree.
    boolean
    isCached(com.sun.source.tree.Tree target)
    Returns true if the tree is cached.
    com.sun.source.util.TreePath
    scan(com.sun.source.tree.Tree tree, com.sun.source.tree.Tree target)
    Scan a single node.

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

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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TreePathCacher

      public TreePathCacher()
  • Method Details

    • isCached

      public boolean isCached(com.sun.source.tree.Tree target)
      Returns true if the tree is cached.
      Parameters:
      target - the tree to search for
      Returns:
      true if the tree is cached
    • addPath

      public void addPath(com.sun.source.tree.Tree target, com.sun.source.util.TreePath path)
      Adds the given key and value to the cache.
      Parameters:
      target - the tree to add
      path - the path to cache
    • getPath

      public @Nullable com.sun.source.util.TreePath getPath(com.sun.source.tree.CompilationUnitTree root, @FindDistinct com.sun.source.tree.Tree target)
      Return the TreePath for a Tree.
      Parameters:
      root - the compilation unit to search in
      target - the target tree to look for
      Returns:
      the TreePath corresponding to target, or null if target is not found in the compilation root
    • clear

      public void clear()
    • scan

      public com.sun.source.util.TreePath scan(com.sun.source.tree.Tree tree, com.sun.source.tree.Tree target)
      Scan a single node. The current path is updated for the duration of the scan.
      Overrides:
      scan in class com.sun.source.util.TreeScanner<com.sun.source.util.TreePath,com.sun.source.tree.Tree>