Class Heuristics


  • public class Heuristics
    extends java.lang.Object
    Utilities for determining tree-based heuristics.

    For an example, see org.checkerframework.checker.interning.InterningVisitor.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Heuristics.Matcher
      A base class for tree-matching algorithms.
      static class  Heuristics.OfKind
      match() returns true if called on a path whose leaf has the given kind (supplied at object initialization).
      static class  Heuristics.OrMatcher
      match() returns true if any of the given matchers returns true.
      static class  Heuristics.PreceededBy  
      static class  Heuristics.Within
      match() returns true if called on a path, any element of which matches the given matcher (supplied at object initialization).
      static class  Heuristics.WithinTrueBranch
      match() returns true if called on a path whose leaf is within the "then" clause of an if whose condition matches the matcher (supplied at object initialization).
    • Constructor Summary

      Constructors 
      Constructor Description
      Heuristics()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean matchParents​(com.sun.source.util.TreePath path, com.sun.source.tree.Tree.Kind... kinds)
      Returns true if a tree has a particular set of direct parents, ignoring blocks and parentheses.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Heuristics

        public Heuristics()
    • Method Detail

      • matchParents

        public static boolean matchParents​(com.sun.source.util.TreePath path,
                                           com.sun.source.tree.Tree.Kind... kinds)
        Returns true if a tree has a particular set of direct parents, ignoring blocks and parentheses.

        For example, to test whether an expression (specified by path) is immediately contained by an if statement which is immediately contained in a method, one would invoke:

         matchParents(path, Kind.IF, Tree.Kind.METHOD)
         
        Parameters:
        path - the path to match
        kinds - the tree kinds to match against, in ascending order starting from the desired kind of the parent
        Returns:
        true if the tree path matches the desired kinds, skipping blocks and parentheses, for as many kinds as specified