IDEA-118588 (Concatenation with empty string fails to fix an expression)

This commit is contained in:
Bas Leijdekkers
2013-12-23 13:39:57 +01:00
parent 183e4169e7
commit 01753c7677
4 changed files with 18 additions and 2 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2013 Dave Griffith, Bas Leijdekkers
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -91,7 +91,7 @@ public class TrivialStringConcatenationInspection extends BaseInspection {
replaced = true;
continue;
}
if (operand == expression) {
if (ParenthesesUtils.stripParentheses(operand) == expression) {
seenEmpty = true;
continue;
}
@@ -114,6 +114,7 @@ public class TrivialStringConcatenationInspection extends BaseInspection {
return text.toString();
}
@NonNls
static String buildReplacement(@NotNull PsiExpression operandToReplace, boolean seenString) {
if (ExpressionUtils.isNullLiteral(operandToReplace)) {
if (seenString) {
@@ -0,0 +1,7 @@
package com.siyeh.igfixes.performance.trivial_string_concatenation;
class Parentheses2 {
void m(String version) {
final String s = " (" + "Groovy " + (version) + ")";
}
}
@@ -0,0 +1,7 @@
package com.siyeh.igfixes.performance.trivial_string_concatenation;
class Parentheses2 {
void m(String version) {
final String s = " (" + (""<caret>) + "Groovy " + (version) + ")";
}
}
@@ -13,6 +13,7 @@ public class TrivialStringConcatenationFixTest extends IGQuickFixesTestCase {
}
public void testParentheses() { doTest("Replace concatenation with 'completedTiles + \" , \" + (totalTiles - completedTiles)'"); }
public void testParentheses2() { doTest("Replace concatenation with '\" (\" + \"Groovy \" + (version) + \")\"'"); }
public void testBinaryNull() { doTest("Replace concatenation with 'String.valueOf((Object)null)'"); }
public void testAtTheEnd() { doTest("Replace concatenation with '\"asdf\" + 1 + o'"); }
}