Use chained calls to append instead of string concatenation

This commit is contained in:
Sam Harwell 2012-07-18 12:28:27 -05:00
parent 6259ab5c9e
commit 885f6530ad
9 changed files with 33 additions and 33 deletions

View File

@ -70,9 +70,9 @@ public class ATNConfigSet extends OrderedHashSet<ATNConfig> {
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(super.toString());
if ( hasSemanticContext ) buf.append(",hasSemanticContext="+hasSemanticContext);
if ( uniqueAlt!=ATN.INVALID_ALT_NUMBER ) buf.append(",uniqueAlt="+uniqueAlt);
if ( conflictingAlts!=null ) buf.append(",conflictingAlts="+conflictingAlts);
if ( hasSemanticContext ) buf.append(",hasSemanticContext=").append(hasSemanticContext);
if ( uniqueAlt!=ATN.INVALID_ALT_NUMBER ) buf.append(",uniqueAlt=").append(uniqueAlt);
if ( conflictingAlts!=null ) buf.append(",conflictingAlts=").append(conflictingAlts);
if ( dipsIntoOuterContext ) buf.append(",dipsIntoOuterContext");
return buf.toString();
}

View File

@ -60,7 +60,7 @@ public class DFASerializer {
if ( t!=null && t.stateNumber != Integer.MAX_VALUE ) {
buf.append(getStateString(s));
String label = getEdgeLabel(i);
buf.append("-"+label+"->"+ getStateString(t)+'\n');
buf.append("-").append(label).append("->").append(getStateString(t)).append('\n');
}
}
}

View File

@ -205,7 +205,7 @@ public class DFAState {
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(stateNumber + ":" + configset);
buf.append(stateNumber).append(":").append(configset);
if ( isAcceptState ) {
buf.append("=>");
if ( predicates!=null ) {

View File

@ -74,7 +74,7 @@ public class PostScriptDocument {
protected StringBuilder header() {
StringBuilder b = new StringBuilder();
b.append("%!PS-Adobe-3.0 EPSF-3.0\n");
b.append(boundingBox+"\n");
b.append(boundingBox).append("\n");
b.append("0.3 setlinewidth\n");
b.append("%% x y w h highlight\n" +
"/highlight {\n" +
@ -116,7 +116,7 @@ public class PostScriptDocument {
public void lineWidth(double w) {
lineWidth = w;
ps.append(w+" setlinewidth\n");
ps.append(w).append(" setlinewidth\n");
}
public void move(double x, double y) {

View File

@ -73,33 +73,33 @@ public class ATNPrinter {
}
buf.append(getStateString(s));
if ( t instanceof EpsilonTransition ) {
buf.append("->"+ getStateString(t.target)+'\n');
buf.append("->").append(getStateString(t.target)).append('\n');
}
else if ( t instanceof RuleTransition ) {
buf.append("-"+g.getRule(((RuleTransition)t).ruleIndex).name+"->"+ getStateString(t.target)+'\n');
buf.append("-").append(g.getRule(((RuleTransition)t).ruleIndex).name).append("->").append(getStateString(t.target)).append('\n');
}
else if ( t instanceof ActionTransition ) {
ActionTransition a = (ActionTransition)t;
buf.append("-"+a.toString()+"->"+ getStateString(t.target)+'\n');
buf.append("-").append(a.toString()).append("->").append(getStateString(t.target)).append('\n');
}
else if ( t instanceof SetTransition ) {
SetTransition st = (SetTransition)t;
boolean not = st instanceof NotSetTransition;
if ( g.isLexer() ) {
buf.append("-"+(not?"~":"")+st.toString()+"->"+ getStateString(t.target)+'\n');
buf.append("-").append(not?"~":"").append(st.toString()).append("->").append(getStateString(t.target)).append('\n');
}
else {
buf.append("-"+(not?"~":"")+st.label().toString(g.getTokenNames())+"->"+ getStateString(t.target)+'\n');
buf.append("-").append(not?"~":"").append(st.label().toString(g.getTokenNames())).append("->").append(getStateString(t.target)).append('\n');
}
}
else if ( t instanceof AtomTransition ) {
AtomTransition a = (AtomTransition)t;
String label = a.toString();
if ( g!=null ) label = g.getTokenDisplayName(a.label);
buf.append("-"+label+"->"+ getStateString(t.target)+'\n');
buf.append("-").append(label).append("->").append(getStateString(t.target)).append('\n');
}
else {
buf.append("-"+t.toString()+"->"+ getStateString(t.target)+'\n');
buf.append("-").append(t.toString()).append("->").append(getStateString(t.target)).append('\n');
}
}
}

View File

@ -200,7 +200,7 @@ public class ATNSerializer {
int p = 0;
int grammarType = ATNSimulator.toInt(data[p++]);
int maxType = ATNSimulator.toInt(data[p++]);
buf.append("max type "+maxType+"\n");
buf.append("max type ").append(maxType).append("\n");
int nstates = ATNSimulator.toInt(data[p++]);
for (int i=1; i<=nstates; i++) {
int stype = ATNSimulator.toInt(data[p++]);
@ -211,9 +211,9 @@ public class ATNSerializer {
int loopBackStateNumber = ATNSimulator.toInt(data[p++]);
arg = " "+loopBackStateNumber;
}
buf.append((i - 1) + ":" +
ATNState.serializationNames.get(stype) + " "+
ruleIndex + arg + "\n");
buf.append(i - 1).append(":")
.append(ATNState.serializationNames.get(stype)).append(" ")
.append(ruleIndex).append(arg).append("\n");
}
int nrules = ATNSimulator.toInt(data[p++]);
for (int i=0; i<nrules; i++) {
@ -221,24 +221,24 @@ public class ATNSerializer {
if ( g.isLexer() ) {
int arg1 = ATNSimulator.toInt(data[p++]);
int arg2 = ATNSimulator.toInt(data[p++]);
buf.append("rule "+i+":"+s+" "+arg1+","+arg2+'\n');
buf.append("rule ").append(i).append(":").append(s).append(" ").append(arg1).append(",").append(arg2).append('\n');
}
else {
buf.append("rule "+i+":"+s+'\n');
buf.append("rule ").append(i).append(":").append(s).append('\n');
}
}
int nmodes = ATNSimulator.toInt(data[p++]);
for (int i=0; i<nmodes; i++) {
int s = ATNSimulator.toInt(data[p++]);
buf.append("mode "+i+":"+s+'\n');
buf.append("mode ").append(i).append(":").append(s).append('\n');
}
int nsets = ATNSimulator.toInt(data[p++]);
for (int i=1; i<=nsets; i++) {
int nintervals = ATNSimulator.toInt(data[p++]);
buf.append((i-1)+":");
buf.append(i-1).append(":");
for (int j=1; j<=nintervals; j++) {
if ( j>1 ) buf.append(", ");
buf.append(getTokenName(ATNSimulator.toInt(data[p]))+".."+getTokenName(ATNSimulator.toInt(data[p + 1])));
buf.append(getTokenName(ATNSimulator.toInt(data[p]))).append("..").append(getTokenName(ATNSimulator.toInt(data[p + 1])));
p += 2;
}
buf.append("\n");
@ -251,17 +251,17 @@ public class ATNSerializer {
int arg1 = ATNSimulator.toInt(data[p + 3]);
int arg2 = ATNSimulator.toInt(data[p + 4]);
int arg3 = ATNSimulator.toInt(data[p + 5]);
buf.append(src+"->"+trg+
" "+Transition.serializationNames.get(ttype)+
" "+arg1+","+arg2+","+arg3+
"\n");
buf.append(src).append("->").append(trg)
.append(" ").append(Transition.serializationNames.get(ttype))
.append(" ").append(arg1).append(",").append(arg2).append(",").append(arg3)
.append("\n");
p += 6;
}
int ndecisions = ATNSimulator.toInt(data[p++]);
for (int i=1; i<=ndecisions; i++) {
int s = ATNSimulator.toInt(data[p++]);
int isGreedy = ATNSimulator.toInt(data[p++]);
buf.append((i-1)+":"+s+" "+isGreedy+"\n");
buf.append(i-1).append(":").append(s).append(" ").append(isGreedy).append("\n");
}
return buf.toString();
}

View File

@ -106,7 +106,7 @@ alternative returns [ATNFactory.Handle p]
lexerCommands returns [ATNFactory.Handle p]
@init {StringBuilder cmds = new StringBuilder();}
: (c=lexerCommand {cmds.append($c.cmd+" ");})+
: (c=lexerCommand {cmds.append($c.cmd).append(' ');})+
{
$p = factory.action(cmds.toString());
}

View File

@ -82,7 +82,7 @@ TEXT
@after {delegate.text(buf.toString());}
: ( c=~('\\'| '$') {buf.append((char)$c);}
| '\\$' {buf.append("$");}
| '\\' c=~('$') {buf.append("\\"+(char)$c);}
| '\\' c=~('$') {buf.append('\\').append((char)$c);}
)+
;

View File

@ -346,9 +346,9 @@ public class Rule implements AttributeResolver {
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("Rule{name="+name);
if ( args!=null ) buf.append(", args=" + args);
if ( retvals!=null ) buf.append(", retvals=" + retvals);
buf.append("Rule{name=").append(name);
if ( args!=null ) buf.append(", args=").append(args);
if ( retvals!=null ) buf.append(", retvals=").append(retvals);
buf.append("}");
return buf.toString();
}