mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-01 18:58:31 +07:00
IDEA-165193 Provide a quick-fix to replace String concatenation in loop with StringBuilder
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
// "Change type of 'res' to StringBuilder" "true"
|
||||
|
||||
public class Main {
|
||||
String test(String[] strings) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (String s : strings) {
|
||||
if (res.length() > 0) {
|
||||
res.insert(0, ".");
|
||||
}
|
||||
res.insert(0, s);
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Change type of 'res' to StringBuilder" "true"
|
||||
|
||||
public class Main {
|
||||
String test(String[] strings) {
|
||||
StringBuilder res = null;
|
||||
for (String s : strings) {
|
||||
if(res == null) {
|
||||
res = new StringBuilder(s);
|
||||
} else {
|
||||
res.append(s);
|
||||
}
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Change type of 'res' to StringBuilder" "true"
|
||||
|
||||
public class Main {
|
||||
void test(String[] strings) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (String s : strings) {
|
||||
if(res.length()+s.length() > 80) {
|
||||
System.out.println(res);
|
||||
res = new StringBuilder();
|
||||
}
|
||||
res.append(s);
|
||||
}
|
||||
System.out.println(res);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Change type of 'res' to StringBuilder" "true"
|
||||
|
||||
public class Main {
|
||||
String test(String[] strings) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (String s : strings) {
|
||||
res.append(s);
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Change type of 'res' to StringBuilder" "true"
|
||||
|
||||
public class Main {
|
||||
String test(String[] strings) {
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (String s : strings) {
|
||||
res.append(s);
|
||||
}
|
||||
res = new StringBuilder(res.toString().trim());
|
||||
return (res.length() == 0) ? null : res.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Change type of 'res' to StringBuilder" "true"
|
||||
|
||||
public class Main {
|
||||
String test(String[] strings) {
|
||||
/*within*/
|
||||
StringBuilder res = new StringBuilder();
|
||||
for (String s : strings) {
|
||||
if (/*before*/res.length() > 0) {
|
||||
res.append(", ");
|
||||
}
|
||||
res.append(s);
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Change type of 'res' to StringBuilder" "true"
|
||||
|
||||
public class Main {
|
||||
String test(String[] strings) {
|
||||
String res = "";
|
||||
for (String s : strings) {
|
||||
if (!res.isEmpty()) {
|
||||
res = "." + res;
|
||||
}
|
||||
res = s <caret>+ res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Change type of 'res' to StringBuilder" "true"
|
||||
|
||||
public class Main {
|
||||
String test(String[] strings) {
|
||||
String res = null;
|
||||
for (String s : strings) {
|
||||
if(res == null) {
|
||||
res = s;
|
||||
} else {
|
||||
res<caret>+=s;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
// "Change type of 'res' to StringBuilder" "true"
|
||||
|
||||
public class Main {
|
||||
void test(String[] strings) {
|
||||
String res = "";
|
||||
for (String s : strings) {
|
||||
if(res.length()+s.length() > 80) {
|
||||
System.out.println(res);
|
||||
res = "";
|
||||
}
|
||||
res<caret>+=s;
|
||||
}
|
||||
System.out.println(res);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Change type of 'res' to StringBuilder" "true"
|
||||
|
||||
public class Main {
|
||||
String test(String[] strings) {
|
||||
String res = "";
|
||||
for (String s : strings) {
|
||||
res <caret>+= s;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Change type of 'res' to StringBuilder" "true"
|
||||
|
||||
public class Main {
|
||||
String test(String[] strings) {
|
||||
String res = "";
|
||||
for (String s : strings) {
|
||||
res <caret>+= s;
|
||||
}
|
||||
res = res.trim();
|
||||
return res.isEmpty() ? null : res;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// "Change type of 'res' to StringBuilder" "true"
|
||||
|
||||
public class Main {
|
||||
String test(String[] strings) {
|
||||
String res = "";
|
||||
for (String s : strings) {
|
||||
if (/*before*/!res/*within*/.isEmpty()) {
|
||||
res += ", ";
|
||||
}
|
||||
res <caret>+= s;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user