public class TreePathCacher extends TreeScanner<TreePath,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 and Description |
---|
TreePathCacher() |
Modifier and Type | Method and Description |
---|---|
void |
addPath(Tree target,
TreePath path)
Adds the given key and value to the cache.
|
void |
clear() |
TreePath |
getPath(CompilationUnitTree root,
Tree target)
Return the TreePath for a Tree.
|
boolean |
isCached(Tree target)
Returns true if the tree is cached.
|
TreePath |
scan(Tree tree,
Tree target)
Scan a single node.
|
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
public boolean isCached(Tree target)
target
- the tree to search forpublic void addPath(Tree target, TreePath path)
target
- the tree to addpath
- the path to cachepublic TreePath getPath(CompilationUnitTree root, @FindDistinct Tree target)
This method uses try/catch and the Result Error for control flow to stop the superclass from scanning other subtrees when target is found.
root
- the compilation unit to search intarget
- the target tree to look forpublic void clear()