diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index 5632f1f3f60..96f6ed68f54 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -484,6 +484,7 @@ class QuickFixRegistrar : QuickFixContributor { CANNOT_CHECK_FOR_ERASED.registerFactory(MakeTypeParameterReifiedAndFunctionInlineFix) TOO_MANY_CHARACTERS_IN_CHARACTER_LITERAL.registerFactory(TooLongCharLiteralToStringFix) + ILLEGAL_ESCAPE.registerFactory(TooLongCharLiteralToStringFix) UNUSED_VALUE.registerFactory(RemoveUnusedValueFix) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/TooLongCharLiteralToStringFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/TooLongCharLiteralToStringFix.kt index 377dd32beb3..ff1bdf184e4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/TooLongCharLiteralToStringFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/TooLongCharLiteralToStringFix.kt @@ -34,7 +34,8 @@ class TooLongCharLiteralToStringFix( companion object Factory : KotlinSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction? { - val element = Errors.TOO_MANY_CHARACTERS_IN_CHARACTER_LITERAL.cast(diagnostic).psiElement + val element = diagnostic.psiElement as? KtConstantExpression ?: return null + if (element.text == "'\\'") return null return TooLongCharLiteralToStringFix(element = element) } } diff --git a/idea/testData/quickfix/tooLongCharLiteralToString/backslash.kt b/idea/testData/quickfix/tooLongCharLiteralToString/backslash.kt new file mode 100644 index 00000000000..93ef5f5f78d --- /dev/null +++ b/idea/testData/quickfix/tooLongCharLiteralToString/backslash.kt @@ -0,0 +1,7 @@ +// "Convert too long character literal to string" "false" +// ACTION: Introduce local variable +// ERROR: Illegal escape: ''\'' + +fun foo() { + '\' +} \ No newline at end of file diff --git a/idea/testData/quickfix/tooLongCharLiteralToString/startWithBackslash.kt b/idea/testData/quickfix/tooLongCharLiteralToString/startWithBackslash.kt new file mode 100644 index 00000000000..85e4be723e7 --- /dev/null +++ b/idea/testData/quickfix/tooLongCharLiteralToString/startWithBackslash.kt @@ -0,0 +1,6 @@ +// "Convert too long character literal to string" "true" +// ERROR: Illegal escape: '\ ' + +fun foo() { + '\ bar' +} \ No newline at end of file diff --git a/idea/testData/quickfix/tooLongCharLiteralToString/startWithBackslash.kt.after b/idea/testData/quickfix/tooLongCharLiteralToString/startWithBackslash.kt.after new file mode 100644 index 00000000000..fe1a948c5c3 --- /dev/null +++ b/idea/testData/quickfix/tooLongCharLiteralToString/startWithBackslash.kt.after @@ -0,0 +1,6 @@ +// "Convert too long character literal to string" "true" +// ERROR: Illegal escape: '\ ' + +fun foo() { + "\ bar" +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 95635f22616..11081f655ee 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -10496,6 +10496,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/tooLongCharLiteralToString"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true); } + @TestMetadata("backslash.kt") + public void testBackslash() throws Exception { + runTest("idea/testData/quickfix/tooLongCharLiteralToString/backslash.kt"); + } + @TestMetadata("backslashShouldNotBeEscaped.kt") public void testBackslashShouldNotBeEscaped() throws Exception { runTest("idea/testData/quickfix/tooLongCharLiteralToString/backslashShouldNotBeEscaped.kt"); @@ -10515,6 +10520,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { public void testEcapedDoubleQuotesShouldNotBeEscaped() throws Exception { runTest("idea/testData/quickfix/tooLongCharLiteralToString/ecapedDoubleQuotesShouldNotBeEscaped.kt"); } + + @TestMetadata("startWithBackslash.kt") + public void testStartWithBackslash() throws Exception { + runTest("idea/testData/quickfix/tooLongCharLiteralToString/startWithBackslash.kt"); + } } @TestMetadata("idea/testData/quickfix/typeAddition")