Fix AE exception in "Convert too long character literal to string"
So #KT-23608 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
1cbaab1531
commit
52d72ab920
@@ -10,7 +10,7 @@ import org.jetbrains.kotlin.psi.KtFile
|
|||||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||||
|
|
||||||
class TooLongCharLiteralToStringFix(
|
class TooLongCharLiteralToStringFix(
|
||||||
element: KtConstantExpression
|
element: KtConstantExpression
|
||||||
) : KotlinQuickFixAction<KtConstantExpression>(element) {
|
) : KotlinQuickFixAction<KtConstantExpression>(element) {
|
||||||
override fun getText(): String = "Convert too long character literal to string"
|
override fun getText(): String = "Convert too long character literal to string"
|
||||||
|
|
||||||
@@ -22,8 +22,9 @@ 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)
|
||||||
|
|
||||||
element.replace(newElement)
|
element.replace(newElement)
|
||||||
|
|||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
// "Convert too long character literal to string" "true"
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
'foo\"bar'<caret>
|
||||||
|
}
|
||||||
Vendored
+5
@@ -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")
|
||||||
|
|||||||
Reference in New Issue
Block a user