mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Port RemoveNoConstructorFix to K2
^KTIJ-29525 GitOrigin-RevId: f2a9ee7f0d31152e2d18cf63882bd50525e665ee
This commit is contained in:
committed by
intellij-monorepo-bot
parent
2d400a11a8
commit
174f46c19f
+1
@@ -101,6 +101,7 @@ class KotlinK2QuickFixRegistrar : KotlinQuickFixRegistrar() {
|
||||
registerFactory(AddReturnExpressionFixFactory.addReturnExpressionFixFactory)
|
||||
registerFactory(RemoveArgumentFixFactory.removeArgumentFixFactory)
|
||||
registerFactory(AddJvmInlineAnnotationFixFactory.addJvmInlineAnnotationFixFactory)
|
||||
registerFactory(RemoveNoConstructorFixFactory.removeNoConstructorFixFactory)
|
||||
}
|
||||
|
||||
private val addAbstract = KtQuickFixesListBuilder.registerPsiQuickFix {
|
||||
|
||||
+18
@@ -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)
|
||||
)
|
||||
}
|
||||
}
|
||||
+26
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+5
-8
@@ -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<KtValueArgumentList, Unit>(element, Unit) {
|
||||
element: KtSuperTypeCallEntry,
|
||||
) : KotlinPsiUpdateModCommandAction.ElementBased<KtSuperTypeCallEntry, Unit>(element, Unit) {
|
||||
|
||||
override fun invoke(
|
||||
actionContext: ActionContext,
|
||||
element: KtValueArgumentList,
|
||||
element: KtSuperTypeCallEntry,
|
||||
elementContext: Unit,
|
||||
updater: ModPsiUpdater,
|
||||
) {
|
||||
val superTypeCallEntry = element.getStrictParentOfType<KtSuperTypeCallEntry>() ?: 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")
|
||||
|
||||
+2
-2
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
|
||||
interface Base
|
||||
class Derived : Base()<caret>
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
@@ -2,4 +2,5 @@
|
||||
|
||||
interface Base
|
||||
class Derived : Base
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
@@ -1,4 +1,5 @@
|
||||
// "Remove constructor call" "true"
|
||||
|
||||
abstract class A : () -> Int()<caret>
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
// "Remove constructor call" "true"
|
||||
|
||||
abstract class A : () -> Int<caret>
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
@@ -1,4 +1,5 @@
|
||||
// "Remove constructor call" "true"
|
||||
|
||||
abstract class B : (() -> Int)()<caret>
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
// "Remove constructor call" "true"
|
||||
|
||||
abstract class B : (() -> Int)<caret>
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
@@ -1,4 +1,5 @@
|
||||
// "Remove constructor call" "true"
|
||||
|
||||
abstract class D : suspend () -> Int()<caret>
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
@@ -1,4 +1,5 @@
|
||||
// "Remove constructor call" "true"
|
||||
|
||||
abstract class D : suspend () -> Int<caret>
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveNoConstructorFix
|
||||
+1
-1
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user