Class TreePathCacher

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

public class TreePathCacher extends TreeScanner<TreePath,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 Details

    • TreePathCacher

      public TreePathCacher()
  • Method Details

    • isCached

      public boolean isCached(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(Tree target, 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 TreePath getPath(CompilationUnitTree root, @FindDistinct 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 TreePath scan(Tree tree, Tree target)
      Scan a single node. The current path is updated for the duration of the scan.
      Overrides:
      scan in class TreeScanner<TreePath,Tree>