mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Convert ChangeObjectToClassFix to ModCommandAction
^KTIJ-29477 GitOrigin-RevId: da5bbd23b352f6b22d9e3b50bf8ae5742c157ef6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
dfb23c90a9
commit
14b85e27d1
+16
-12
@@ -1,23 +1,27 @@
|
||||
// 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.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.modcommand.ActionContext
|
||||
import com.intellij.modcommand.ModPsiUpdater
|
||||
import org.jetbrains.kotlin.idea.base.resources.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.classic.quickfixes.KotlinQuickFixAction
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.applicable.intentions.KotlinPsiUpdateModCommandAction
|
||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtPsiFactory
|
||||
|
||||
class ChangeObjectToClassFix(element: KtObjectDeclaration) : KotlinQuickFixAction<KtObjectDeclaration>(element) {
|
||||
override fun getText(): String = KotlinBundle.message("fix.change.object.to.class")
|
||||
class ChangeObjectToClassFix(
|
||||
element: KtObjectDeclaration,
|
||||
) : KotlinPsiUpdateModCommandAction.ElementBased<KtObjectDeclaration, Unit>(element, Unit) {
|
||||
|
||||
override fun getFamilyName(): String = text
|
||||
override fun getFamilyName(): String = KotlinBundle.message("fix.change.object.to.class")
|
||||
|
||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||
val objectDeclaration = element ?: return
|
||||
val psiFactory = KtPsiFactory(project)
|
||||
objectDeclaration.getObjectKeyword()?.replace(psiFactory.createClassKeyword())
|
||||
objectDeclaration.replace(psiFactory.createClass(objectDeclaration.text))
|
||||
override fun invoke(
|
||||
actionContext: ActionContext,
|
||||
element: KtObjectDeclaration,
|
||||
elementContext: Unit,
|
||||
updater: ModPsiUpdater,
|
||||
) {
|
||||
val psiFactory = KtPsiFactory(actionContext.project)
|
||||
element.getObjectKeyword()?.replace(psiFactory.createClassKeyword())
|
||||
element.replace(psiFactory.createClass(element.text))
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -2,16 +2,16 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.quickfix
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.idea.codeinsight.api.classic.quickfixes.KotlinQuickFixAction
|
||||
import org.jetbrains.kotlin.psi.KtConstructor
|
||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||
|
||||
internal object ChangeObjectToClassFixFactory : KotlinSingleIntentionActionFactory() {
|
||||
override fun createAction(diagnostic: Diagnostic): KotlinQuickFixAction<KtObjectDeclaration>? {
|
||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||
val element = diagnostic.psiElement as? KtConstructor<*> ?: return null
|
||||
val containingObject = element.containingClassOrObject as? KtObjectDeclaration ?: return null
|
||||
return ChangeObjectToClassFix(containingObject)
|
||||
return ChangeObjectToClassFix(containingObject).asIntention()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user