mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[Kotlin] Disable 'convert to raw string' for multi-dollar strings
KTIJ-30275 GitOrigin-RevId: 4f382fd5a5607727be6f125265e3c2b56edec96a
This commit is contained in:
committed by
intellij-monorepo-bot
parent
06fa278008
commit
0100b7005f
+5
-4
@@ -16,11 +16,12 @@ import org.jetbrains.kotlin.idea.codeinsight.utils.isToString
|
||||
import org.jetbrains.kotlin.idea.references.mainReference
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isSingleQuoted
|
||||
|
||||
private const val TRIPLE_DOUBLE_QUOTE = "\"\"\""
|
||||
|
||||
/**
|
||||
* Recursively visits all operands of binary [expression] with plus and,
|
||||
* Recursively visits all operands of binary expression with plus and,
|
||||
* returns true if all operands do not have a new line. Otherwise, returns false.
|
||||
*/
|
||||
fun KtExpression.containNoNewLine(): Boolean {
|
||||
@@ -180,7 +181,7 @@ private fun foldOperandsOfBinaryExpression(left: KtExpression?, right: String, f
|
||||
context(KaSession)
|
||||
fun buildStringTemplateForBinaryExpression(expression: KtBinaryExpression): KtStringTemplateExpression {
|
||||
val rightText = buildStringTemplateForExpression(expression.right, forceBraces = false, nextText = null)
|
||||
return foldOperandsOfBinaryExpression(expression.left, rightText, KtPsiFactory(expression))
|
||||
return foldOperandsOfBinaryExpression(expression.left, rightText, KtPsiFactory(expression.project))
|
||||
}
|
||||
|
||||
context(KaSession)
|
||||
@@ -223,8 +224,8 @@ fun KtStringTemplateExpression.canBeConvertedToStringLiteral(): Boolean {
|
||||
// the replacement may make things even worse, suppress the action
|
||||
return false
|
||||
}
|
||||
val text = text
|
||||
if (text.startsWith("\"\"\"")) return false // already raw
|
||||
if (!isSingleQuoted()) return false // already raw
|
||||
if (interpolationPrefix != null) return false // unsupported
|
||||
|
||||
val escapeEntries = entries.filterIsInstance<KtEscapeStringTemplateEntry>()
|
||||
for (entry in escapeEntries) {
|
||||
|
||||
+10
@@ -5193,6 +5193,11 @@ public abstract class K2IntentionTestGenerated extends AbstractK2IntentionTest {
|
||||
runTest("../../../idea/tests/testData/intentions/convertToRawStringTemplate/consecutiveBreaks.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("KTIJ-30275.kt")
|
||||
public void testKTIJ_30275() throws Exception {
|
||||
runTest("../../../idea/tests/testData/intentions/convertToRawStringTemplate/KTIJ-30275.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("multiDollar.kt")
|
||||
public void testMultiDollar() throws Exception {
|
||||
runTest("../../../idea/tests/testData/intentions/convertToRawStringTemplate/multiDollar.kt");
|
||||
@@ -5267,6 +5272,11 @@ public abstract class K2IntentionTestGenerated extends AbstractK2IntentionTest {
|
||||
runTest("../../../idea/tests/testData/intentions/toRawStringLiteral/dollar2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("KTIJ-30275.kt")
|
||||
public void testKTIJ_30275() throws Exception {
|
||||
runTest("../../../idea/tests/testData/intentions/toRawStringLiteral/KTIJ-30275.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("quotesAndSlashes.kt")
|
||||
public void testQuotesAndSlashes() throws Exception {
|
||||
runTest("../../../idea/tests/testData/intentions/toRawStringLiteral/quotesAndSlashes.kt");
|
||||
|
||||
+10
@@ -9597,6 +9597,11 @@ public abstract class K1IntentionTestGenerated extends AbstractK1IntentionTest {
|
||||
runTest("testData/intentions/convertToRawStringTemplate/consecutiveBreaks.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("KTIJ-30275.kt")
|
||||
public void testKTIJ_30275() throws Exception {
|
||||
runTest("testData/intentions/convertToRawStringTemplate/KTIJ-30275.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("multiDollar.kt")
|
||||
public void testMultiDollar() throws Exception {
|
||||
runTest("testData/intentions/convertToRawStringTemplate/multiDollar.kt");
|
||||
@@ -19519,6 +19524,11 @@ public abstract class K1IntentionTestGenerated extends AbstractK1IntentionTest {
|
||||
runTest("testData/intentions/toRawStringLiteral/dollar2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("KTIJ-30275.kt")
|
||||
public void testKTIJ_30275() throws Exception {
|
||||
runTest("testData/intentions/toRawStringLiteral/KTIJ-30275.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("quotesAndSlashes.kt")
|
||||
public void testQuotesAndSlashes() throws Exception {
|
||||
runTest("testData/intentions/toRawStringLiteral/quotesAndSlashes.kt");
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// IS_APPLICABLE: false
|
||||
// SKIP_ERRORS_BEFORE
|
||||
// SKIP_ERRORS_AFTER
|
||||
// SKIP_WARNINGS_AFTER
|
||||
// COMPILER_ARGUMENTS: -Xmulti-dollar-interpolation
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val x = "x"
|
||||
val y = $$"$${x.length}<caret>"
|
||||
|
||||
println(y) //ouput is 1
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
// IS_APPLICABLE: false
|
||||
// IGNORE_K1
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val x = "x"
|
||||
val y = $$"$${x.<caret>length}"
|
||||
|
||||
println(y) //ouput is 1
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user