Simplify ParserRuleContext.toString

This commit is contained in:
Sam Harwell 2012-07-13 14:26:14 -05:00
parent 683b915507
commit d626c4acd6
1 changed files with 5 additions and 5 deletions

View File

@ -304,15 +304,15 @@ public class ParserRuleContext<Symbol extends Token> extends RuleContext {
public String toString(@NotNull Recognizer<?,?> recog, RuleContext stop) {
if ( recog==null ) return super.toString(recog, stop);
StringBuilder buf = new StringBuilder();
ParserRuleContext<?> p = this;
RuleContext p = this;
buf.append("[");
String[] ruleNames = recog.getRuleNames();
while ( p != null && p != stop ) {
ATN atn = recog.getATN();
ATNState s = atn.states.get(p.s);
String ruleName = recog.getRuleNames()[s.ruleIndex];
int ruleIndex = p.getRuleIndex();
String ruleName = ruleIndex >= 0 && ruleIndex < ruleNames.length ? ruleNames[ruleIndex] : Integer.toString(ruleIndex);
buf.append(ruleName);
if ( p.parent != null ) buf.append(" ");
p = (ParserRuleContext<?>)p.parent;
p = p.parent;
}
buf.append("]");
return buf.toString();