Fix "Too long character literal -> string" in ILLEGAL_ESCAPE
Related to #KT-23788
This commit is contained in:
@@ -4,7 +4,6 @@ import com.intellij.codeInsight.intention.IntentionAction
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.psi.KtConstantExpression
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
@@ -36,6 +35,7 @@ class TooLongCharLiteralToStringFix(
|
||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||
val element = diagnostic.psiElement as? KtConstantExpression ?: return null
|
||||
if (element.text == "'\\'") return null
|
||||
if (element.text.startsWith("\"")) return null
|
||||
return TooLongCharLiteralToStringFix(element = element)
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Convert too long character literal to string" "false"
|
||||
// ACTION: Introduce local variable
|
||||
// ACTION: To raw string literal
|
||||
// ERROR: Illegal escape: '\ '
|
||||
|
||||
fun foo() {
|
||||
"\ <caret>"
|
||||
}
|
||||
@@ -10525,6 +10525,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
public void testStartWithBackslash() throws Exception {
|
||||
runTest("idea/testData/quickfix/tooLongCharLiteralToString/startWithBackslash.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("startWithBackslashInString.kt")
|
||||
public void testStartWithBackslashInString() throws Exception {
|
||||
runTest("idea/testData/quickfix/tooLongCharLiteralToString/startWithBackslashInString.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/typeAddition")
|
||||
|
||||
Reference in New Issue
Block a user