diff --git a/plugins/kotlin/code-insight/impl-base/src/org/jetbrains/kotlin/idea/codeinsights/impl/base/StringTemplateUtils.kt b/plugins/kotlin/code-insight/impl-base/src/org/jetbrains/kotlin/idea/codeinsights/impl/base/StringTemplateUtils.kt index c60949b445a2..00cce4caab7a 100644 --- a/plugins/kotlin/code-insight/impl-base/src/org/jetbrains/kotlin/idea/codeinsights/impl/base/StringTemplateUtils.kt +++ b/plugins/kotlin/code-insight/impl-base/src/org/jetbrains/kotlin/idea/codeinsights/impl/base/StringTemplateUtils.kt @@ -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 { diff --git a/plugins/kotlin/code-insight/intentions-k2/tests/test/org/jetbrains/kotlin/idea/k2/intentions/tests/K2IntentionTestGenerated.java b/plugins/kotlin/code-insight/intentions-k2/tests/test/org/jetbrains/kotlin/idea/k2/intentions/tests/K2IntentionTestGenerated.java index 92eb1ba21d0b..74a63baa8715 100644 --- a/plugins/kotlin/code-insight/intentions-k2/tests/test/org/jetbrains/kotlin/idea/k2/intentions/tests/K2IntentionTestGenerated.java +++ b/plugins/kotlin/code-insight/intentions-k2/tests/test/org/jetbrains/kotlin/idea/k2/intentions/tests/K2IntentionTestGenerated.java @@ -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) diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/intentions/ToRawStringLiteralIntention.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/intentions/ToRawStringLiteralIntention.kt index bbbd4f0ac7dc..5f8ef381d3b6 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/intentions/ToRawStringLiteralIntention.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/intentions/ToRawStringLiteralIntention.kt @@ -37,7 +37,7 @@ class ToRawStringLiteralIntention : SelfTargetingOffsetIndependentIntention+ + " \n\nworld!" \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/intentions/convertToRawStringTemplate/consecutiveBreaks.kt.after b/plugins/kotlin/idea/tests/testData/intentions/convertToRawStringTemplate/consecutiveBreaks.kt.after new file mode 100644 index 000000000000..eb296b74526f --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/intentions/convertToRawStringTemplate/consecutiveBreaks.kt.after @@ -0,0 +1,4 @@ +val foo = """abc + + +world!""" \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/intentions/convertToRawStringTemplate/spaceBeforeBreak.kt b/plugins/kotlin/idea/tests/testData/intentions/convertToRawStringTemplate/spaceBeforeBreak.kt new file mode 100644 index 000000000000..7773cf2d7b04 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/intentions/convertToRawStringTemplate/spaceBeforeBreak.kt @@ -0,0 +1,2 @@ +val spaceBeforeLineBreak = "Hello, " + + " \nworld!" \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/intentions/convertToRawStringTemplate/spaceBeforeBreak.kt.after b/plugins/kotlin/idea/tests/testData/intentions/convertToRawStringTemplate/spaceBeforeBreak.kt.after new file mode 100644 index 000000000000..812d042e3e72 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/intentions/convertToRawStringTemplate/spaceBeforeBreak.kt.after @@ -0,0 +1,2 @@ +val spaceBeforeLineBreak = """Hello, +world!""" \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/intentions/toRawStringLiteral/trailingSpace.kt b/plugins/kotlin/idea/tests/testData/intentions/toRawStringLiteral/trailingSpace.kt index 71a2782e9ee6..6f5849681f9d 100644 --- a/plugins/kotlin/idea/tests/testData/intentions/toRawStringLiteral/trailingSpace.kt +++ b/plugins/kotlin/idea/tests/testData/intentions/toRawStringLiteral/trailingSpace.kt @@ -1,2 +1 @@ -// IS_APPLICABLE: false val v = "\"\\Hello, \nworld!\\\"" \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/intentions/toRawStringLiteral/trailingSpace.kt.after b/plugins/kotlin/idea/tests/testData/intentions/toRawStringLiteral/trailingSpace.kt.after new file mode 100644 index 000000000000..02f907b62933 --- /dev/null +++ b/plugins/kotlin/idea/tests/testData/intentions/toRawStringLiteral/trailingSpace.kt.after @@ -0,0 +1,2 @@ +val v = """"\Hello, +world!\"""" \ No newline at end of file