checkers.util
Class Heuristics
java.lang.Object
checkers.util.Heuristics
public class Heuristics
extends Object
Utilities for determining tree-based heuristics.
- See Also:
for an example
Nested Class Summary
static class |
Heuristics.Matcher
A convenience class for tree-matching algorithms. |
Method Summary
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 |
Heuristics
public Heuristics()
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 matchkinds
- 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 searchkind
- the kind on which the matcher should be appliedm
- 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