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)
| 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 | } |
no test coverage detected