Process '$' correctly in "Convert concatenation to template"

So #KT-12226 Fixed
This commit is contained in:
Toshiaki Kameyama
2018-03-14 12:46:10 +03:00
committed by Mikhail Glukhikh
parent 3b2bbee595
commit 66906e2c80
4 changed files with 14 additions and 1 deletions
@@ -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
}
}
@@ -0,0 +1,3 @@
fun test(): String {
return "" + '$' + "foo" + '$' + "bar" + '$'<caret>
}
@@ -0,0 +1,3 @@
fun test(): String {
return "\$foo\$bar$"<caret>
}
@@ -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");