Add "Too long character literal -> string" fix to ILLEGAL_ESCAPE error
So #KT-23788 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
6d39eb9239
commit
85cd1e938e
@@ -484,6 +484,7 @@ class QuickFixRegistrar : QuickFixContributor {
|
|||||||
CANNOT_CHECK_FOR_ERASED.registerFactory(MakeTypeParameterReifiedAndFunctionInlineFix)
|
CANNOT_CHECK_FOR_ERASED.registerFactory(MakeTypeParameterReifiedAndFunctionInlineFix)
|
||||||
|
|
||||||
TOO_MANY_CHARACTERS_IN_CHARACTER_LITERAL.registerFactory(TooLongCharLiteralToStringFix)
|
TOO_MANY_CHARACTERS_IN_CHARACTER_LITERAL.registerFactory(TooLongCharLiteralToStringFix)
|
||||||
|
ILLEGAL_ESCAPE.registerFactory(TooLongCharLiteralToStringFix)
|
||||||
|
|
||||||
UNUSED_VALUE.registerFactory(RemoveUnusedValueFix)
|
UNUSED_VALUE.registerFactory(RemoveUnusedValueFix)
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ class TooLongCharLiteralToStringFix(
|
|||||||
|
|
||||||
companion object Factory : KotlinSingleIntentionActionFactory() {
|
companion object Factory : KotlinSingleIntentionActionFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
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)
|
return TooLongCharLiteralToStringFix(element = element)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// "Convert too long character literal to string" "false"
|
||||||
|
// ACTION: Introduce local variable
|
||||||
|
// ERROR: Illegal escape: ''\''
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
'\'<caret>
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// "Convert too long character literal to string" "true"
|
||||||
|
// ERROR: Illegal escape: '\ '
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
'\ bar<caret>'
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// "Convert too long character literal to string" "true"
|
||||||
|
// ERROR: Illegal escape: '\ '
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
"\ bar"
|
||||||
|
}
|
||||||
@@ -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);
|
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")
|
@TestMetadata("backslashShouldNotBeEscaped.kt")
|
||||||
public void testBackslashShouldNotBeEscaped() throws Exception {
|
public void testBackslashShouldNotBeEscaped() throws Exception {
|
||||||
runTest("idea/testData/quickfix/tooLongCharLiteralToString/backslashShouldNotBeEscaped.kt");
|
runTest("idea/testData/quickfix/tooLongCharLiteralToString/backslashShouldNotBeEscaped.kt");
|
||||||
@@ -10515,6 +10520,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
public void testEcapedDoubleQuotesShouldNotBeEscaped() throws Exception {
|
public void testEcapedDoubleQuotesShouldNotBeEscaped() throws Exception {
|
||||||
runTest("idea/testData/quickfix/tooLongCharLiteralToString/ecapedDoubleQuotesShouldNotBeEscaped.kt");
|
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")
|
@TestMetadata("idea/testData/quickfix/typeAddition")
|
||||||
|
|||||||
Reference in New Issue
Block a user