public class TreePathCacher
extends com.sun.source.util.TreeScanner<com.sun.source.util.TreePath,com.sun.source.tree.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(com.sun.source.tree.Tree target,
com.sun.source.util.TreePath path) |
void |
clear() |
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) |
com.sun.source.util.TreePath |
scan(com.sun.source.tree.Tree tree,
com.sun.source.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, visitWildcardpublic boolean isCached(com.sun.source.tree.Tree target)
target - the tree to search forpublic void addPath(com.sun.source.tree.Tree target,
com.sun.source.util.TreePath path)
target - the tree to addpath - the path to cachepublic com.sun.source.util.TreePath getPath(com.sun.source.tree.CompilationUnitTree root,
com.sun.source.tree.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()
public com.sun.source.util.TreePath scan(com.sun.source.tree.Tree tree,
com.sun.source.tree.Tree target)
scan in class com.sun.source.util.TreeScanner<com.sun.source.util.TreePath,com.sun.source.tree.Tree>