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

Method getParentClosure

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

Return first ancestor of p that is not an only child including p. So if p.getParent().getChildCount()>1, this returns p. If we have found a chain rule at p's parent (p is its only child), then move p to its parent and try again.

(ParserRuleContext p)

Source from the content-addressed store, hash-verified

408 * move p to its parent and try again.
409 */
410 public static ParserRuleContext getParentClosure(ParserRuleContext p) {
411 if ( p==null ) return null;
412 // if p not an only child, return p
413 if ( p.getParent()==null || p.getParent().getChildCount()>1 ) return p;
414 // we found a chain rule node
415 return getParentClosure(p.getParent());
416 }
417
418 /** Walk upwards from node while p.start == token; return null if there is
419 * no ancestor starting at token.

Callers

nothing calls this directly

Calls 2

getParentMethod · 0.45
getChildCountMethod · 0.45

Tested by

no test coverage detected