From 885f6530ada3a97b050dfdfaa7570d8b0121bd5e Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 18 Jul 2012 12:28:27 -0500 Subject: [PATCH] Use chained calls to append instead of string concatenation --- .../antlr/v4/runtime/atn/ATNConfigSet.java | 6 ++-- .../antlr/v4/runtime/dfa/DFASerializer.java | 2 +- .../org/antlr/v4/runtime/dfa/DFAState.java | 2 +- .../runtime/tree/gui/PostScriptDocument.java | 4 +-- .../src/org/antlr/v4/automata/ATNPrinter.java | 14 +++++----- .../org/antlr/v4/automata/ATNSerializer.java | 28 +++++++++---------- tool/src/org/antlr/v4/parse/ATNBuilder.g | 2 +- tool/src/org/antlr/v4/parse/ActionSplitter.g | 2 +- tool/src/org/antlr/v4/tool/Rule.java | 6 ++-- 9 files changed, 33 insertions(+), 33 deletions(-) diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java index 994bd6eb3..d64de3b5c 100755 --- a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java +++ b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java @@ -70,9 +70,9 @@ public class ATNConfigSet extends OrderedHashSet { 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(); } diff --git a/runtime/Java/src/org/antlr/v4/runtime/dfa/DFASerializer.java b/runtime/Java/src/org/antlr/v4/runtime/dfa/DFASerializer.java index face14f53..0b06d4c5a 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/dfa/DFASerializer.java +++ b/runtime/Java/src/org/antlr/v4/runtime/dfa/DFASerializer.java @@ -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'); } } } diff --git a/runtime/Java/src/org/antlr/v4/runtime/dfa/DFAState.java b/runtime/Java/src/org/antlr/v4/runtime/dfa/DFAState.java index faf8806a8..98586b585 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/dfa/DFAState.java +++ b/runtime/Java/src/org/antlr/v4/runtime/dfa/DFAState.java @@ -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 ) { diff --git a/runtime/Java/src/org/antlr/v4/runtime/tree/gui/PostScriptDocument.java b/runtime/Java/src/org/antlr/v4/runtime/tree/gui/PostScriptDocument.java index 06a092fc9..0672f6396 100644 --- a/runtime/Java/src/org/antlr/v4/runtime/tree/gui/PostScriptDocument.java +++ b/runtime/Java/src/org/antlr/v4/runtime/tree/gui/PostScriptDocument.java @@ -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) { diff --git a/tool/src/org/antlr/v4/automata/ATNPrinter.java b/tool/src/org/antlr/v4/automata/ATNPrinter.java index 41ced4639..db83c1fc5 100644 --- a/tool/src/org/antlr/v4/automata/ATNPrinter.java +++ b/tool/src/org/antlr/v4/automata/ATNPrinter.java @@ -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'); } } } diff --git a/tool/src/org/antlr/v4/automata/ATNSerializer.java b/tool/src/org/antlr/v4/automata/ATNSerializer.java index 64e7a0f71..5d727854b 100644 --- a/tool/src/org/antlr/v4/automata/ATNSerializer.java +++ b/tool/src/org/antlr/v4/automata/ATNSerializer.java @@ -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; i1 ) 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(); } diff --git a/tool/src/org/antlr/v4/parse/ATNBuilder.g b/tool/src/org/antlr/v4/parse/ATNBuilder.g index 8ab10147c..82060a03b 100644 --- a/tool/src/org/antlr/v4/parse/ATNBuilder.g +++ b/tool/src/org/antlr/v4/parse/ATNBuilder.g @@ -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()); } diff --git a/tool/src/org/antlr/v4/parse/ActionSplitter.g b/tool/src/org/antlr/v4/parse/ActionSplitter.g index 0776b0de9..5f1e437d6 100644 --- a/tool/src/org/antlr/v4/parse/ActionSplitter.g +++ b/tool/src/org/antlr/v4/parse/ActionSplitter.g @@ -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);} )+ ; diff --git a/tool/src/org/antlr/v4/tool/Rule.java b/tool/src/org/antlr/v4/tool/Rule.java index 2bdc12f53..e029c493f 100644 --- a/tool/src/org/antlr/v4/tool/Rule.java +++ b/tool/src/org/antlr/v4/tool/Rule.java @@ -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(); }