IDEA-167466 String concatenation in loop inspection: provide additional quick-fix to introduce a new StringBuilder;

String concatenation in loop is enabled by default now
This commit is contained in:
Tagir Valeev
2017-02-02 14:26:32 +03:00
parent b73c0c1000
commit 0183b826f9
10 changed files with 364 additions and 112 deletions

View File

@@ -0,0 +1,20 @@
// "Introduce new StringBuilder to update variable 's'" "true"
public class Main {
void test(boolean b) {
String s = "";
if (b) {
StringBuilder sBuilder = new StringBuilder();
for(int i = 0; i<10; i++) {
if(sBuilder.indexOf("a") > 0) {
System.out.println(sBuilder);
break;
}
sBuilder.append(i);
}
s = sBuilder.toString();
}
s = s.trim();
System.out.println(s);
}
}

View File

@@ -0,0 +1,12 @@
// "Introduce new StringBuilder to update variable 's'" "true"
public class Main {
void test(String s) {
StringBuilder sBuilder = new StringBuilder(s);
for(int i = 0; i<10; i++) {
sBuilder.append(i);
}
s = sBuilder.toString();
System.out.println(s);
}
}

View File

@@ -0,0 +1,17 @@
// "Introduce new StringBuilder to update variable 's'" "true"
public class Main {
void test(boolean b) {
String s = "";
if (b)
for(int i=0; i<10; i++) {
if(s.indexOf("a") > 0) {
System.out.println(s);
break;
}
s+<caret>=i;
}
s = s.trim();
System.out.println(s);
}
}

View File

@@ -0,0 +1,10 @@
// "Introduce new StringBuilder to update variable 's'" "true"
public class Main {
void test(String s) {
for(int i=0; i<10; i++) {
s+<caret>=i;
}
System.out.println(s);
}
}