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
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtPsiFactory
class TooLongCharLiteralToStringFix(
element: KtConstantExpression
element: KtConstantExpression
) : KotlinQuickFixAction<KtConstantExpression>(element) {
override fun getText(): String = "Convert too long character literal to string"
@@ -22,8 +22,9 @@ class TooLongCharLiteralToStringFix(
}
val newStringContent = text
.slice(1..text.length - 2)
.replace("\"", "\\\"")
.slice(1..text.length - 2)
.replace("\\\"", "\"")
.replace("\"", "\\\"")
val newElement = KtPsiFactory(element).createStringTemplate(newStringContent)
element.replace(newElement)
@@ -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");
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")