Class TreePathCacher
- All Implemented Interfaces:
TreeVisitor<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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the given key and value to the cache.void
clear()
getPath
(CompilationUnitTree root, Tree target) Return the TreePath for a Tree.boolean
Returns true if the tree is cached.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
-
Constructor Details
-
TreePathCacher
public TreePathCacher()
-
-
Method Details
-
isCached
Returns true if the tree is cached.- Parameters:
target
- the tree to search for- Returns:
- true if the tree is cached
-
addPath
Adds the given key and value to the cache.- Parameters:
target
- the tree to addpath
- the path to cache
-
getPath
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
Scan a single node. The current path is updated for the duration of the scan.- Overrides:
scan
in classTreeScanner<TreePath,
Tree>
-