Source:
<code>public String text(GrammarAST t) { if ( t==null ) return ""; StringBuilder buf = new StringBuilder(); int a = t.getTokenStartIndex(); int b = t.getTokenStopIndex(); IntervalSet ignore = new IntervalSet(); List<GrammarAST> optionsSubTrees = t.getNodesWithType(ELEMENT_OPTIONS); for (GrammarAST sub : optionsSubTrees) { ignore.add(sub.getTokenStartIndex(), sub.getTokenStopIndex()); } IntervalSet noOptions = new IntervalSet(); List<GrammarAST> labeledSubTrees = t.getNodesWithType(new IntervalSet(ASSIGN,PLUS_ASSIGN)); for (GrammarAST sub : labeledSubTrees) { noOptions.add(sub.getChild(0).getTokenStartIndex()); } String options; for (int i=a; i<=b; i++) { options = ""; if ( ignore.contains(i) ) continue; Token tok = tokenStream.get(i); StringBuilder existingOptions = new StringBuilder(); GrammarAST node = t.getNodeWithTokenIndex(tok.getTokenIndex()); if ( node instanceof GrammarASTWithOptions ) { GrammarASTWithOptions o = (GrammarASTWithOptions)node; Map<String, GrammarAST> opts = o.getOptions(); if ( opts.size()>0 ) { existingOptions.append(","); for (String key : opts.keySet()) { existingOptions.append(key); existingOptions.append('='); existingOptions.append(opts.get(key).getText()); } } } <START> if ( node!=null && !noOptions.contains(i) && <END> (tok.getType()==TOKEN_REF || tok.getType()==STRING_LITERAL || tok.getType()==RULE_REF) ) { options = String.format("<tokenIndex=%d%s>", tok.getTokenIndex(), existingOptions.toString()); } buf.append(tok.getText()); buf.append(options); } return buf.toString(); }</code><technical_language>This condition else if (!existingOptions.isEmpty()) block</technical_language>

Target:
public String text(GrammarAST t) { if ( t==null ) return ""; int tokenStartIndex = t.getTokenStartIndex(); int tokenStopIndex = t.getTokenStopIndex(); IntervalSet ignore = new IntervalSet(); List<GrammarAST> optionsSubTrees = t.getNodesWithType(ELEMENT_OPTIONS); for (GrammarAST sub : optionsSubTrees) { ignore.add(sub.getTokenStartIndex(), sub.getTokenStopIndex()); } IntervalSet noOptions = new IntervalSet(); List<GrammarAST> labeledSubTrees = t.getNodesWithType(new IntervalSet(ASSIGN,PLUS_ASSIGN)); for (GrammarAST sub : labeledSubTrees) { noOptions.add(sub.getChild(0).getTokenStartIndex()); } StringBuilder buf = new StringBuilder(); for (int i=tokenStartIndex; i<=tokenStopIndex; i++) { if ( ignore.contains(i) ) { continue; } Token tok = tokenStream.get(i); StringBuilder elementOptions = new StringBuilder(); if (!noOptions.contains(i)) { GrammarAST node = t.getNodeWithTokenIndex(tok.getTokenIndex()); if ( node!=null && (tok.getType()==TOKEN_REF || tok.getType()==STRING_LITERAL || tok.getType()==RULE_REF) ) { elementOptions.append("tokenIndex=").append(tok.getTokenIndex()); } if ( node instanceof GrammarASTWithOptions ) { GrammarASTWithOptions o = (GrammarASTWithOptions)node; for (Map.Entry<String, GrammarAST> entry : o.getOptions().entrySet()) { if (elementOptions.length() > 0) { elementOptions.append(','); } elementOptions.append(entry.getKey()); elementOptions.append('='); elementOptions.append(entry.getValue().getText()); } } } buf.append(tok.getText()); if (elementOptions.length() > 0) { buf.append('<').append(elementOptions).append('>'); } } return buf.toString(); }