Class TreePathCacherTest
java.lang.Object
org.checkerframework.framework.util.TreePathCacherTest
Unit tests for
TreePathCacher, checked against the JDK reference implementation TreePath.getPath(CompilationUnitTree, Tree).
These exercise the structural cases that the checker test suites do not target directly:
- the
TreePathCacher.getPath(TreePath, Tree)overload finding a target that is not under the given path's leaf (the out-of-subtree case), and - finding a target deep in a class with many top-level members.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidChecks that a tree from a different compilation unit is reported (and cached) as not present.voidChecks thatTreePathCacher.addArtificialPath(com.sun.source.tree.Tree, com.sun.source.util.TreePath)marks the tree as artificial, that the mark survivesTreePathCacher.useUnit(com.sun.source.tree.CompilationUnitTree)for the same unit, and thatTreePathCacher.clear()drops it.voidChecks thatgetPath(CompilationUnitTree, Tree)matches the JDK for every tree, both cold and cached.voidChecks that many lookups under the same leaf, enough forTreePathCacherto index the leaf's subtree, match the JDK for targets under the leaf, outside it, and absent from the compilation unit.voidChecks thatgetPath(TreePath, Tree)returns the correct path for targets under the leaf.voidChecks thatgetPath(TreePath, Tree)finds a target that is NOT under the given path's leaf: the search expands outward to the whole compilation unit.voidChecks that afterTreePathCacher.clear(),TreePathCacher.useUnit(com.sun.source.tree.CompilationUnitTree)for the unit the cache was used for before clears the cache like for a fresh cache, instead of keeping the entries added after the clear.voidChecks thatTreePathCacher.useUnit(com.sun.source.tree.CompilationUnitTree)keeps the cache, including the path of a tree that a scan cannot find (an artificial tree), when called again for the same compilation unit, and clears it for another compilation unit.voidSimulates the checkers of a compound checker, which share one cache and each callTreePathCacher.useUnit(com.sun.source.tree.CompilationUnitTree)when they start a compilation unit: every entry, a registered path, a path found by a scan, and a cached absence, survives the later checkers' calls for the same unit, and none survives the next unit, even when the unit after that is the first one again.
-
Constructor Details
-
TreePathCacherTest
public TreePathCacherTest()
-
-
Method Details
-
firstOverloadMatchesJdk
Checks thatgetPath(CompilationUnitTree, Tree)matches the JDK for every tree, both cold and cached.- Throws:
Exception- if parsing the test source fails
-
secondOverloadFindsOutOfSubtreeTargets
Checks thatgetPath(TreePath, Tree)finds a target that is NOT under the given path's leaf: the search expands outward to the whole compilation unit. A fresh cacher is used for every target so it is found by scanning rather than served from the cache.- Throws:
Exception- if parsing the test source fails
-
secondOverloadFindsInSubtreeTargets
Checks thatgetPath(TreePath, Tree)returns the correct path for targets under the leaf.- Throws:
Exception- if parsing the test source fails
-
absentTreeIsNull
Checks that a tree from a different compilation unit is reported (and cached) as not present.- Throws:
Exception- if parsing the test sources fails
-
useUnitClearsOnlyForANewUnit
Checks thatTreePathCacher.useUnit(com.sun.source.tree.CompilationUnitTree)keeps the cache, including the path of a tree that a scan cannot find (an artificial tree), when called again for the same compilation unit, and clears it for another compilation unit.- Throws:
Exception- if parsing the test sources fails
-
useUnitKeepsEntriesForAllCheckersOfAUnit
Simulates the checkers of a compound checker, which share one cache and each callTreePathCacher.useUnit(com.sun.source.tree.CompilationUnitTree)when they start a compilation unit: every entry, a registered path, a path found by a scan, and a cached absence, survives the later checkers' calls for the same unit, and none survives the next unit, even when the unit after that is the first one again.- Throws:
Exception- if parsing the test sources fails
-
addArtificialPathMarksTheTree
Checks thatTreePathCacher.addArtificialPath(com.sun.source.tree.Tree, com.sun.source.util.TreePath)marks the tree as artificial, that the mark survivesTreePathCacher.useUnit(com.sun.source.tree.CompilationUnitTree)for the same unit, and thatTreePathCacher.clear()drops it.- Throws:
Exception- if parsing the test sources fails
-
useUnitAfterClearBehavesLikeAFreshCache
Checks that afterTreePathCacher.clear(),TreePathCacher.useUnit(com.sun.source.tree.CompilationUnitTree)for the unit the cache was used for before clears the cache like for a fresh cache, instead of keeping the entries added after the clear.- Throws:
Exception- if parsing the test sources fails
-
manyLookupsUnderOneLeafMatchJdk
Checks that many lookups under the same leaf, enough forTreePathCacherto index the leaf's subtree, match the JDK for targets under the leaf, outside it, and absent from the compilation unit. The body declaresInteger a, b;, whose declarators share a type tree.- Throws:
Exception- if parsing the test sources fails
-