checkers.util
Class Heuristics

java.lang.Object
  extended by checkers.util.Heuristics

public class Heuristics
extends Object

Utilities for determining tree-based heuristics.

See Also:
for an example

Nested Class Summary
Modifier and Type Class and Description
static class Heuristics.Matcher
          A convenience class for tree-matching algorithms.
 
Constructor Summary
Constructor and Description
Heuristics()
           
 
Method Summary
Modifier and Type Method and Description
static boolean applyAt(TreePath path, Tree.Kind kind, Heuristics.Matcher m)
          Applies a tree-matching algorithm at the first parent on a given tree path with a specified kind and returns the result.
static boolean matchParents(TreePath path, Tree.Kind... kinds)
          Determines whether 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(TreePath path,
                                   Tree.Kind... kinds)
Determines whether 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, 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

applyAt

public static boolean applyAt(TreePath path,
                              Tree.Kind kind,
                              Heuristics.Matcher m)
Applies a tree-matching algorithm at the first parent on a given tree path with a specified kind and returns the result.

Parameters:
path - the path to search
kind - the kind on which the matcher should be applied
m - the matcher to run
Returns:
true if a tree with Tree.Kind kind is found on the path and the matcher, when applied, returns true; false otherwise