mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Fix "Convert concatenation to raw string" intention with spaces
^KTIJ-24892 fixed closes https://github.com/JetBrains/intellij-community/pull/2383 GitOrigin-RevId: 400aa5dc4816c49e17ffe2ca781609d828683a0d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
564658a081
commit
d48b99349b
+1
-11
@@ -210,16 +210,6 @@ private fun convertContent(element: KtStringTemplateExpression): String {
|
||||
return StringUtilRt.convertLineSeparators(text, "\n")
|
||||
}
|
||||
|
||||
private fun hasTrailingSpaces(text: String): Boolean {
|
||||
var afterSpace = false
|
||||
for (c in text) {
|
||||
if ((c == '\n' || c == '\r') && afterSpace) return true
|
||||
afterSpace = c == ' ' || c == '\t'
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private fun KtStringTemplateEntry.value() = if (this is KtEscapeStringTemplateEntry) this.unescapedValue else text
|
||||
|
||||
fun KtStringTemplateExpression.canBeConvertedToStringLiteral(): Boolean {
|
||||
@@ -238,7 +228,7 @@ fun KtStringTemplateExpression.canBeConvertedToStringLiteral(): Boolean {
|
||||
}
|
||||
|
||||
val converted = convertContent(this)
|
||||
return !converted.contains("\"\"\"") && !hasTrailingSpaces(converted)
|
||||
return !converted.contains("\"\"\"")
|
||||
}
|
||||
|
||||
fun KtStringTemplateExpression.convertToStringLiteral(): KtExpression {
|
||||
|
||||
+10
@@ -3359,10 +3359,20 @@ public abstract class K2IntentionTestGenerated extends AbstractK2IntentionTest {
|
||||
runTest("../../../idea/tests/testData/intentions/convertToRawStringTemplate/basic.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("consecutiveBreaks.kt")
|
||||
public void testConsecutiveBreaks() throws Exception {
|
||||
runTest("../../../idea/tests/testData/intentions/convertToRawStringTemplate/consecutiveBreaks.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("octalEscape.kt")
|
||||
public void testOctalEscape() throws Exception {
|
||||
runTest("../../../idea/tests/testData/intentions/convertToRawStringTemplate/octalEscape.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("spaceBeforeBreak.kt")
|
||||
public void testSpaceBeforeBreak() throws Exception {
|
||||
runTest("../../../idea/tests/testData/intentions/convertToRawStringTemplate/spaceBeforeBreak.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+1
-11
@@ -37,7 +37,7 @@ class ToRawStringLiteralIntention : SelfTargetingOffsetIndependentIntention<KtSt
|
||||
}
|
||||
|
||||
val converted = convertContent(element)
|
||||
return !converted.contains("\"\"\"") && !hasTrailingSpaces(converted)
|
||||
return !converted.contains("\"\"\"")
|
||||
}
|
||||
|
||||
override fun applyTo(element: KtStringTemplateExpression, editor: Editor?) {
|
||||
@@ -78,15 +78,5 @@ class ToRawStringLiteralIntention : SelfTargetingOffsetIndependentIntention<KtSt
|
||||
return StringUtilRt.convertLineSeparators(text, "\n")
|
||||
}
|
||||
|
||||
private fun hasTrailingSpaces(text: String): Boolean {
|
||||
var afterSpace = false
|
||||
for (c in text) {
|
||||
if ((c == '\n' || c == '\r') && afterSpace) return true
|
||||
afterSpace = c == ' ' || c == '\t'
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private fun KtStringTemplateEntry.value() = if (this is KtEscapeStringTemplateEntry) this.unescapedValue else text
|
||||
}
|
||||
+10
@@ -8774,10 +8774,20 @@ public abstract class K1IntentionTestGenerated extends AbstractK1IntentionTest {
|
||||
runTest("testData/intentions/convertToRawStringTemplate/basic.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("consecutiveBreaks.kt")
|
||||
public void testConsecutiveBreaks() throws Exception {
|
||||
runTest("testData/intentions/convertToRawStringTemplate/consecutiveBreaks.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("octalEscape.kt")
|
||||
public void testOctalEscape() throws Exception {
|
||||
runTest("testData/intentions/convertToRawStringTemplate/octalEscape.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("spaceBeforeBreak.kt")
|
||||
public void testSpaceBeforeBreak() throws Exception {
|
||||
runTest("testData/intentions/convertToRawStringTemplate/spaceBeforeBreak.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
val foo = "abc\n" <caret>+
|
||||
" \n\nworld!"
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
val foo = """abc
|
||||
|
||||
|
||||
world!"""
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
val spaceBeforeLineBreak = "Hello, " <caret>+
|
||||
" \nworld!"
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
val spaceBeforeLineBreak = """Hello,
|
||||
world!"""
|
||||
@@ -1,2 +1 @@
|
||||
// IS_APPLICABLE: false
|
||||
val v = <caret>"\"\\Hello, \nworld!\\\""
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
val v = """"\Hello,
|
||||
world!\""""
|
||||
Reference in New Issue
Block a user