diff --git a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/KotlinK2QuickFixRegistrar.kt b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/KotlinK2QuickFixRegistrar.kt index eff254104692..d71792ec8692 100644 --- a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/KotlinK2QuickFixRegistrar.kt +++ b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/KotlinK2QuickFixRegistrar.kt @@ -101,6 +101,7 @@ class KotlinK2QuickFixRegistrar : KotlinQuickFixRegistrar() { registerFactory(AddReturnExpressionFixFactory.addReturnExpressionFixFactory) registerFactory(RemoveArgumentFixFactory.removeArgumentFixFactory) registerFactory(AddJvmInlineAnnotationFixFactory.addJvmInlineAnnotationFixFactory) + registerFactory(RemoveNoConstructorFixFactory.removeNoConstructorFixFactory) } private val addAbstract = KtQuickFixesListBuilder.registerPsiQuickFix { diff --git a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/RemoveNoConstructorFixFactory.kt b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/RemoveNoConstructorFixFactory.kt new file mode 100644 index 000000000000..108a08fd4a82 --- /dev/null +++ b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/RemoveNoConstructorFixFactory.kt @@ -0,0 +1,18 @@ +// 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 org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic +import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory +import org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix +import org.jetbrains.kotlin.psi.KtSuperTypeCallEntry + +internal object RemoveNoConstructorFixFactory { + + val removeNoConstructorFixFactory = KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.NoConstructor -> + val element = diagnostic.psi as? KtSuperTypeCallEntry ?: return@ModCommandBased emptyList() + + listOf( + RemoveNoConstructorFix(element) + ) + } +} diff --git a/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java b/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java index f8ae843aa0de..d1d39273777c 100644 --- a/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java +++ b/plugins/kotlin/code-insight/fixes-k2/tests/test/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/HighLevelQuickFixTestGenerated.java @@ -5627,7 +5627,33 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu + @RunWith(JUnit3RunnerWithInners.class) + @TestMetadata("../../../idea/tests/testData/quickfix/removeNoConstructor") + public static class RemoveNoConstructor extends AbstractHighLevelQuickFixTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + @TestMetadata("basic.kt") + public void testBasic() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeNoConstructor/basic.kt"); + } + + @TestMetadata("functionType.kt") + public void testFunctionType() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeNoConstructor/functionType.kt"); + } + + @TestMetadata("functionType2.kt") + public void testFunctionType2() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeNoConstructor/functionType2.kt"); + } + + @TestMetadata("suspend.kt") + public void testSuspend() throws Exception { + runTest("../../../idea/tests/testData/quickfix/removeNoConstructor/suspend.kt"); + } + } diff --git a/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/RemoveNoConstructorFix.kt b/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/RemoveNoConstructorFix.kt index f022081c0aa3..dc190650eafb 100644 --- a/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/RemoveNoConstructorFix.kt +++ b/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/RemoveNoConstructorFix.kt @@ -8,22 +8,19 @@ import org.jetbrains.kotlin.idea.base.resources.KotlinBundle import org.jetbrains.kotlin.idea.codeinsight.api.applicable.intentions.KotlinPsiUpdateModCommandAction import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.psi.KtSuperTypeCallEntry -import org.jetbrains.kotlin.psi.KtValueArgumentList -import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType class RemoveNoConstructorFix( - element: KtValueArgumentList, -) : KotlinPsiUpdateModCommandAction.ElementBased(element, Unit) { + element: KtSuperTypeCallEntry, +) : KotlinPsiUpdateModCommandAction.ElementBased(element, Unit) { override fun invoke( actionContext: ActionContext, - element: KtValueArgumentList, + element: KtSuperTypeCallEntry, elementContext: Unit, updater: ModPsiUpdater, ) { - val superTypeCallEntry = element.getStrictParentOfType() ?: return - val superTypeEntry = KtPsiFactory(actionContext.project).createSuperTypeEntry(superTypeCallEntry.firstChild.text) - superTypeCallEntry.replaced(superTypeEntry) + val superTypeEntry = KtPsiFactory(actionContext.project).createSuperTypeEntry(element.firstChild.text) + element.replaced(superTypeEntry) } override fun getFamilyName() = KotlinBundle.message("remove.constructor.call") diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNoConstructorFixFactory.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNoConstructorFixFactory.kt index b95ad7c1ea77..4690202e73ad 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNoConstructorFixFactory.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNoConstructorFixFactory.kt @@ -5,11 +5,11 @@ package org.jetbrains.kotlin.idea.quickfix import com.intellij.codeInsight.intention.IntentionAction import com.intellij.modcommand.ModCommandAction import org.jetbrains.kotlin.diagnostics.Diagnostic -import org.jetbrains.kotlin.psi.KtValueArgumentList +import org.jetbrains.kotlin.psi.KtSuperTypeCallEntry internal object RemoveNoConstructorFixFactory : KotlinSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction? = - (diagnostic.psiElement as? KtValueArgumentList) + (diagnostic.psiElement.parent as? KtSuperTypeCallEntry) ?.let { RemoveNoConstructorFix(it) } ?.let(ModCommandAction::asIntention) } diff --git a/plugins/kotlin/idea/tests/testData/quickfix/addDefaultConstructor/expectAnnotation3.kt b/plugins/kotlin/idea/tests/testData/quickfix/addDefaultConstructor/expectAnnotation3.kt index c3f25dace593..e03125b5bb5e 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/addDefaultConstructor/expectAnnotation3.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/addDefaultConstructor/expectAnnotation3.kt @@ -2,7 +2,6 @@ // ENABLE_MULTIPLATFORM // ACTION: Make internal // ACTION: Make private -// ACTION: Remove constructor call // ERROR: Expected annotation class 'Foo' has no actual declaration in module light_idea_test_case for JVM // ERROR: This class does not have a constructor expect annotation class Foo diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/basic.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/basic.kt index f8b3655f7909..fcf971db6090 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/basic.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/basic.kt @@ -2,4 +2,5 @@ interface Base class Derived : Base() -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/basic.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/basic.kt.after index aa5a0bda16a1..7e7cfd9cb1b3 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/basic.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/basic.kt.after @@ -2,4 +2,5 @@ interface Base class Derived : Base -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType.kt index dc6649c08c05..cbe145624324 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType.kt @@ -1,4 +1,5 @@ // "Remove constructor call" "true" abstract class A : () -> Int() -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType.kt.after index ac264a6ee5c0..ba477a509ef5 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType.kt.after @@ -1,4 +1,5 @@ // "Remove constructor call" "true" abstract class A : () -> Int -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType2.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType2.kt index 8dbcb4b9703b..8303282f34bf 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType2.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType2.kt @@ -1,4 +1,5 @@ // "Remove constructor call" "true" abstract class B : (() -> Int)() -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType2.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType2.kt.after index 3425d8f22e87..74beaa46bd84 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType2.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/functionType2.kt.after @@ -1,4 +1,5 @@ // "Remove constructor call" "true" abstract class B : (() -> Int) -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/suspend.kt b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/suspend.kt index 0de47122b520..03af05f126a9 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/suspend.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/suspend.kt @@ -1,4 +1,5 @@ // "Remove constructor call" "true" abstract class D : suspend () -> Int() -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/suspend.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/suspend.kt.after index 3dd68f8c170d..c1d09bf9a09a 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/suspend.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/removeNoConstructor/suspend.kt.after @@ -1,4 +1,5 @@ // "Remove constructor call" "true" abstract class D : suspend () -> Int -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix \ No newline at end of file diff --git a/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2QuickFixTests.kt b/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2QuickFixTests.kt index c6db4f172a9c..b68c133d6607 100644 --- a/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2QuickFixTests.kt +++ b/plugins/kotlin/util/test-generator-fir/test/org/jetbrains/kotlin/fir/testGenerator/codeinsight/GenerateK2QuickFixTests.kt @@ -163,7 +163,7 @@ internal fun MutableTWorkspace.generateK2FixTests() { model("$idea/quickfix/removeAtFromAnnotationArgument", pattern = pattern, isIgnored = true) model("$idea/quickfix/removeDefaultParameterValue", pattern = pattern, isIgnored = true) model("$idea/quickfix/removeFinalUpperBound", pattern = pattern, isIgnored = true) - model("$idea/quickfix/removeNoConstructor", pattern = pattern, isIgnored = true) + model("$idea/quickfix/removeNoConstructor", pattern = pattern) model("$idea/quickfix/removeRedundantAssignment", pattern = pattern, isIgnored = true) model("$idea/quickfix/removeRedundantInitializer", pattern = pattern, isIgnored = true) model("$idea/quickfix/removeRedundantLabel", pattern = pattern, isIgnored = true)