From 66906e2c807c373dbecfd7cfee1bdf6f35776472 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Wed, 14 Mar 2018 12:46:10 +0300 Subject: [PATCH] Process '$' correctly in "Convert concatenation to template" So #KT-12226 Fixed --- .../idea/intentions/ConvertToStringTemplateIntention.kt | 3 ++- .../intentions/convertToStringTemplate/dollarSignChar.kt | 3 +++ .../convertToStringTemplate/dollarSignChar.kt.after | 3 +++ .../kotlin/idea/intentions/IntentionTestGenerated.java | 6 ++++++ 4 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 idea/testData/intentions/convertToStringTemplate/dollarSignChar.kt create mode 100644 idea/testData/intentions/convertToStringTemplate/dollarSignChar.kt.after 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");