StringConcatenationInLoopsInspection: automatically create append chains

This commit is contained in:
Tagir Valeev
2017-01-31 13:00:41 +03:00
parent cb4521b853
commit a47088fa4f
6 changed files with 40 additions and 12 deletions

View File

@@ -4,6 +4,7 @@ public class Main {
String test(String[] strings) {
StringBuilder res = new StringBuilder();
for (String s : strings) {
res.append(s).append("\n");
res.append(s);
}
return res.toString();

View File

@@ -8,7 +8,12 @@ public class Main {
if (/*before*/res.length() > 0) {
res.append(", ");
}
res.append(s);
if (s.contains("'")) {
res.append('[' // bracket
).append(s).append(']');
} else {
res.append(s);
}
}
return res.toString();
}

View File

@@ -4,7 +4,8 @@ public class Main {
String test(String[] strings) {
String res = "";
for (String s : strings) {
res <caret>+= s;
res <caret>+= s + "\n";
res += s;
}
return res;
}

View File

@@ -7,7 +7,12 @@ public class Main {
if (/*before*/!res/*within*/.isEmpty()) {
res += ", ";
}
res = (res <caret>+ s);
if (s.contains("'")) {
res = (res <caret>+ '[' // bracket
+ s + ']');
} else {
res = (res + s);
}
}
return res;
}