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