MCPcopy Create free account
hub / github.com/antlr/codebuff / earliestAncestorEndingWithToken

Method earliestAncestorEndingWithToken

src/org/antlr/codebuff/Trainer.java:447–459  ·  view source on GitHub ↗

Walk upwards from node while p.stop == token; return immediate parent if there is no ancestor stopping at token. This is the earliest right ancestor. E.g, for '}' of a block, return parent up the chain from block stopping with '}'. For '{' of block, return just block as nothing stops with '{'. (

(TerminalNode node)

Source from the content-addressed store, hash-verified

445 * stops with '{'. (block starts with it).
446 */
447 public static ParserRuleContext earliestAncestorEndingWithToken(TerminalNode node) {
448 Token token = node.getSymbol();
449 ParserRuleContext p = (ParserRuleContext)node.getParent();
450 ParserRuleContext prev = null;
451 while (p!=null && p.getStop()==token) {
452 prev = p;
453 p = p.getParent();
454 }
455 if ( prev==null ) {
456 return (ParserRuleContext)node.getParent();
457 }
458 return prev;
459 }
460
461 /** Walk upwards from node until we find a child of p at t's char position.
462 * Don't see alignment with self, t, or element *after* us.

Callers 1

getContextFeaturesMethod · 0.95

Calls 1

getParentMethod · 0.45

Tested by

no test coverage detected