MCPcopy Index your code
hub / github.com/antlr/antlr4 / evaluate

Method evaluate

runtime/Java/src/org/antlr/v4/runtime/tree/xpath/XPath.java:204–227  ·  view source on GitHub ↗

Return a list of all nodes starting at t as root that satisfy the path. The root / is relative to the node passed to #evaluate.

(final ParseTree t)

Source from the content-addressed store, hash-verified

202 * {@link #evaluate}.
203 */
204 public Collection<ParseTree> evaluate(final ParseTree t) {
205 ParserRuleContext dummyRoot = new ParserRuleContext();
206 dummyRoot.children = Collections.singletonList(t); // don't set t's parent.
207
208 Collection<ParseTree> work = Collections.<ParseTree>singleton(dummyRoot);
209
210 int i = 0;
211 while ( i < elements.length ) {
212 Collection<ParseTree> next = new LinkedHashSet<ParseTree>();
213 for (ParseTree node : work) {
214 if ( node.getChildCount()>0 ) {
215 // only try to match next element if it has children
216 // e.g., //func/*/stat might have a token node for which
217 // we can't go looking for stat nodes.
218 Collection<? extends ParseTree> matching = elements[i].evaluate(node);
219 next.addAll(matching);
220 }
221 }
222 i++;
223 work = next;
224 }
225
226 return work;
227 }
228}

Callers 1

findAllMethod · 0.95

Calls 3

getChildCountMethod · 0.65
evaluateMethod · 0.65
addAllMethod · 0.65

Tested by

no test coverage detected