diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt index b05f7300156..66216a262cb 100644 --- a/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt +++ b/idea/src/org/jetbrains/kotlin/idea/intentions/ConvertToStringTemplateIntention.kt @@ -86,9 +86,10 @@ open class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentInte if (KotlinBuiltIns.isChar(type)) { val value = expressionText.removePrefix("'").removeSuffix("'") - return when (value) { // escape double quote and unescape single one + return when (value) { // escape double quote and unescape single one and $ "\"" -> "\\\"" "\\'" -> "'" + "$" -> if (forceBraces) "\\$" else "$" else -> value } } diff --git a/idea/testData/intentions/convertToStringTemplate/dollarSignChar.kt b/idea/testData/intentions/convertToStringTemplate/dollarSignChar.kt new file mode 100644 index 00000000000..35f844f6bae --- /dev/null +++ b/idea/testData/intentions/convertToStringTemplate/dollarSignChar.kt @@ -0,0 +1,3 @@ +fun test(): String { + return "" + '$' + "foo" + '$' + "bar" + '$' +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToStringTemplate/dollarSignChar.kt.after b/idea/testData/intentions/convertToStringTemplate/dollarSignChar.kt.after new file mode 100644 index 00000000000..9d483ef92cf --- /dev/null +++ b/idea/testData/intentions/convertToStringTemplate/dollarSignChar.kt.after @@ -0,0 +1,3 @@ +fun test(): String { + return "\$foo\$bar$" +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java index 2cc73b12b1b..3c28a663150 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/intentions/IntentionTestGenerated.java @@ -6768,6 +6768,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest { doTest(fileName); } + @TestMetadata("dollarSignChar.kt") + public void testDollarSignChar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/dollarSignChar.kt"); + doTest(fileName); + } + @TestMetadata("endOfLineComment.kt") public void testEndOfLineComment() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/endOfLineComment.kt");