mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-91439 (StringBuffer replacement with String is wrong when char[] is involved)
This commit is contained in:
+6
-4
@@ -180,9 +180,11 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
|
||||
result.append('(').append(argument.getText()).append(')');
|
||||
}
|
||||
else {
|
||||
result.append(argument.getText());
|
||||
if (type != null && !type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) {
|
||||
result.append(".toString()");
|
||||
result.append("String.valueOf(").append(argument.getText()).append(")");
|
||||
}
|
||||
else {
|
||||
result.append(argument.getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -280,7 +282,7 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
|
||||
|
||||
public static boolean isAppend(PsiMethodCallExpression methodCallExpression) {
|
||||
final PsiReferenceExpression methodExpression = methodCallExpression.getMethodExpression();
|
||||
final String methodName = methodExpression.getReferenceName();
|
||||
@NonNls final String methodName = methodExpression.getReferenceName();
|
||||
return "append".equals(methodName);
|
||||
}
|
||||
}
|
||||
@@ -299,7 +301,7 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
|
||||
if (!(grandParent instanceof PsiMethodCallExpression)) {
|
||||
break;
|
||||
}
|
||||
final String name = referenceExpression.getReferenceName();
|
||||
@NonNls final String name = referenceExpression.getReferenceName();
|
||||
if ("append".equals(name)) {
|
||||
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)grandParent;
|
||||
final PsiExpressionList argumentList = methodCallExpression.getArgumentList();
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@ package com.siyeh.igfixes.style.replace_with_string;
|
||||
|
||||
class NonString2 {
|
||||
|
||||
String foo(Object o) {
|
||||
return o.toString();
|
||||
String foo(char[] o) {
|
||||
return String.valueOf(o);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@ package com.siyeh.igfixes.style.replace_with_string;
|
||||
|
||||
class NonString2 {
|
||||
|
||||
String foo(Object o) {
|
||||
String foo(char[] o) {
|
||||
return new StringBuilder<caret>().append(o).toString();
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -15,13 +15,13 @@ public class StringBufferReplaceableWithStringFixTest extends IGQuickFixesTestCa
|
||||
}
|
||||
|
||||
public void testSimpleStringBuffer() { doTest(); }
|
||||
public void testStringBuilderAppend() { doTest("StringBuilderAppend", InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
|
||||
public void testStringBuilderAppend() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
|
||||
public void testStringBufferVariable() { doTest(); }
|
||||
public void testStringBufferVariable2() { doTest(); }
|
||||
public void testStartsWithPrimitive() { doTest(); }
|
||||
public void testPrecedence() { doTest("Precedence", InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
|
||||
public void testPrecedence2() { doTest("Precedence2", InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
|
||||
public void testPrecedence3() { doTest("Precedence3", InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
|
||||
public void testNonString1() { doTest("Precedence3", InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
|
||||
public void testNonString2() { doTest("Precedence3", InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
|
||||
public void testPrecedence() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
|
||||
public void testPrecedence2() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
|
||||
public void testPrecedence3() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
|
||||
public void testNonString1() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
|
||||
public void testNonString2() { doTest(InspectionGadgetsBundle.message("string.builder.replaceable.by.string.quickfix")); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user