Class TreeFinder
java.lang.Object
com.sun.source.util.TreeScanner<Void,List<Insertion>>
org.checkerframework.afu.annotator.find.TreeFinder
- All Implemented Interfaces:
TreeVisitor<Void,
List<Insertion>>
A
TreeScanner
that is able to locate program elements in an AST based on
Criteria
. getInsertionsByPosition(JCTree.JCCompilationUnit,List)
scans a tree and
creates (in field insertions
) a mapping of source positions (as character offsets) to
insertion text.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DebugWriter
Debugging logger.static final DebugWriter
Warning logger. -
Constructor Summary
ConstructorsConstructorDescriptionTreeFinder
(com.sun.tools.javac.tree.JCTree.JCCompilationUnit tree) Creates aTreeFinder
from a source tree. -
Method Summary
Modifier and TypeMethodDescriptiongetInsertionsByPosition
(com.sun.tools.javac.tree.JCTree.JCCompilationUnit node, List<Insertion> p) Scans the given tree with the given insertion list and returns the mapping from source position to insertion text.An alternative to TreePath.getPath(CompilationUnitTree,Tree) that caches its results.getPaths()
getPositions
(com.sun.tools.javac.tree.JCTree.JCCompilationUnit node, Insertions insertions) Scans the given tree with the givenInsertions
and returns the mapping from source position to insertion text.static TreePath
If this code location is not an array type, return null.static String
leafToStringTruncated
(TreePath path, int length) Returns a string representation of the leaf of the given path, usingtoStringTruncated(com.sun.source.tree.Tree, int)
.static void
Reports an error inserting an insertion toSystem.err
.Scans this tree, using the list of insertions to generate the source position to insertion text mapping.static String
Returns a printed representation of a TreePath.static String
toStringOneLine
(Tree tree) Returns toString(), but without line separators.static String
toStringTruncated
(Tree tree, int length) Returns eithertoStringOneLine(com.sun.source.tree.Tree)
if it is no more thanlength
characters, ortoStringOneLine(com.sun.source.tree.Tree)
quoted and truncated.Methods inherited from class com.sun.source.util.TreeScanner
reduce, scan, visitAnnotatedType, visitAnnotation, visitAnyPattern, visitArrayAccess, visitArrayType, visitAssert, visitAssignment, visitBinary, visitBindingPattern, visitBlock, visitBreak, visitCase, visitCatch, visitClass, visitCompilationUnit, visitCompoundAssignment, visitConditionalExpression, visitConstantCaseLabel, visitContinue, visitDeconstructionPattern, visitDefaultCaseLabel, 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, visitPatternCaseLabel, visitPrimitiveType, visitProvides, visitRequires, visitReturn, visitStringTemplate, visitSwitch, visitSwitchExpression, visitSynchronized, visitThrow, visitTry, visitTypeCast, visitTypeParameter, visitUnary, visitUnionType, visitUses, visitVariable, visitWhileLoop, visitWildcard, visitYield
-
Field Details
-
dbug
Debugging logger. -
warn
Warning logger.
-
-
Constructor Details
-
TreeFinder
public TreeFinder(com.sun.tools.javac.tree.JCTree.JCCompilationUnit tree) Creates aTreeFinder
from a source tree.- Parameters:
tree
- the source tree to search
-
-
Method Details
-
largestContainingArray
If this code location is not an array type, return null. Otherwise, starting at an array type, walk up the AST as long as still an array, and stop at the largest containing array (with nothing but arrays in between).- Parameters:
p
- a tree path- Returns:
- a path to the largest containing array, or null if none
-
getPath
An alternative to TreePath.getPath(CompilationUnitTree,Tree) that caches its results. -
scan
Scans this tree, using the list of insertions to generate the source position to insertion text mapping. Insertions are removed from the list when positions are found for them. Thus, they are inserted at the first location (the leftmost highest in the tree) that they match.When a match is found, this routine removes the insertion from p and adds it to the insertions map as a value, with a key that is a pair. On return, p contains only the insertions for which no match was found.
- Overrides:
scan
in classTreeScanner<Void,
List<Insertion>> - Parameters:
node
- AST node being considered for annotation insertionsp
- list of insertions not yet placed
-
reportInsertionError
Reports an error inserting an insertion toSystem.err
.- Parameters:
i
- the insertion that caused the errore
- the error. If there's a message it will be printed.
-
getPaths
-
getInsertionsByPosition
public com.google.common.collect.SetMultimap<org.plumelib.util.IPair<Integer,ASTPath>, getInsertionsByPositionInsertion> (com.sun.tools.javac.tree.JCTree.JCCompilationUnit node, List<Insertion> p) Scans the given tree with the given insertion list and returns the mapping from source position to insertion text. The positions are sorted in decreasing order of index, so that inserting one doesn't throw off the index for a subsequent one.N.B.: This method calls
scan()
internally.- Parameters:
node
- the tree to scanp
- the list of insertion criteria- Returns:
- the source position to insertion text mapping
-
getPositions
public com.google.common.collect.SetMultimap<org.plumelib.util.IPair<Integer,ASTPath>, getPositionsInsertion> (com.sun.tools.javac.tree.JCTree.JCCompilationUnit node, Insertions insertions) Scans the given tree with the givenInsertions
and returns the mapping from source position to insertion text.N.B.: This method calls
scan()
internally.- Parameters:
node
- the tree to scaninsertions
- the insertion criteria- Returns:
- the source position to insertion text mapping
-
toString
Returns a printed representation of a TreePath.- Parameters:
path
- a TreePath- Returns:
- a printed representation of the given TreePath
-
leafToStringTruncated
Returns a string representation of the leaf of the given path, usingtoStringTruncated(com.sun.source.tree.Tree, int)
.- Parameters:
path
- a pathlength
- the maximum length for the result; must be at least 6- Returns:
- a one-line string representation of the leaf of the given path that is no longer than
length
characters long
-
toStringOneLine
Returns toString(), but without line separators.- Parameters:
tree
- a tree- Returns:
- a one-line string representation of the tree
-
toStringTruncated
Returns eithertoStringOneLine(com.sun.source.tree.Tree)
if it is no more thanlength
characters, ortoStringOneLine(com.sun.source.tree.Tree)
quoted and truncated.- Parameters:
tree
- a treelength
- the maximum length for the result; must be at least 6- Returns:
- a one-line string representation of the tree that is no longer than
length
characters long
-