mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin k2] Provide "Make function not open" fix for DECLARATION_CANT_BE_INLINED compiler error
^KTIJ-30589 GitOrigin-RevId: 1a318303b6f96d67ad8f68237f6a1db6df7a4792
This commit is contained in:
committed by
intellij-monorepo-bot
parent
dfe5d93081
commit
b3675b28cb
+23
@@ -0,0 +1,23 @@
|
||||
// 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.RemoveModifierFixBase
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.KtNamedFunction
|
||||
import org.jetbrains.kotlin.psi.psiUtil.containingClass
|
||||
|
||||
internal object DeclarationCantBeInlinedFixFactories {
|
||||
|
||||
val removeOpenModifierFixFactory = KotlinQuickFixFactory.IntentionBased { diagnostic: KaFirDiagnostic.DeclarationCantBeInlined ->
|
||||
val function = diagnostic.psi as? KtNamedFunction ?: return@IntentionBased emptyList()
|
||||
val containingClass = function.containingClass() ?: return@IntentionBased emptyList()
|
||||
if (containingClass.isInterface()) return@IntentionBased emptyList()
|
||||
if (!function.hasModifier(KtTokens.OPEN_KEYWORD)) return@IntentionBased emptyList()
|
||||
|
||||
listOf(
|
||||
RemoveModifierFixBase(function, KtTokens.OPEN_KEYWORD, false)
|
||||
)
|
||||
}
|
||||
}
|
||||
+1
@@ -172,6 +172,7 @@ class KotlinK2QuickFixRegistrar : KotlinQuickFixRegistrar() {
|
||||
registerFactory(ConfusingBranchConditionErrorFixFactories.wrapExpressionInParenthesesFixFactory)
|
||||
registerFactory(WrapWithParenthesesFixFactories.suspendFixFactory)
|
||||
registerFactory(WrapWithParenthesesFixFactories.suspendFunErrorFixFactory)
|
||||
registerFactory(DeclarationCantBeInlinedFixFactories.removeOpenModifierFixFactory)
|
||||
}
|
||||
|
||||
private val addAbstract = KtQuickFixesListBuilder.registerPsiQuickFix {
|
||||
|
||||
+22
@@ -7324,7 +7324,29 @@ public abstract class HighLevelQuickFixTestGenerated extends AbstractHighLevelQu
|
||||
}
|
||||
}
|
||||
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("../../../idea/tests/testData/quickfix/declarationCantBeInlined")
|
||||
public static class DeclarationCantBeInlined 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("inClass.kt")
|
||||
public void testInClass() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/declarationCantBeInlined/inClass.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inInterface.kt")
|
||||
public void testInInterface() throws Exception {
|
||||
runTest("../../../idea/tests/testData/quickfix/declarationCantBeInlined/inInterface.kt");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,4 +2,5 @@
|
||||
open class A {
|
||||
inli<caret>ne open fun foo() {}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFixBase
|
||||
+2
-1
@@ -2,4 +2,5 @@
|
||||
open class A {
|
||||
inline fun foo() {}
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFix
|
||||
// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.RemoveModifierFixBase
|
||||
@@ -3,4 +3,6 @@
|
||||
interface B {
|
||||
<caret>inline fun foo()
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ConvertMemberToExtensionFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ConvertMemberToExtensionFix
|
||||
// TODO: KTIJ-29625
|
||||
/* IGNORE_K2 */
|
||||
+3
-1
@@ -6,4 +6,6 @@ interface B {
|
||||
inline fun B.foo() {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ConvertMemberToExtensionFix
|
||||
// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.ConvertMemberToExtensionFix
|
||||
// TODO: KTIJ-29625
|
||||
/* IGNORE_K2 */
|
||||
+1
-1
@@ -112,7 +112,7 @@ internal fun MutableTWorkspace.generateK2FixTests() {
|
||||
model("$idea/quickfix/convertToIsArrayOfCall", pattern = pattern)
|
||||
model("$idea/quickfix/createFromUsage", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/createLabel", pattern = pattern)
|
||||
model("$idea/quickfix/declarationCantBeInlined", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/declarationCantBeInlined", pattern = pattern)
|
||||
model("$idea/quickfix/declaringJavaClass", pattern = pattern, isIgnored = true)
|
||||
model("$idea/quickfix/decreaseVisibility", pattern = pattern)
|
||||
model("$idea/quickfix/deprecatedJavaAnnotation", pattern = pattern, isIgnored = true)
|
||||
|
||||
Reference in New Issue
Block a user