Class TreeMatcher<V>


  • public final class TreeMatcher<V>
    extends Object
    Implementation of a pattern based tree matcher. It allows you to iterate over all matches of a tree for a given pattern.
    final TreePattern<String> pattern = TreePattern.compile("add($x,$y)"); final Tree<String, ?> tree = TreeNode.parse("add(1,add(2,3))"); final TreeMatcher<String> matcher = pattern.matcher(tree); matcher.results().forEach(r -> System.out.println(r.tree().toParenthesesString())); // Prints: // add(1,add(2,3)) // add(2,3)
    Since:
    5.0
    Version:
    5.0
    See Also:
    TreePattern.matcher(Tree)
    • Method Detail

      • pattern

        public TreePattern<Vpattern()
        Return the underlying pattern of this matcher.
        Returns:
        the underlying tree pattern
      • tree

        public Tree<V,​?> tree()
        Return the matching tree.
        Returns:
        the matching tree
      • matches

        public boolean matches()
        Tests if the tree matches the pattern.
        Returns:
        true if the tree matches against the pattern, false otherwise
        Throws:
        NullPointerException - if the given predicate is null