Remove ConvertTrimIndentToTrimMarginIntention
Relates to #KT-31502
This commit is contained in:
@@ -1683,11 +1683,6 @@
|
||||
<category>Kotlin</category>
|
||||
</intentionAction>
|
||||
|
||||
<intentionAction>
|
||||
<className>org.jetbrains.kotlin.idea.intentions.ConvertTrimIndentToTrimMarginIntention</className>
|
||||
<category>Kotlin</category>
|
||||
</intentionAction>
|
||||
|
||||
<intentionAction>
|
||||
<className>org.jetbrains.kotlin.idea.intentions.ConvertPropertyGetterToInitializerIntention</className>
|
||||
<category>Kotlin</category>
|
||||
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
fun test() {
|
||||
val x =
|
||||
<spot>"""
|
||||
|a
|
||||
|b
|
||||
""".trimMargin()</spot>
|
||||
}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
fun test() {
|
||||
val x =
|
||||
<spot>"""
|
||||
a
|
||||
b
|
||||
""".trimIndent()</spot>
|
||||
}
|
||||
-5
@@ -1,5 +0,0 @@
|
||||
<html>
|
||||
<body>
|
||||
This intention converts an <b>trimIndent()</b> call to an <b>trimMargin()</b> call.
|
||||
</body>
|
||||
</html>
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.idea.intentions
|
||||
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
import org.jetbrains.kotlin.psi.KtStringTemplateExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelector
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
|
||||
class ConvertTrimIndentToTrimMarginIntention : SelfTargetingIntention<KtCallExpression>(
|
||||
KtCallExpression::class.java, "Convert to 'trimMargin'"
|
||||
) {
|
||||
override fun isApplicableTo(element: KtCallExpression, caretOffset: Int): Boolean {
|
||||
val template = (element.getQualifiedExpressionForSelector()?.receiverExpression as? KtStringTemplateExpression) ?: return false
|
||||
if (!template.text.startsWith("\"\"\"")) return false
|
||||
|
||||
val callee = element.calleeExpression ?: return false
|
||||
if (callee.text != "trimIndent" || callee.getCallableDescriptor()?.fqNameSafe != FqName("kotlin.text.trimIndent")) return false
|
||||
|
||||
val entries = template.entries
|
||||
return listOfNotNull(entries.firstOrNull(), entries.lastOrNull()).all { it.text.isLineBreakOrBlank() }
|
||||
}
|
||||
|
||||
override fun applyTo(element: KtCallExpression, editor: Editor?) {
|
||||
val qualifiedExpression = element.getQualifiedExpressionForSelector()
|
||||
val template = (qualifiedExpression?.receiverExpression as? KtStringTemplateExpression) ?: return
|
||||
|
||||
val indent = template.entries.asSequence().mapNotNull { stringTemplateEntry ->
|
||||
val text = stringTemplateEntry.text
|
||||
if (text.isLineBreakOrBlank()) null else text.takeWhile { it.isWhitespace() }
|
||||
}.minBy { it.length } ?: ""
|
||||
|
||||
val newTemplate = buildString {
|
||||
template.entries.forEach { entry ->
|
||||
val text = entry.text
|
||||
if (text.isLineBreakOrBlank()) {
|
||||
append(text)
|
||||
} else {
|
||||
append(indent)
|
||||
append("|")
|
||||
append(text.drop(indent.length))
|
||||
}
|
||||
}
|
||||
}
|
||||
qualifiedExpression.replace(KtPsiFactory(element).createExpression("\"\"\"$newTemplate\"\"\".trimMargin()"))
|
||||
}
|
||||
}
|
||||
|
||||
private fun String.isLineBreakOrBlank() = this == "\n" || this.isBlank()
|
||||
@@ -1 +0,0 @@
|
||||
org.jetbrains.kotlin.idea.intentions.ConvertTrimIndentToTrimMarginIntention
|
||||
@@ -1,9 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun test() {
|
||||
val x =
|
||||
"""
|
||||
a
|
||||
b
|
||||
c
|
||||
""".<caret>trimIndent()
|
||||
}
|
||||
-9
@@ -1,9 +0,0 @@
|
||||
// WITH_RUNTIME
|
||||
fun test() {
|
||||
val x =
|
||||
"""
|
||||
|a
|
||||
| b
|
||||
| c
|
||||
""".trimMargin()
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
fun test() {
|
||||
val x =
|
||||
"""1
|
||||
a
|
||||
b
|
||||
""".<caret>trimIndent()
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
fun test() {
|
||||
val x =
|
||||
"""
|
||||
a
|
||||
b
|
||||
1""".<caret>trimIndent()
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
// IS_APPLICABLE: false
|
||||
// WITH_RUNTIME
|
||||
fun test() {
|
||||
val x = " a".<caret>trimIndent()
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// INTENTION_TEXT: "Convert to 'trimMargin'"
|
||||
// WITH_RUNTIME
|
||||
fun test() {
|
||||
val x =
|
||||
"""
|
||||
a
|
||||
|
||||
b
|
||||
""".<caret>trimIndent()
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
// INTENTION_TEXT: "Convert to 'trimMargin'"
|
||||
// WITH_RUNTIME
|
||||
fun test() {
|
||||
val x =
|
||||
"""
|
||||
|a
|
||||
|
||||
|b
|
||||
""".trimMargin()
|
||||
}
|
||||
@@ -8132,44 +8132,6 @@ public class IntentionTestGenerated extends AbstractIntentionTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/intentions/convertTrimIndentToTrimMargin")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ConvertTrimIndentToTrimMargin extends AbstractIntentionTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInConvertTrimIndentToTrimMargin() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/intentions/convertTrimIndentToTrimMargin"), Pattern.compile("^([\\w\\-_]+)\\.(kt|kts)$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("differentIndent.kt")
|
||||
public void testDifferentIndent() throws Exception {
|
||||
runTest("idea/testData/intentions/convertTrimIndentToTrimMargin/differentIndent.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("notBlankFirst.kt")
|
||||
public void testNotBlankFirst() throws Exception {
|
||||
runTest("idea/testData/intentions/convertTrimIndentToTrimMargin/notBlankFirst.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("notBlankLast.kt")
|
||||
public void testNotBlankLast() throws Exception {
|
||||
runTest("idea/testData/intentions/convertTrimIndentToTrimMargin/notBlankLast.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("notRawString.kt")
|
||||
public void testNotRawString() throws Exception {
|
||||
runTest("idea/testData/intentions/convertTrimIndentToTrimMargin/notRawString.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simple.kt")
|
||||
public void testSimple() throws Exception {
|
||||
runTest("idea/testData/intentions/convertTrimIndentToTrimMargin/simple.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/intentions/convertTrimMarginToTrimIndent")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user