Class TreePathCacherTest

java.lang.Object
org.checkerframework.framework.util.TreePathCacherTest

public class TreePathCacherTest extends Object
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.
A previous "optimization" that narrowed that overload to scan only the leaf's subtree passed NullnessTest but produced wrong results here; this test guards against that regression.
  • Constructor Details

    • TreePathCacherTest

      public TreePathCacherTest()
  • Method Details

    • firstOverloadMatchesJdk

      public void firstOverloadMatchesJdk() throws Exception
      Checks that getPath(CompilationUnitTree, Tree) matches the JDK for every tree, both cold and cached.
      Throws:
      Exception - if parsing the test source fails
    • secondOverloadFindsOutOfSubtreeTargets

      public void secondOverloadFindsOutOfSubtreeTargets() throws Exception
      Checks that getPath(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

      public void secondOverloadFindsInSubtreeTargets() throws Exception
      Checks that getPath(TreePath, Tree) returns the correct path for targets under the leaf.
      Throws:
      Exception - if parsing the test source fails
    • absentTreeIsNull

      public void absentTreeIsNull() throws Exception
      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

      public void useUnitClearsOnlyForANewUnit() throws Exception
      Checks that TreePathCacher.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

      public void useUnitKeepsEntriesForAllCheckersOfAUnit() throws Exception
      Simulates the checkers of a compound checker, which share one cache and each call TreePathCacher.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

      public void addArtificialPathMarksTheTree() throws Exception
      Throws:
      Exception - if parsing the test sources fails
    • useUnitAfterClearBehavesLikeAFreshCache

      public void useUnitAfterClearBehavesLikeAFreshCache() throws Exception
      Checks that after TreePathCacher.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

      public void manyLookupsUnderOneLeafMatchJdk() throws Exception
      Checks that many lookups under the same leaf, enough for TreePathCacher to index the leaf's subtree, match the JDK for targets under the leaf, outside it, and absent from the compilation unit. The body declares Integer a, b;, whose declarators share a type tree.
      Throws:
      Exception - if parsing the test sources fails