Fix AE exception in "Convert too long character literal to string"

So #KT-23608 Fixed
This commit is contained in:
Toshiaki Kameyama
2018-04-06 06:07:32 +03:00
committed by Mikhail Glukhikh
parent 1cbaab1531
commit 52d72ab920
4 changed files with 20 additions and 3 deletions
@@ -23,6 +23,7 @@ class TooLongCharLiteralToStringFix(
val newStringContent = text val newStringContent = text
.slice(1..text.length - 2) .slice(1..text.length - 2)
.replace("\\\"", "\"")
.replace("\"", "\\\"") .replace("\"", "\\\"")
val newElement = KtPsiFactory(element).createStringTemplate(newStringContent) val newElement = KtPsiFactory(element).createStringTemplate(newStringContent)
@@ -0,0 +1,5 @@
// "Convert too long character literal to string" "true"
fun foo() {
'foo\"bar'<caret>
}
@@ -0,0 +1,5 @@
// "Convert too long character literal to string" "true"
fun foo() {
"foo\"bar"
}
@@ -11297,6 +11297,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/tooLongCharLiteralToString/doubleQuotesShouldBeEscaped.kt"); String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/tooLongCharLiteralToString/doubleQuotesShouldBeEscaped.kt");
doTest(fileName); doTest(fileName);
} }
@TestMetadata("ecapedDoubleQuotesShouldNotBeEscaped.kt")
public void testEcapedDoubleQuotesShouldNotBeEscaped() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/tooLongCharLiteralToString/ecapedDoubleQuotesShouldNotBeEscaped.kt");
doTest(fileName);
}
} }
@TestMetadata("idea/testData/quickfix/typeAddition") @TestMetadata("idea/testData/quickfix/typeAddition")