Unescape single quote when converting to string template

This commit is contained in:
Valentin Kipyatkov
2016-03-24 18:55:42 +03:00
parent 7f2ccb5613
commit e62c8a0860
4 changed files with 17 additions and 1 deletions
@@ -100,7 +100,11 @@ class ConvertToStringTemplateIntention : SelfTargetingOffsetIndependentIntention
if (KotlinBuiltIns.isChar(type)) {
val value = expressionText.removePrefix("'").removeSuffix("'")
return if (value == "\"") "\\\"" else value
return when (value) { // escape double quote and unescape single one
"\"" -> "\\\""
"\\'" -> "'"
else -> value
}
}
val constant = ConstantExpressionEvaluator.getConstant(expression, bindingContext)
@@ -0,0 +1,3 @@
fun test(p: String): String {
return <caret>p + '\''
}
@@ -0,0 +1,3 @@
fun test(p: String): String {
return <caret>"$p'"
}
@@ -4807,6 +4807,12 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
doTest(fileName);
}
@TestMetadata("unescapeSingleQuote.kt")
public void testUnescapeSingleQuote() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/intentions/convertToStringTemplate/unescapeSingleQuote.kt");
doTest(fileName);
}
}
@TestMetadata("idea/testData/intentions/declarations")