[kotlin] IndentRawStringIntention to k2

^KTIJ-22963 Fixed

GitOrigin-RevId: 4f627ead2f85e2c81a6fe85fb0bf62e2fa87d1ba
This commit is contained in:
vlad.koshkin
2023-12-11 12:35:25 +00:00
committed by intellij-monorepo-bot
parent 21025d5b0d
commit 703e934506
20 changed files with 100 additions and 56 deletions
@@ -189,5 +189,11 @@
<categoryKey>group.names.kotlin</categoryKey>
</intentionAction>
<intentionAction>
<language>kotlin</language>
<className>org.jetbrains.kotlin.idea.codeInsight.intentions.shared.IndentRawStringIntention</className>
<bundleName>messages.KotlinBundle</bundleName>
<categoryKey>group.names.kotlin</categoryKey>
</intentionAction>
</extensions>
</idea-plugin>
@@ -1,6 +1,6 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.kotlin.idea.intentions
package org.jetbrains.kotlin.idea.codeInsight.intentions.shared
import com.intellij.application.options.CodeStyle
import com.intellij.openapi.editor.Editor
@@ -16,11 +16,13 @@ import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForReceiver
import org.jetbrains.kotlin.psi.psiUtil.parents
import org.jetbrains.kotlin.psi.psiUtil.startOffset
private const val QTS = "\"\"\""
class IndentRawStringIntention : SelfTargetingOffsetIndependentIntention<KtStringTemplateExpression>(
KtStringTemplateExpression::class.java, KotlinBundle.lazyMessage("indent.raw.string")
) {
override fun isApplicableTo(element: KtStringTemplateExpression): Boolean {
if (!element.text.startsWith("\"\"\"")) return false
if (!element.text.startsWith(QTS)) return false
if (element.parents.any { it is KtAnnotationEntry || (it as? KtProperty)?.hasModifier(KtTokens.CONST_KEYWORD) == true }) return false
if (element.getQualifiedExpressionForReceiver() != null) return false
val entries = element.entries
@@ -44,7 +46,6 @@ class IndentRawStringIntention : SelfTargetingOffsetIndependentIntention<KtStrin
}
}
element.replace(KtPsiFactory(project).createExpression("\"\"\"$newString\"\"\".trimIndent()"))
element.replace(KtPsiFactory(project).createExpression("$QTS${newString}$QTS.trimIndent()"))
}
}
@@ -778,6 +778,49 @@ public abstract class SharedK1IntentionTestGenerated extends AbstractSharedK1Int
}
}
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../testData/intentions/indentRawString")
public static class IndentRawString extends AbstractSharedK1IntentionTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("annotationEntry.kt")
public void testAnnotationEntry() throws Exception {
runTest("../testData/intentions/indentRawString/annotationEntry.kt");
}
@TestMetadata("const.kt")
public void testConst() throws Exception {
runTest("../testData/intentions/indentRawString/const.kt");
}
@TestMetadata("hasIndent.kt")
public void testHasIndent() throws Exception {
runTest("../testData/intentions/indentRawString/hasIndent.kt");
}
@TestMetadata("notRawString.kt")
public void testNotRawString() throws Exception {
runTest("../testData/intentions/indentRawString/notRawString.kt");
}
@TestMetadata("receiver.kt")
public void testReceiver() throws Exception {
runTest("../testData/intentions/indentRawString/receiver.kt");
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("../testData/intentions/indentRawString/simple.kt");
}
@TestMetadata("singleLine.kt")
public void testSingleLine() throws Exception {
runTest("../testData/intentions/indentRawString/singleLine.kt");
}
}
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../testData/intentions/operatorToFunction")
public static class OperatorToFunction extends AbstractSharedK1IntentionTest {
@@ -778,6 +778,49 @@ public abstract class SharedK2IntentionTestGenerated extends AbstractSharedK2Int
}
}
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../testData/intentions/indentRawString")
public static class IndentRawString extends AbstractSharedK2IntentionTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("annotationEntry.kt")
public void testAnnotationEntry() throws Exception {
runTest("../testData/intentions/indentRawString/annotationEntry.kt");
}
@TestMetadata("const.kt")
public void testConst() throws Exception {
runTest("../testData/intentions/indentRawString/const.kt");
}
@TestMetadata("hasIndent.kt")
public void testHasIndent() throws Exception {
runTest("../testData/intentions/indentRawString/hasIndent.kt");
}
@TestMetadata("notRawString.kt")
public void testNotRawString() throws Exception {
runTest("../testData/intentions/indentRawString/notRawString.kt");
}
@TestMetadata("receiver.kt")
public void testReceiver() throws Exception {
runTest("../testData/intentions/indentRawString/receiver.kt");
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("../testData/intentions/indentRawString/simple.kt");
}
@TestMetadata("singleLine.kt")
public void testSingleLine() throws Exception {
runTest("../testData/intentions/indentRawString/singleLine.kt");
}
}
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("../testData/intentions/operatorToFunction")
public static class OperatorToFunction extends AbstractSharedK2IntentionTest {
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.codeInsight.intentions.shared.IndentRawStringIntention
@@ -11040,49 +11040,6 @@ public abstract class K1IntentionTestGenerated extends AbstractK1IntentionTest {
}
}
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("testData/intentions/indentRawString")
public static class IndentRawString extends AbstractK1IntentionTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
}
@TestMetadata("annotationEntry.kt")
public void testAnnotationEntry() throws Exception {
runTest("testData/intentions/indentRawString/annotationEntry.kt");
}
@TestMetadata("const.kt")
public void testConst() throws Exception {
runTest("testData/intentions/indentRawString/const.kt");
}
@TestMetadata("hasIndent.kt")
public void testHasIndent() throws Exception {
runTest("testData/intentions/indentRawString/hasIndent.kt");
}
@TestMetadata("notRawString.kt")
public void testNotRawString() throws Exception {
runTest("testData/intentions/indentRawString/notRawString.kt");
}
@TestMetadata("receiver.kt")
public void testReceiver() throws Exception {
runTest("testData/intentions/indentRawString/receiver.kt");
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("testData/intentions/indentRawString/simple.kt");
}
@TestMetadata("singleLine.kt")
public void testSingleLine() throws Exception {
runTest("testData/intentions/indentRawString/singleLine.kt");
}
}
@RunWith(JUnit3RunnerWithInners.class)
@TestMetadata("testData/intentions/infixCallToOrdinary")
public static class InfixCallToOrdinary extends AbstractK1IntentionTest {
@@ -1 +0,0 @@
org.jetbrains.kotlin.idea.intentions.IndentRawStringIntention
@@ -2,6 +2,7 @@
package org.jetbrains.kotlin.idea.j2k.post.processing
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.idea.codeInsight.intentions.shared.IndentRawStringIntention
import org.jetbrains.kotlin.idea.codeInsight.intentions.shared.RemoveUnnecessaryParenthesesIntention
import org.jetbrains.kotlin.idea.codeinsight.utils.NegatedBinaryExpressionSimplificationUtils.canBeSimplifiedWithoutChangingSemantics
import org.jetbrains.kotlin.idea.codeinsights.impl.base.KotlinInspectionFacade
@@ -819,13 +819,6 @@
<categoryKey>group.names.kotlin</categoryKey>
</intentionAction>
<intentionAction>
<language>kotlin</language>
<className>org.jetbrains.kotlin.idea.intentions.IndentRawStringIntention</className>
<bundleName>messages.KotlinBundle</bundleName>
<categoryKey>group.names.kotlin</categoryKey>
</intentionAction>
<intentionAction>
<language>kotlin</language>
<className>org.jetbrains.kotlin.idea.intentions.ConvertVarargParameterToArrayIntention</className>