return new ParseTreePattern(this, pattern, patternRuleIndex, tree);
/** Does {@code pattern} matched as rule patternRuleIndex match tree? Pass in a * compiled pattern instead of a string representation of a tree pattern. */ public boolean matches(ParseTree tree, ParseTreePattern pattern) { MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>(); ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels); return mismatchedNode == null; }
/** * Find all nodes using XPath and then try to match those subtrees against * this tree pattern. * * @param tree The {@link ParseTree} to match against this pattern. * @param xpath An expression matching the nodes * * @return A collection of {@link ParseTreeMatch} objects describing the * successful matches. Unsuccessful matches are omitted from the result, * regardless of the reason for the failure. */ public List<ParseTreeMatch> findAll(ParseTree tree, String xpath) { Collection<ParseTree> subtrees = XPath.findAll(tree, xpath, matcher.getParser()); List<ParseTreeMatch> matches = new ArrayList<ParseTreeMatch>(); for (ParseTree t : subtrees) { ParseTreeMatch match = match(t); if ( match.succeeded() ) { matches.add(match); } } return matches; }
String treePattern = "<TOKEN_REF> : <STRING_LITERAL>;"; ParseTreePattern p = parser.compileParseTreePattern(treePattern, ANTLRv4Parser.RULE_lexerRule); List<ParseTreeMatch> matches = p.findAll(tree, lexerRulesXPath);
/** * Compare {@code pattern} matched against {@code tree} and return a * {@link ParseTreeMatch} object that contains the matched elements, or the * node at which the match failed. Pass in a compiled pattern instead of a * string representation of a tree pattern. */ public ParseTreeMatch match(ParseTree tree, ParseTreePattern pattern) { MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>(); ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels); return new ParseTreeMatch(tree, pattern, labels, mismatchedNode); }
/** * Find all nodes using XPath and then try to match those subtrees against * this tree pattern. * * @param tree The {@link ParseTree} to match against this pattern. * @param xpath An expression matching the nodes * * @return A collection of {@link ParseTreeMatch} objects describing the * successful matches. Unsuccessful matches are omitted from the result, * regardless of the reason for the failure. */ public List<ParseTreeMatch> findAll(ParseTree tree, String xpath) { Collection<ParseTree> subtrees = XPath.findAll(tree, xpath, matcher.getParser()); List<ParseTreeMatch> matches = new ArrayList<ParseTreeMatch>(); for (ParseTree t : subtrees) { ParseTreeMatch match = match(t); if ( match.succeeded() ) { matches.add(match); } } return matches; }
return new ParseTreePattern(this, pattern, patternRuleIndex, tree);
/** Does {@code pattern} matched as rule patternRuleIndex match tree? Pass in a * compiled pattern instead of a string representation of a tree pattern. */ public boolean matches(ParseTree tree, ParseTreePattern pattern) { MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>(); ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels); return mismatchedNode == null; }
/** * Find all nodes using XPath and then try to match those subtrees against * this tree pattern. * * @param tree The {@link ParseTree} to match against this pattern. * @param xpath An expression matching the nodes * * @return A collection of {@link ParseTreeMatch} objects describing the * successful matches. Unsuccessful matches are omitted from the result, * regardless of the reason for the failure. */ public List<ParseTreeMatch> findAll(ParseTree tree, String xpath) { Collection<ParseTree> subtrees = XPath.findAll(tree, xpath, matcher.getParser()); List<ParseTreeMatch> matches = new ArrayList<ParseTreeMatch>(); for (ParseTree t : subtrees) { ParseTreeMatch match = match(t); if ( match.succeeded() ) { matches.add(match); } } return matches; }
return new ParseTreePattern(this, pattern, patternRuleIndex, tree);
/** Does {@code pattern} matched as rule patternRuleIndex match tree? Pass in a * compiled pattern instead of a string representation of a tree pattern. */ public boolean matches(ParseTree tree, ParseTreePattern pattern) { MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>(); ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels); return mismatchedNode == null; }
/** * Find all nodes using XPath and then try to match those subtrees against * this tree pattern. * * @param tree The {@link ParseTree} to match against this pattern. * @param xpath An expression matching the nodes * * @return A collection of {@link ParseTreeMatch} objects describing the * successful matches. Unsuccessful matches are omitted from the result, * regardless of the reason for the failure. */ public List<ParseTreeMatch> findAll(ParseTree tree, String xpath) { Collection<ParseTree> subtrees = XPath.findAll(tree, xpath, matcher.getParser()); List<ParseTreeMatch> matches = new ArrayList<ParseTreeMatch>(); for (ParseTree t : subtrees) { ParseTreeMatch match = match(t); if ( match.succeeded() ) { matches.add(match); } } return matches; }
return new ParseTreePattern(this, pattern, patternRuleIndex, tree);
/** Does {@code pattern} matched as rule patternRuleIndex match tree? Pass in a * compiled pattern instead of a string representation of a tree pattern. */ public boolean matches(ParseTree tree, ParseTreePattern pattern) { MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>(); ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels); return mismatchedNode == null; }
/** * Find all nodes using XPath and then try to match those subtrees against * this tree pattern. * * @param tree The {@link ParseTree} to match against this pattern. * @param xpath An expression matching the nodes * * @return A collection of {@link ParseTreeMatch} objects describing the * successful matches. Unsuccessful matches are omitted from the result, * regardless of the reason for the failure. */ @NotNull public List<ParseTreeMatch> findAll(@NotNull ParseTree tree, @NotNull String xpath) { Collection<ParseTree> subtrees = XPath.findAll(tree, xpath, matcher.getParser()); List<ParseTreeMatch> matches = new ArrayList<ParseTreeMatch>(); for (ParseTree t : subtrees) { ParseTreeMatch match = match(t); if ( match.succeeded() ) { matches.add(match); } } return matches; }
return new ParseTreePattern(this, pattern, patternRuleIndex, tree);
/** Does {@code pattern} matched as rule patternRuleIndex match tree? Pass in a * compiled pattern instead of a string representation of a tree pattern. */ public boolean matches(ParseTree tree, ParseTreePattern pattern) { MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>(); ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels); return mismatchedNode == null; }
/** * Compare {@code pattern} matched against {@code tree} and return a * {@link ParseTreeMatch} object that contains the matched elements, or the * node at which the match failed. Pass in a compiled pattern instead of a * string representation of a tree pattern. */ public ParseTreeMatch match(ParseTree tree, ParseTreePattern pattern) { MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>(); ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels); return new ParseTreeMatch(tree, pattern, labels, mismatchedNode); }
/** * Compare {@code pattern} matched against {@code tree} and return a * {@link ParseTreeMatch} object that contains the matched elements, or the * node at which the match failed. Pass in a compiled pattern instead of a * string representation of a tree pattern. */ public ParseTreeMatch match(ParseTree tree, ParseTreePattern pattern) { MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>(); ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels); return new ParseTreeMatch(tree, pattern, labels, mismatchedNode); }
/** * Compare {@code pattern} matched against {@code tree} and return a * {@link ParseTreeMatch} object that contains the matched elements, or the * node at which the match failed. Pass in a compiled pattern instead of a * string representation of a tree pattern. */ public ParseTreeMatch match(ParseTree tree, ParseTreePattern pattern) { MultiMap<String, ParseTree> labels = new MultiMap<String, ParseTree>(); ParseTree mismatchedNode = matchImpl(tree, pattern.getPatternTree(), labels); return new ParseTreeMatch(tree, pattern, labels, mismatchedNode); }