From 9d313e642422ccf3520181a5afc42cb9a0e9018f Mon Sep 17 00:00:00 2001 From: Andrey Cherkasov Date: Sat, 25 May 2024 19:03:24 +0400 Subject: [PATCH] [kotlin] Move RemoveNoConstructorFix to frontend independent module ...and convert it to ModCommandAction. ^KTIJ-29525 GitOrigin-RevId: 24a801b95eab21cb8651e00aa5eef43b058d098a --- .../idea/quickfix/RemoveNoConstructorFix.kt | 30 +++++++++++++++++ .../kotlin/idea/quickfix/QuickFixRegistrar.kt | 4 +-- .../idea/quickfix/RemoveNoConstructorFix.kt | 33 ++++--------------- 3 files changed, 39 insertions(+), 28 deletions(-) create mode 100644 plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/RemoveNoConstructorFix.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 new file mode 100644 index 000000000000..f022081c0aa3 --- /dev/null +++ b/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/RemoveNoConstructorFix.kt @@ -0,0 +1,30 @@ +// 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.quickfix + +import com.intellij.modcommand.ActionContext +import com.intellij.modcommand.ModPsiUpdater +import org.jetbrains.kotlin.idea.base.psi.replaced +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) { + + override fun invoke( + actionContext: ActionContext, + element: KtValueArgumentList, + elementContext: Unit, + updater: ModPsiUpdater, + ) { + val superTypeCallEntry = element.getStrictParentOfType() ?: return + val superTypeEntry = KtPsiFactory(actionContext.project).createSuperTypeEntry(superTypeCallEntry.firstChild.text) + superTypeCallEntry.replaced(superTypeEntry) + } + + override fun getFamilyName() = KotlinBundle.message("remove.constructor.call") +} diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index 120e0e8f53be..0c5c7edf6db0 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -659,9 +659,9 @@ class QuickFixRegistrar : QuickFixContributor { WRONG_ANNOTATION_TARGET.registerFactory(AddAnnotationTargetFix, AddAnnotationUseSiteTargetFix) WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET.registerFactory(MoveReceiverAnnotationFix, AddAnnotationTargetFix) - NO_CONSTRUCTOR.registerFactory(RemoveNoConstructorFix) + NO_CONSTRUCTOR.registerFactory(RemoveNoConstructorFixFactory) NO_CONSTRUCTOR.registerFactory(AddDefaultConstructorFix) - NO_CONSTRUCTOR_WARNING.registerFactory(RemoveNoConstructorFix) + NO_CONSTRUCTOR_WARNING.registerFactory(RemoveNoConstructorFixFactory) ANNOTATION_USED_AS_ANNOTATION_ARGUMENT.registerFactory(RemoveAtFromAnnotationArgument) diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNoConstructorFix.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNoConstructorFix.kt index 9f4ee72b6331..b95ad7c1ea77 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNoConstructorFix.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNoConstructorFix.kt @@ -2,33 +2,14 @@ package org.jetbrains.kotlin.idea.quickfix -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.project.Project +import com.intellij.codeInsight.intention.IntentionAction +import com.intellij.modcommand.ModCommandAction import org.jetbrains.kotlin.diagnostics.Diagnostic -import org.jetbrains.kotlin.idea.base.resources.KotlinBundle -import org.jetbrains.kotlin.idea.base.psi.replaced -import org.jetbrains.kotlin.idea.codeinsight.api.classic.quickfixes.KotlinQuickFixAction -import org.jetbrains.kotlin.psi.KtFile -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(constructor: KtValueArgumentList) : KotlinQuickFixAction(constructor) { - - override fun getText() = KotlinBundle.message("remove.constructor.call") - - override fun getFamilyName() = text - - override fun invoke(project: Project, editor: Editor?, file: KtFile) { - val superTypeCallEntry = element?.getStrictParentOfType() ?: return - val superTypeEntry = KtPsiFactory(project).createSuperTypeEntry(superTypeCallEntry.firstChild.text) - superTypeCallEntry.replaced(superTypeEntry) - } - - companion object : KotlinSingleIntentionActionFactory() { - override fun createAction(diagnostic: Diagnostic): KotlinQuickFixAction? = - (diagnostic.psiElement as? KtValueArgumentList)?.let { RemoveNoConstructorFix(it) } - } +internal object RemoveNoConstructorFixFactory : KotlinSingleIntentionActionFactory() { + override fun createAction(diagnostic: Diagnostic): IntentionAction? = + (diagnostic.psiElement as? KtValueArgumentList) + ?.let { RemoveNoConstructorFix(it) } + ?.let(ModCommandAction::asIntention) }