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 TreePathCacher()
-
Method Summary
All Methods Instance Methods Concrete Methods 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
clear()
@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, visitBlock, visitBreak, visitCase, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitContinue, visitDoWhileLoop, visitEmptyStatement, visitEnhancedForLoop, visitErroneous, visitExports, visitExpressionStatement, visitForLoop, visitIdentifier, visitIf, visitImport, visitInstanceOf, visitIntersectionType, visitLabeledStatement, visitLambdaExpression, visitLiteral, visitMemberReference, visitMemberSelect, visitMethod, visitMethodInvocation, visitModifiers, visitModule, visitNewArray, visitNewClass, visitOpens, visitOther, visitPackage, visitParameterizedType, visitParenthesized, visitPrimitiveType, visitProvides, visitRequires, visitReturn, visitSwitch, visitSynchronized, visitThrow, visitTry, visitTypeCast, visitTypeParameter, visitUnary, visitUnionType, visitUses, visitVariable, visitWhileLoop, visitWildcard
-
-
-
-
Method Detail
-
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 addpath
- 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 intarget
- 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 classcom.sun.source.util.TreeScanner<com.sun.source.util.TreePath,com.sun.source.tree.Tree>
-
-