IDEA-143911 (quick fix produces uncompilable code (StringBuffer can be replaced with String))

This commit is contained in:
Bas Leijdekkers
2015-08-17 17:40:36 +02:00
parent b00e5ea35e
commit 1a9e331018
4 changed files with 21 additions and 1 deletions
@@ -209,7 +209,7 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
}
if (element instanceof PsiWhiteSpace) {
if (element.getText().contains("\n")) {
if (element.getText().contains("\n") && result.length() > 0) {
result.append('\n'); // keep line break structure
}
}
@@ -0,0 +1,9 @@
class Linebreaks {
void m(String code) {
String controlDigit = String.valueOf(code.charAt(5)) +
code.charAt(7) +
code.charAt(9) +
code.charAt(11);
}
}
@@ -0,0 +1,10 @@
class Linebreaks {
void m(String code) {
String controlDigit = new Stri<caret>ngBuilder()
.append(code.charAt(5))
.append(code.charAt(7))
.append(code.charAt(9))
.append(code.charAt(11)).toString();
}
}
@@ -35,4 +35,5 @@ public class StringBufferReplaceableByStringFixTest extends IGQuickFixesTestCase
public void testMethodCallOnString() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
public void testComplex1() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
public void testComplex2() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
public void testLinebreaks() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
}