Fix "Too long character literal -> string" in ILLEGAL_ESCAPE

Related to #KT-23788
This commit is contained in:
Mikhail Glukhikh
2018-05-22 16:38:29 +03:00
parent 85cd1e938e
commit 2a9108bcd3
3 changed files with 14 additions and 1 deletions
@@ -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)
}
}
@@ -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")