diff --git a/plugins/kotlin/code-insight/impl-base/src/org/jetbrains/kotlin/idea/codeinsights/impl/base/StringTemplateUtils.kt b/plugins/kotlin/code-insight/impl-base/src/org/jetbrains/kotlin/idea/codeinsights/impl/base/StringTemplateUtils.kt index 3e40efacdec1..04049205498c 100644 --- a/plugins/kotlin/code-insight/impl-base/src/org/jetbrains/kotlin/idea/codeinsights/impl/base/StringTemplateUtils.kt +++ b/plugins/kotlin/code-insight/impl-base/src/org/jetbrains/kotlin/idea/codeinsights/impl/base/StringTemplateUtils.kt @@ -50,10 +50,11 @@ fun isStringPlusExpressionWithoutNewLineInOperands(expression: KtBinaryExpressio if (expression.getKtType()?.isString != true) return false val plusOperation = expression.operationReference.mainReference.resolveToSymbol() as? KtCallableSymbol val classContainingPlus = plusOperation?.getContainingSymbol() as? KtNamedClassOrObjectSymbol - if (classContainingPlus == null) { - return plusOperation?.callableIdIfNonLocal?.asSingleFqName()?.asString() == "kotlin.text.plus" + return if (classContainingPlus != null) { + classContainingPlus.classIdIfNonLocal?.asSingleFqName() == StandardNames.FqNames.string.toSafe() + } else { + plusOperation?.callableIdIfNonLocal?.asSingleFqName()?.asString() in listOf("kotlin.text.plus", "kotlin.plus") } - return classContainingPlus.classIdIfNonLocal?.asSingleFqName() == StandardNames.FqNames.string.toSafe() } /** diff --git a/plugins/kotlin/code-insight/intentions-k2/tests/test/org/jetbrains/kotlin/idea/k2/intentions/tests/K2IntentionTestGenerated.java b/plugins/kotlin/code-insight/intentions-k2/tests/test/org/jetbrains/kotlin/idea/k2/intentions/tests/K2IntentionTestGenerated.java index 5cf0844d177e..653c1f73580c 100644 --- a/plugins/kotlin/code-insight/intentions-k2/tests/test/org/jetbrains/kotlin/idea/k2/intentions/tests/K2IntentionTestGenerated.java +++ b/plugins/kotlin/code-insight/intentions-k2/tests/test/org/jetbrains/kotlin/idea/k2/intentions/tests/K2IntentionTestGenerated.java @@ -2067,6 +2067,11 @@ public abstract class K2IntentionTestGenerated extends AbstractK2IntentionTest { runTest("../../../idea/tests/testData/intentions/convertToStringTemplate/specialCharsInCharLiteral.kt"); } + @TestMetadata("startsWithNullableVariable.kt") + public void testStartsWithNullableVariable() throws Exception { + runTest("../../../idea/tests/testData/intentions/convertToStringTemplate/startsWithNullableVariable.kt"); + } + @TestMetadata("stringPlusStringLiteral.kt") public void testStringPlusStringLiteral() throws Exception { runTest("../../../idea/tests/testData/intentions/convertToStringTemplate/stringPlusStringLiteral.kt"); diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/intentions/K1IntentionTestGenerated.java b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/intentions/K1IntentionTestGenerated.java index 8febcc3e055a..0252c0919a46 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/intentions/K1IntentionTestGenerated.java +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/intentions/K1IntentionTestGenerated.java @@ -9608,6 +9608,11 @@ public abstract class K1IntentionTestGenerated extends AbstractK1IntentionTest { runTest("testData/intentions/convertToStringTemplate/specialCharsInCharLiteral.kt"); } + @TestMetadata("startsWithNullableVariable.kt") + public void testStartsWithNullableVariable() throws Exception { + runTest("testData/intentions/convertToStringTemplate/startsWithNullableVariable.kt"); + } + @TestMetadata("stringPlusStringLiteral.kt") public void testStringPlusStringLiteral() throws Exception { runTest("testData/intentions/convertToStringTemplate/stringPlusStringLiteral.kt"); diff --git a/plugins/kotlin/idea/tests/testData/intentions/convertToStringTemplate/startsWithNullableVariable.kt b/plugins/kotlin/idea/tests/testData/intentions/convertToStringTemplate/startsWithNullableVariable.kt new file mode 100644 index 000000000000..0dbcd434bff3 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/intentions/convertToStringTemplate/startsWithNullableVariable.kt @@ -0,0 +1,2 @@ +val foo: String? = "text" +val bar = foo + "bar" \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/intentions/convertToStringTemplate/startsWithNullableVariable.kt.after b/plugins/kotlin/idea/tests/testData/intentions/convertToStringTemplate/startsWithNullableVariable.kt.after new file mode 100644 index 000000000000..f5d1c405c257 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/intentions/convertToStringTemplate/startsWithNullableVariable.kt.after @@ -0,0 +1,2 @@ +val foo: String? = "text" +val bar = "${foo}bar" \ No newline at end of file diff --git a/plugins/kotlin/k2-fe10-bindings/test/org/jetbrains/kotlin/idea/k2/fe10bindings/inspections/Fe10BindingIntentionTestGenerated.java b/plugins/kotlin/k2-fe10-bindings/test/org/jetbrains/kotlin/idea/k2/fe10bindings/inspections/Fe10BindingIntentionTestGenerated.java index 1f1e9140639d..9bc833280cf4 100644 --- a/plugins/kotlin/k2-fe10-bindings/test/org/jetbrains/kotlin/idea/k2/fe10bindings/inspections/Fe10BindingIntentionTestGenerated.java +++ b/plugins/kotlin/k2-fe10-bindings/test/org/jetbrains/kotlin/idea/k2/fe10bindings/inspections/Fe10BindingIntentionTestGenerated.java @@ -686,6 +686,11 @@ public abstract class Fe10BindingIntentionTestGenerated extends AbstractFe10Bind runTest("../idea/tests/testData/intentions/convertToStringTemplate/specialCharsInCharLiteral.kt"); } + @TestMetadata("startsWithNullableVariable.kt") + public void testStartsWithNullableVariable() throws Exception { + runTest("../idea/tests/testData/intentions/convertToStringTemplate/startsWithNullableVariable.kt"); + } + @TestMetadata("stringPlusStringLiteral.kt") public void testStringPlusStringLiteral() throws Exception { runTest("../idea/tests/testData/intentions/convertToStringTemplate/stringPlusStringLiteral.kt");