mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Port WrapWithParenthesesFix to K2
^KTIJ-29545 GitOrigin-RevId: ccfc6e8e6a8759f57177e98a9adb0d3b5a8b73e9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1d1d3d2238
commit
811ea2fea6
+2
@@ -170,6 +170,8 @@ class KotlinK2QuickFixRegistrar : KotlinQuickFixRegistrar() {
|
||||
registerFactory(CallFromPublicInlineFixFactories.protectedCallFromPublicInlineErrorFixFactory)
|
||||
registerFactory(CallFromPublicInlineFixFactories.superCallFromPublicInlineFixFactory)
|
||||
registerFactory(ConfusingBranchConditionErrorFixFactories.wrapExpressionInParenthesesFixFactory)
|
||||
registerFactory(WrapWithParenthesesFixFactories.suspendFixFactory)
|
||||
registerFactory(WrapWithParenthesesFixFactories.suspendFunErrorFixFactory)
|
||||
}
|
||||
|
||||
private val addAbstract = KtQuickFixesListBuilder.registerPsiQuickFix {
|
||||
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.k2.codeinsight.fixes
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory
|
||||
import org.jetbrains.kotlin.idea.quickfix.WrapWithParenthesesFix
|
||||
import org.jetbrains.kotlin.psi.KtBinaryExpression
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
internal object WrapWithParenthesesFixFactories {
|
||||
|
||||
val suspendFixFactory = KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.ModifierFormForNonBuiltInSuspend ->
|
||||
listOfNotNull(
|
||||
createFixIfAvailable(diagnostic.psi)
|
||||
)
|
||||
}
|
||||
|
||||
val suspendFunErrorFixFactory =
|
||||
KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.ModifierFormForNonBuiltInSuspendFunError ->
|
||||
listOfNotNull(
|
||||
createFixIfAvailable(diagnostic.psi)
|
||||
)
|
||||
}
|
||||
|
||||
private fun createFixIfAvailable(element: PsiElement): WrapWithParenthesesFix? {
|
||||
return element
|
||||
.safeAs<KtBinaryExpression>()
|
||||
?.takeIf { it.operationReference.text == "suspend" }
|
||||
?.right
|
||||
?.let { WrapWithParenthesesFix(it) } ?: return null
|
||||
}
|
||||
}
|
||||
+22
@@ -11225,7 +11225,29 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../../idea/tests/testData/quickfix/wrapArgumentWithParentheses")
|
||||
public static class WrapArgumentWithParentheses extends AbstractHighLevelQuickFixTest {
|
||||
@java.lang.Override
|
||||
@org.jetbrains.annotations.NotNull
|
||||
public final KotlinPluginMode getPluginMode() {
|
||||
return KotlinPluginMode.K2;
|
||||
}
|
||||
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("ModifierFormForNonBuiltInSuspend.kt")
|
||||
public void testModifierFormForNonBuiltInSuspend() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/wrapArgumentWithParentheses/ModifierFormForNonBuiltInSuspend.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ModifierFormForNonBuiltInSuspendFun.kt")
|
||||
public void testModifierFormForNonBuiltInSuspendFun() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/wrapArgumentWithParentheses/ModifierFormForNonBuiltInSuspendFun.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../../idea/tests/testData/quickfix/wrapWhenExpressionInParentheses")
|
||||
|
||||
+2
-1
@@ -5,4 +5,5 @@ fun foo() {
|
||||
1 suspend<caret> {}
|
||||
}
|
||||
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.WrapWithParenthesesFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.WrapWithParenthesesFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.WrapWithParenthesesFix
|
||||
+2
-1
@@ -5,4 +5,5 @@ fun foo() {
|
||||
1 suspend ({})
|
||||
}
|
||||
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.WrapWithParenthesesFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.WrapWithParenthesesFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.WrapWithParenthesesFix
|
||||
+2
-1
@@ -5,4 +5,5 @@ fun foo() {
|
||||
1 suspend<caret> fun() {}
|
||||
}
|
||||
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.WrapWithParenthesesFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.WrapWithParenthesesFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.WrapWithParenthesesFix
|
||||
+2
-1
@@ -5,4 +5,5 @@ fun foo() {
|
||||
1 suspend (fun() {})
|
||||
}
|
||||
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.WrapWithParenthesesFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.WrapWithParenthesesFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.WrapWithParenthesesFix
|
||||
+1
-1
@@ -203,7 +203,7 @@ internal fun MutableTWorkspace.generateK2FixTests() {
|
||||
model("$idea/quickfix/variables", pattern = pattern, isRecursive = false, isIgnored = true)
|
||||
model("$idea/quickfix/variables/changeToPropertyAccess", pattern = pattern, isRecursive = false, isIgnored = true)
|
||||
model("$idea/quickfix/variables/changeToFunctionInvocation", pattern = pattern, isRecursive = false)
|
||||
model("$idea/quickfix/wrapArgumentWithParentheses", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/wrapArgumentWithParentheses", pattern = pattern)
|
||||
model("$idea/quickfix/wrapWhenExpressionInParentheses", pattern = pattern)
|
||||
model("$idea/quickfix/wrongLongSuffix", pattern = pattern)
|
||||
model("$idea/quickfix/yieldUnsupported", pattern = pattern, isIgnored = true)
|
||||
|
||||
Reference in New Issue
Block a user