mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Port ChangeObjectToClassFix to K2
This quick fix is for the CONSTRUCTOR_IN_OBJECT error. ^KTIJ-29477 GitOrigin-RevId: b0adf1076540455f02764fce5ce0e5dbdcaca8d3
This commit is contained in:
committed by
intellij-monorepo-bot
parent
14b85e27d1
commit
68b382c580
+21
@@ -0,0 +1,21 @@
|
||||
// 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.ChangeObjectToClassFix
|
||||
import org.jetbrains.kotlin.psi.KtConstructor
|
||||
import org.jetbrains.kotlin.psi.KtObjectDeclaration
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
|
||||
|
||||
internal object ChangeObjectToClassFixFactory {
|
||||
|
||||
val changeObjectToClassFixFactory = KotlinQuickFixFactory.ModCommandBased { diagnostic: KaFirDiagnostic.ConstructorInObject ->
|
||||
val element = diagnostic.psi as? KtConstructor<*> ?: return@ModCommandBased emptyList()
|
||||
val containingObject = element.containingClassOrObject as? KtObjectDeclaration ?: return@ModCommandBased emptyList()
|
||||
|
||||
listOf(
|
||||
ChangeObjectToClassFix(containingObject)
|
||||
)
|
||||
}
|
||||
}
|
||||
+1
@@ -106,6 +106,7 @@ class KotlinK2QuickFixRegistrar : KotlinQuickFixRegistrar() {
|
||||
registerFactory(ArgumentTypeMismatchFactory.wrapWithArrayLiteralFixFactory)
|
||||
registerFactory(ConvertLateinitPropertyToNotNullDelegateFixFactory.convertLateinitPropertyToNotNullDelegateFixFactory)
|
||||
registerFactory(AddReifiedToTypeParameterOfFunctionFixFactory.addReifiedToTypeParameterOfFunctionFixFactory)
|
||||
registerFactory(ChangeObjectToClassFixFactory.changeObjectToClassFixFactory)
|
||||
}
|
||||
|
||||
private val addAbstract = KtQuickFixesListBuilder.registerPsiQuickFix {
|
||||
|
||||
+22
@@ -5696,7 +5696,29 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
|
||||
|
||||
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../../idea/tests/testData/quickfix/changeObjectToClass")
|
||||
public static class ChangeObjectToClass 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("primaryConstructor.kt")
|
||||
public void testPrimaryConstructor() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/changeObjectToClass/primaryConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("secondaryConstructor.kt")
|
||||
public void testSecondaryConstructor() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/changeObjectToClass/secondaryConstructor.kt");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+2
-1
@@ -6,4 +6,5 @@ annotation class Ann
|
||||
object Foo<caret>(val s: String) : Any() {
|
||||
constructor() : this("")
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ChangeObjectToClassFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ChangeObjectToClassFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ChangeObjectToClassFix
|
||||
+2
-1
@@ -6,4 +6,5 @@ annotation class Ann
|
||||
class Foo(val s: String) : Any() {
|
||||
constructor() : this("")
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ChangeObjectToClassFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ChangeObjectToClassFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ChangeObjectToClassFix
|
||||
+2
-1
@@ -6,4 +6,5 @@ annotation class Ann
|
||||
object Foo(val s: String) : Any() {
|
||||
<caret>constructor() : this("")
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ChangeObjectToClassFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ChangeObjectToClassFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ChangeObjectToClassFix
|
||||
+2
-1
@@ -6,4 +6,5 @@ annotation class Ann
|
||||
class Foo(val s: String) : Any() {
|
||||
constructor() : this("")
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ChangeObjectToClassFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ChangeObjectToClassFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ChangeObjectToClassFix
|
||||
+1
-1
@@ -93,7 +93,7 @@ internal fun MutableTWorkspace.generateK2FixTests() {
|
||||
model("$idea/quickfix/canBeParameter", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/canBePrimaryConstructorProperty", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/castDueToProgressionResolveChange", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/changeObjectToClass", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/changeObjectToClass", pattern = pattern)
|
||||
model("$idea/quickfix/changeSignature", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/changeSuperTypeListEntryTypeArgument", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/changeToLabeledReturn", pattern = pattern)
|
||||
|
||||
Reference in New Issue
Block a user