mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-85620 (Inspection "'StringBuffer' can be replaced with 'String'" produces invalid code.)
This commit is contained in:
+2
-2
@@ -154,7 +154,7 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
|
||||
final PsiExpression argument = arguments[0];
|
||||
if (result.length() != 0) {
|
||||
result.append('+');
|
||||
if (ParenthesesUtils.getPrecedence(argument) > ParenthesesUtils.ADDITIVE_PRECEDENCE) {
|
||||
if (ParenthesesUtils.getPrecedence(argument) >= ParenthesesUtils.ADDITIVE_PRECEDENCE) {
|
||||
result.append('(').append(argument.getText()).append(')');
|
||||
}
|
||||
else {
|
||||
@@ -167,7 +167,7 @@ public class StringBufferReplaceableByStringInspection extends BaseInspection {
|
||||
result.append("String.valueOf(").append(argument.getText()).append(")");
|
||||
}
|
||||
else {
|
||||
if (ParenthesesUtils.getPrecedence(argument) > ParenthesesUtils.ADDITIVE_PRECEDENCE) {
|
||||
if (ParenthesesUtils.getPrecedence(argument) >= ParenthesesUtils.ADDITIVE_PRECEDENCE) {
|
||||
result.append('(').append(argument.getText()).append(')');
|
||||
}
|
||||
else {
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.siyeh.igfixes.style.replace_with_string;
|
||||
|
||||
class Precedence2 {
|
||||
void foo() {
|
||||
long start = 0, end = 0;
|
||||
String string = "Time: " + (end - start) + ".";
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package com.siyeh.igfixes.style.replace_with_string;
|
||||
|
||||
class Precedence2 {
|
||||
void foo() {
|
||||
long start = 0, end = 0;
|
||||
String string = new StringB<caret>uilder().append("Time: ").append(end - start).append(".").toString();
|
||||
}
|
||||
}
|
||||
+1
@@ -35,4 +35,5 @@ public class StringBufferReplaceableWithStringFixTest extends IGQuickFixesTestCa
|
||||
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")); }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user