diff --git a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/KotlinK2QuickFixRegistrar.kt b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/KotlinK2QuickFixRegistrar.kt index 7bfd31870250..f39d053fe3b3 100644 --- a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/KotlinK2QuickFixRegistrar.kt +++ b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/KotlinK2QuickFixRegistrar.kt @@ -424,6 +424,7 @@ class KotlinK2QuickFixRegistrar : KotlinQuickFixRegistrar() { ) registerFactory(OptInAnnotationWrongTargetFixFactory.optInAnnotationWrongTargetFixFactory) + registerFactory(OptInModuleLevelFixFactories.optInIsNotEnabledFactory) registerFactory(OptInFileLevelFixFactories.optInUsageFactory) registerFactory(OptInFileLevelFixFactories.optInUsageErrorFactory) registerFactory(OptInFileLevelFixFactories.optInOverrideFactory) diff --git a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/OptInFileLevelFixFactories.kt b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/OptInFileLevelFixFactories.kt index c279944be913..545d3624625c 100644 --- a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/OptInFileLevelFixFactories.kt +++ b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/OptInFileLevelFixFactories.kt @@ -1,12 +1,15 @@ // 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 com.intellij.codeInsight.intention.IntentionAction import com.intellij.psi.PsiElement import com.intellij.psi.createSmartPointer import com.intellij.psi.util.findParentOfType import org.jetbrains.kotlin.analysis.api.KaSession import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic +import org.jetbrains.kotlin.idea.base.util.module import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory +import org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix import org.jetbrains.kotlin.idea.quickfix.UseOptInFileAnnotationFix import org.jetbrains.kotlin.idea.util.findAnnotation import org.jetbrains.kotlin.name.ClassId @@ -36,7 +39,7 @@ internal object OptInFileLevelFixFactories { context(KaSession) private fun createQuickFix( diagnostic: KaFirDiagnostic, - ): List { + ): List { val element = diagnostic.psi.findParentOfType() ?: return emptyList() @@ -54,12 +57,24 @@ internal object OptInFileLevelFixFactories { return emptyList() } - return listOf( - UseOptInFileAnnotationFix( - containingFile, optInFqName, optInMarkerClassId.asSingleFqName(), - findFileAnnotation(containingFile, optInFqName)?.createSmartPointer() - ) + val result = mutableListOf() + val argumentClassFqName = optInMarkerClassId.asSingleFqName() + result += UseOptInFileAnnotationFix( + file = containingFile, + optInFqName = optInFqName, + argumentClassFqName = argumentClassFqName, + existingAnnotationEntry = findFileAnnotation(containingFile, optInFqName)?.createSmartPointer(), ) + + containingFile.module?.let { module -> + result += AddModuleOptInFix( + file = containingFile, + module = module, + annotationFqName = argumentClassFqName, + ) + } + + return result } // Find the existing file-level annotation of the specified class if it exists diff --git a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/OptInFixUtils.kt b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/OptInFixUtils.kt index d07fe5c7cadf..b51062a20a71 100644 --- a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/OptInFixUtils.kt +++ b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/OptInFixUtils.kt @@ -5,7 +5,7 @@ import com.intellij.psi.PsiElement import org.jetbrains.kotlin.analysis.api.KaExperimentalApi import org.jetbrains.kotlin.analysis.api.KaSession import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic -import org.jetbrains.kotlin.analysis.api.symbols.KaNamedClassOrObjectSymbol +import org.jetbrains.kotlin.analysis.api.symbols.KaNamedClassSymbol import org.jetbrains.kotlin.idea.base.util.names.FqNames import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName @@ -26,17 +26,17 @@ internal object OptInFixUtils { ?: FqNames.OptInFqNames.OLD_USE_EXPERIMENTAL_FQ_NAME.takeIf { it.annotationApplicable() } context (KaSession) - private fun FqName.annotationApplicable(): Boolean = - getClassOrObjectSymbolByClassId(ClassId.topLevel(this)) != null + fun FqName.annotationApplicable(): Boolean = + findClass(ClassId.topLevel(this)) != null context (KaSession) - fun findAnnotation(classId: ClassId): KaNamedClassOrObjectSymbol? = - getClassOrObjectSymbolByClassId(classId) as? KaNamedClassOrObjectSymbol + fun findAnnotation(classId: ClassId): KaNamedClassSymbol? = + findClass(classId) as? KaNamedClassSymbol context (KaSession) @OptIn(KaExperimentalApi::class) - fun annotationIsVisible(annotation: KaNamedClassOrObjectSymbol, from: KtElement): Boolean { - val file = from.containingKtFile.getFileSymbol() + fun annotationIsVisible(annotation: KaNamedClassSymbol, from: KtElement): Boolean { + val file = from.containingKtFile.symbol return isVisible(annotation, file, receiverExpression = null, from) } } \ No newline at end of file diff --git a/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/OptInModuleLevelFixFactories.kt b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/OptInModuleLevelFixFactories.kt new file mode 100644 index 000000000000..9426acdc0b15 --- /dev/null +++ b/plugins/kotlin/code-insight/fixes-k2/src/org/jetbrains/kotlin/idea/k2/codeinsight/fixes/OptInModuleLevelFixFactories.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.k2.codeinsight.fixes + +import org.jetbrains.kotlin.analysis.api.fir.diagnostics.KaFirDiagnostic +import org.jetbrains.kotlin.idea.base.util.module +import org.jetbrains.kotlin.idea.base.util.names.FqNames +import org.jetbrains.kotlin.idea.codeinsight.api.applicators.fixes.KotlinQuickFixFactory +import org.jetbrains.kotlin.idea.k2.codeinsight.fixes.OptInFixUtils.annotationApplicable +import org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix +import org.jetbrains.kotlin.resolve.checkers.OptInNames + +internal object OptInModuleLevelFixFactories { + + val optInIsNotEnabledFactory = KotlinQuickFixFactory.IntentionBased { diagnostic: KaFirDiagnostic.OptInIsNotEnabled -> + val file = diagnostic.psi.containingKtFile + val module = file.module + ?: return@IntentionBased emptyList() + + val annotationFqName = OptInNames.REQUIRES_OPT_IN_FQ_NAME.takeIf { it.annotationApplicable() } + ?: FqNames.OptInFqNames.OLD_EXPERIMENTAL_FQ_NAME.takeIf { it.annotationApplicable() } + ?: return@IntentionBased emptyList() + + val quickFix = AddModuleOptInFix( + file = file, + module = module, + annotationFqName = annotationFqName, + ) + listOf(quickFix) + } +} \ No newline at end of file diff --git a/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/quickfix/tests/K2QuickFixTestGenerated.java b/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/quickfix/tests/K2QuickFixTestGenerated.java index c8518fb14488..383dd0a0bdda 100644 --- a/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/quickfix/tests/K2QuickFixTestGenerated.java +++ b/plugins/kotlin/code-insight/inspections-k2/tests/test/org/jetbrains/kotlin/idea/k2/quickfix/tests/K2QuickFixTestGenerated.java @@ -1479,11 +1479,6 @@ public abstract class K2QuickFixTestGenerated extends AbstractK2QuickFixTest { runTest("../../../idea/tests/testData/quickfix/optIn/basicFunctionNotApplicable.kt"); } - @TestMetadata("basicFunctionNotApplicableFir.kt") - public void testBasicFunctionNotApplicableFir() throws Exception { - runTest("../../../idea/tests/testData/quickfix/optIn/basicFunctionNotApplicableFir.kt"); - } - @TestMetadata("basicModule.kt") public void testBasicModule() throws Exception { runTest("../../../idea/tests/testData/quickfix/optIn/basicModule.kt"); @@ -1634,11 +1629,6 @@ public abstract class K2QuickFixTestGenerated extends AbstractK2QuickFixTest { runTest("../../../idea/tests/testData/quickfix/optIn/override.kt"); } - @TestMetadata("overrideFir.kt") - public void testOverrideFir() throws Exception { - runTest("../../../idea/tests/testData/quickfix/optIn/overrideFir.kt"); - } - @TestMetadata("propagateOptIn.kt") public void testPropagateOptIn() throws Exception { runTest("../../../idea/tests/testData/quickfix/optIn/propagateOptIn.kt"); diff --git a/plugins/kotlin/frontend-independent/kotlin.fir.frontend-independent.iml b/plugins/kotlin/frontend-independent/kotlin.fir.frontend-independent.iml index f7b28e7525b5..445164afcc97 100644 --- a/plugins/kotlin/frontend-independent/kotlin.fir.frontend-independent.iml +++ b/plugins/kotlin/frontend-independent/kotlin.fir.frontend-independent.iml @@ -34,6 +34,8 @@ + + \ No newline at end of file diff --git a/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/AddModuleOptInFix.kt b/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/AddModuleOptInFix.kt new file mode 100644 index 000000000000..87df66377073 --- /dev/null +++ b/plugins/kotlin/frontend-independent/src/org/jetbrains/kotlin/idea/quickfix/AddModuleOptInFix.kt @@ -0,0 +1,67 @@ +// 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.codeInspection.util.IntentionFamilyName +import com.intellij.codeInspection.util.IntentionName +import com.intellij.openapi.editor.Editor +import com.intellij.openapi.module.Module +import com.intellij.openapi.project.Project +import org.jetbrains.kotlin.idea.base.resources.KotlinBundle +import org.jetbrains.kotlin.idea.codeinsight.api.classic.quickfixes.KotlinQuickFixAction +import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayout +import org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator +import org.jetbrains.kotlin.name.FqName +import org.jetbrains.kotlin.psi.KtFile + +/** + * A quick fix that adds an opt-in compiler argument to the current module configuration facet. + */ +class AddModuleOptInFix( + file: KtFile, + private val module: Module, + private val annotationFqName: FqName, +) : KotlinQuickFixAction(file) { + + private val configurator by lazy { + KotlinProjectConfigurator.EP_NAME + .lazySequence() + .filter { it.canAddModuleWideOptIn } + .firstOrNull { it.isApplicable(module) } + } + + override fun getText(): @IntentionName String = KotlinBundle.message( + "fix.opt_in.text.use.module", + annotationFqName.shortName().asString(), + configurator?.userVisibleNameFor(module) ?: module.name, + ) + + override fun getFamilyName(): @IntentionFamilyName String = + KotlinBundle.message("add.an.opt.in.requirement.marker.compiler.argument") + + /** + * The actual name of the opt-in compiler argument depends on the Kotlin compiler version: + * * `-opt-in` (since Kotlin 1.6) https://youtrack.jetbrains.com/issue/KT-47099 + * * `-Xopt-in` (before Kotlin 1.6) https://blog.jetbrains.com/kotlin/2020/03/kotlin-1-3-70-released/ + * * `-Xuse-experimental` (before Kotlin 1.3.70), a fallback if `RequireOptIn` annotation does not exist + */ + override fun invoke( + project: Project, + editor: Editor?, + file: KtFile, + ) { + val optInPrefix = if (KotlinPluginLayout.standaloneCompilerVersion.kotlinVersion.isAtLeast(1, 6, 0)) "" + else "X" + + configurator?.addModuleWideOptIn( + module, + annotationFqName, + "-${optInPrefix}opt-in=${annotationFqName}", + ) + } + + override fun isAvailable( + project: Project, + editor: Editor?, + file: KtFile, + ): Boolean = configurator != null +} \ No newline at end of file diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeModuleOptInFix.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeModuleOptInFix.kt index 67ae0319bdb5..d18210325ebd 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeModuleOptInFix.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeModuleOptInFix.kt @@ -3,74 +3,27 @@ package org.jetbrains.kotlin.idea.quickfix import com.intellij.codeInsight.intention.IntentionAction -import com.intellij.openapi.editor.Editor -import com.intellij.openapi.module.Module -import com.intellij.openapi.project.Project import org.jetbrains.kotlin.diagnostics.Diagnostic -import org.jetbrains.kotlin.idea.base.resources.KotlinBundle import org.jetbrains.kotlin.idea.base.util.names.FqNames import org.jetbrains.kotlin.idea.caches.project.toDescriptor -import org.jetbrains.kotlin.idea.codeinsight.api.classic.quickfixes.KotlinQuickFixAction -import org.jetbrains.kotlin.idea.compiler.configuration.KotlinPluginLayout -import org.jetbrains.kotlin.idea.configuration.allConfigurators import org.jetbrains.kotlin.idea.util.projectStructure.module -import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.resolve.checkers.OptInNames -/** - * A quick fix that adds an opt-in compiler argument to the current module configuration facet. - */ -open class MakeModuleOptInFix( - file: KtFile, - private val module: Module, - private val annotationFqName: FqName, -) : KotlinQuickFixAction(file) { +internal object MakeModuleOptInFix : KotlinSingleIntentionActionFactory() { - private val configurator by lazy { - allConfigurators().find { it.isApplicable(module) && it.canAddModuleWideOptIn } - } + override fun createAction(diagnostic: Diagnostic): IntentionAction? { + val containingKtFile = diagnostic.psiElement.containingFile as? KtFile ?: return null + val module = containingKtFile.module ?: return null + val moduleDescriptor = module.toDescriptor() - /** - * The actual name of the opt-in compiler argument depends on the Kotlin compiler version: - * * `-opt-in` (since Kotlin 1.6) https://youtrack.jetbrains.com/issue/KT-47099 - * * `-Xopt-in` (before Kotlin 1.6) https://blog.jetbrains.com/kotlin/2020/03/kotlin-1-3-70-released/ - * * `-Xuse-experimental` (before Kotlin 1.3.70), a fallback if `RequireOptIn` annotation does not exist - */ - private val compilerArgName = when { - module.toDescriptor()?.let { OptInFixesUtils.annotationExists(it, OptInNames.REQUIRES_OPT_IN_FQ_NAME) } == false -> "-Xuse-experimental" - KotlinPluginLayout.standaloneCompilerVersion.kotlinVersion.isAtLeast(1, 6, 0) -> "-opt-in" - else -> "-Xopt-in" - } - - private val compilerArgument = "$compilerArgName=$annotationFqName" - - override fun getText(): String = KotlinBundle.message( - "fix.opt_in.text.use.module", - annotationFqName.shortName().asString(), - configurator?.userVisibleNameFor(module) ?: module.name - ) - - override fun getFamilyName(): String = KotlinBundle.message("add.an.opt.in.requirement.marker.compiler.argument") - - override fun invoke(project: Project, editor: Editor?, file: KtFile) { - configurator?.addModuleWideOptIn(module, annotationFqName, compilerArgument) - } - - override fun isAvailable(project: Project, editor: Editor?, file: KtFile): Boolean = configurator != null - - companion object : KotlinSingleIntentionActionFactory() { - override fun createAction(diagnostic: Diagnostic): IntentionAction? { - val containingKtFile = diagnostic.psiElement.containingFile as? KtFile ?: return null - val module = containingKtFile.module ?: return null - val moduleDescriptor = module.toDescriptor() - return MakeModuleOptInFix( - containingKtFile, - module, - OptInNames.REQUIRES_OPT_IN_FQ_NAME.takeIf { - moduleDescriptor != null && OptInFixesUtils.annotationExists(moduleDescriptor, it) - } ?: FqNames.OptInFqNames.OLD_EXPERIMENTAL_FQ_NAME - ) - } + return AddModuleOptInFix( + containingKtFile, + module, + OptInNames.REQUIRES_OPT_IN_FQ_NAME.takeIf { + moduleDescriptor != null && OptInFixesUtils.annotationExists(moduleDescriptor, it) + } ?: FqNames.OptInFqNames.OLD_EXPERIMENTAL_FQ_NAME + ) } } + diff --git a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/OptInFileLevelFixesFactory.kt b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/OptInFileLevelFixesFactory.kt index 72c23f0efbc6..ea0cb3b7cc03 100644 --- a/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/OptInFileLevelFixesFactory.kt +++ b/plugins/kotlin/idea/src/org/jetbrains/kotlin/idea/quickfix/OptInFileLevelFixesFactory.kt @@ -3,8 +3,6 @@ package org.jetbrains.kotlin.idea.quickfix import com.intellij.codeInsight.intention.IntentionAction -import com.intellij.codeInsight.intention.LowPriorityAction -import com.intellij.openapi.module.Module import com.intellij.psi.createSmartPointer import com.intellij.psi.util.findParentOfType import org.jetbrains.kotlin.descriptors.resolveClassByFqName @@ -42,20 +40,22 @@ internal object OptInFileLevelFixesFactory : KotlinIntentionActionsFactory() { val optInFqName = OptInFixesUtils.optInFqName(moduleDescriptor) - val result = mutableListOf() - val containingFile = element.containingKtFile - val module = containingFile.module - result.add( - UseOptInFileAnnotationFix( - containingFile, optInFqName, annotationFqName, - findFileAnnotation(containingFile, optInFqName)?.createSmartPointer() - ) + val result = mutableListOf() + result += UseOptInFileAnnotationFix( + file = containingFile, + optInFqName = optInFqName, + argumentClassFqName = annotationFqName, + existingAnnotationEntry = findFileAnnotation(containingFile, optInFqName)?.createSmartPointer(), ) - if (module != null) { - result.add(MakeModuleOptInFix(containingFile, module, annotationFqName)) + containingFile.module?.let { module -> + result += AddModuleOptInFix( + file = containingFile, + module = module, + annotationFqName = annotationFqName, + ) } return result diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/quickfix/K1QuickFixTestGenerated.java b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/quickfix/K1QuickFixTestGenerated.java index 507890c85583..15c680d5f0b7 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/quickfix/K1QuickFixTestGenerated.java +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/quickfix/K1QuickFixTestGenerated.java @@ -12398,11 +12398,6 @@ public abstract class K1QuickFixTestGenerated extends AbstractK1QuickFixTest { runTest("testData/quickfix/optIn/basicFunctionNotApplicable.kt"); } - @TestMetadata("basicFunctionNotApplicableFir.kt") - public void testBasicFunctionNotApplicableFir() throws Exception { - runTest("testData/quickfix/optIn/basicFunctionNotApplicableFir.kt"); - } - @TestMetadata("basicModule.kt") public void testBasicModule() throws Exception { runTest("testData/quickfix/optIn/basicModule.kt"); @@ -12553,11 +12548,6 @@ public abstract class K1QuickFixTestGenerated extends AbstractK1QuickFixTest { runTest("testData/quickfix/optIn/override.kt"); } - @TestMetadata("overrideFir.kt") - public void testOverrideFir() throws Exception { - runTest("testData/quickfix/optIn/overrideFir.kt"); - } - @TestMetadata("propagateOptIn.kt") public void testPropagateOptIn() throws Exception { runTest("testData/quickfix/optIn/propagateOptIn.kt"); diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/basicFunctionNotApplicable.kt b/plugins/kotlin/idea/tests/testData/quickfix/optIn/basicFunctionNotApplicable.kt index f1ee669134a2..5fc853db796c 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/basicFunctionNotApplicable.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/basicFunctionNotApplicable.kt @@ -1,5 +1,4 @@ // "Propagate 'MyExperimentalAPI' opt-in requirement to 'bar'" "false" -// IGNORE_K2 // COMPILER_ARGUMENTS: -opt-in=kotlin.RequiresOptIn // WITH_STDLIB // ACTION: Opt in for 'MyExperimentalAPI' in containing file 'basicFunctionNotApplicable.kt' diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/basicFunctionNotApplicableFir.kt b/plugins/kotlin/idea/tests/testData/quickfix/optIn/basicFunctionNotApplicableFir.kt deleted file mode 100644 index c4299b046029..000000000000 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/basicFunctionNotApplicableFir.kt +++ /dev/null @@ -1,27 +0,0 @@ -// "Propagate 'MyExperimentalAPI' opt-in requirement to 'bar'" "false" -// IGNORE_K1 -// COMPILER_ARGUMENTS: -opt-in=kotlin.RequiresOptIn -// WITH_STDLIB -// ACTION: Opt in for 'MyExperimentalAPI' in containing file 'basicFunctionNotApplicableFir.kt' -// ACTION: Opt in for 'MyExperimentalAPI' on 'bar' -// ACTION: Opt in for 'MyExperimentalAPI' on containing class 'Bar' -// ACTION: Propagate 'MyExperimentalAPI' opt-in requirement to containing class 'Bar' -// ERROR: This declaration needs opt-in. Its usage must be marked with '@MyExperimentalAPI' or '@OptIn(MyExperimentalAPI::class)' -// ERROR: This declaration needs opt-in. Its usage must be marked with '@MyExperimentalAPI' or '@OptIn(MyExperimentalAPI::class)' -// ERROR: This annotation is not applicable to target 'member function' - -@RequiresOptIn -@Target(AnnotationTarget.CLASS) -annotation class MyExperimentalAPI - -@MyExperimentalAPI -class Some { - @MyExperimentalAPI - fun foo() {} -} - -class Bar { - fun bar() { - Some().foo() - } -} diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/basicModule.kt b/plugins/kotlin/idea/tests/testData/quickfix/optIn/basicModule.kt index 281eade04dcb..a47a985a0873 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/basicModule.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/basicModule.kt @@ -1,5 +1,4 @@ // "Opt in for 'MyExperimentalAPI' in module 'light_idea_test_case'" "true" -// IGNORE_K2 // COMPILER_ARGUMENTS: -opt-in=kotlin.RequiresOptIn // COMPILER_ARGUMENTS_AFTER: -opt-in=kotlin.RequiresOptIn -opt-in=test.MyExperimentalAPI // DISABLE-ERRORS @@ -22,4 +21,5 @@ class Bar { } } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MakeModuleOptInFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/basicModule.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/optIn/basicModule.kt.after index 6131d0596c4c..90de56157972 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/basicModule.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/basicModule.kt.after @@ -1,5 +1,4 @@ // "Opt in for 'MyExperimentalAPI' in module 'light_idea_test_case'" "true" -// IGNORE_K2 // COMPILER_ARGUMENTS: -opt-in=kotlin.RequiresOptIn // COMPILER_ARGUMENTS_AFTER: -opt-in=kotlin.RequiresOptIn -opt-in=test.MyExperimentalAPI // DISABLE-ERRORS @@ -22,4 +21,5 @@ class Bar { } } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MakeModuleOptInFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/nestedClassesFir.kt b/plugins/kotlin/idea/tests/testData/quickfix/optIn/nestedClassesFir.kt index 24243090b907..6fa19cde9727 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/nestedClassesFir.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/nestedClassesFir.kt @@ -3,6 +3,7 @@ // COMPILER_ARGUMENTS: -opt-in=kotlin.RequiresOptIn // WITH_STDLIB // ACTION: Opt in for 'MyExperimentalAPI' in containing file 'nestedClassesFir.kt' +// ACTION: Opt in for 'MyExperimentalAPI' in module 'light_idea_test_case' // ACTION: Opt in for 'MyExperimentalAPI' on 'bar' // ACTION: Opt in for 'MyExperimentalAPI' on containing class 'Inner' // ACTION: Propagate 'MyExperimentalAPI' opt-in requirement to 'bar' @@ -13,7 +14,8 @@ annotation class MyExperimentalAPI @MyExperimentalAPI -fun foo() {} +fun foo() { +} class Outer { class Bar { diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/override.kt b/plugins/kotlin/idea/tests/testData/quickfix/optIn/override.kt index f135e122b727..477badbd2082 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/override.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/override.kt @@ -1,5 +1,4 @@ // "Propagate 'MyExperimentalAPI' opt-in requirement to containing class 'Derived'" "false" -// IGNORE_K2 // COMPILER_ARGUMENTS: -opt-in=kotlin.RequiresOptIn // WITH_STDLIB // ACTION: Enable a trailing comma by default in the formatter diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/overrideFir.kt b/plugins/kotlin/idea/tests/testData/quickfix/optIn/overrideFir.kt deleted file mode 100644 index 0362a18c0bdf..000000000000 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/overrideFir.kt +++ /dev/null @@ -1,24 +0,0 @@ -// "Propagate 'MyExperimentalAPI' opt-in requirement to containing class 'Derived'" "false" -// IGNORE_K1 -// COMPILER_ARGUMENTS: -opt-in=kotlin.RequiresOptIn -// WITH_STDLIB -// ACTION: Enable a trailing comma by default in the formatter -// ACTION: Go To Super Method -// ACTION: Opt in for 'MyExperimentalAPI' in containing file 'overrideFir.kt' -// ACTION: Opt in for 'MyExperimentalAPI' on 'foo' -// ACTION: Opt in for 'MyExperimentalAPI' on containing class 'Derived' -// ACTION: Propagate 'MyExperimentalAPI' opt-in requirement to 'foo' -// ERROR: Base declaration of supertype 'Base' needs opt-in. The declaration override must be annotated with '@MyExperimentalAPI' or '@OptIn(MyExperimentalAPI::class)' - -@RequiresOptIn -@Target(AnnotationTarget.FUNCTION) -annotation class MyExperimentalAPI - -open class Base { - @MyExperimentalAPI - open fun foo() {} -} - -class Derived : Base() { - override fun foo() {} -} diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/propagateOptIn8Fir.kt b/plugins/kotlin/idea/tests/testData/quickfix/optIn/propagateOptIn8Fir.kt index a30be5b356c8..59d9956559d9 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/propagateOptIn8Fir.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/propagateOptIn8Fir.kt @@ -2,6 +2,7 @@ // IGNORE_K1 // ERROR: This declaration needs opt-in. Its usage must be marked with '@UnstableApi' or '@OptIn(UnstableApi::class)' // ACTION: Opt in for 'UnstableApi' in containing file 'propagateOptIn8Fir.kt' +// ACTION: Opt in for 'UnstableApi' in module 'light_idea_test_case' // ACTION: Opt in for 'UnstableApi' on 'foo' // ACTION: Propagate 'UnstableApi' opt-in requirement to 'foo' // COMPILER_ARGUMENTS: -opt-in=kotlin.RequiresOptIn diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/basicModule.kts b/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/basicModule.kts index d6bf17fd7ef8..91fde2d0a754 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/basicModule.kts +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/basicModule.kts @@ -27,4 +27,4 @@ class Bar { } } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MakeModuleOptInFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/basicModule.kts.after b/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/basicModule.kts.after index dd0a7ab361c1..5252015f12ec 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/basicModule.kts.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/basicModule.kts.after @@ -27,4 +27,4 @@ class Bar { } } -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MakeModuleOptInFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOn.kts b/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOn.kts index eeedb2226746..8384aba13da3 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOn.kts +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOn.kts @@ -7,4 +7,4 @@ @RequiresOptIn annotation class MyExperimentalAPI -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MakeModuleOptInFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOn.kts.after b/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOn.kts.after index c9ba26569c81..9307691798a8 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOn.kts.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOn.kts.after @@ -7,4 +7,4 @@ @RequiresOptIn annotation class MyExperimentalAPI -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MakeModuleOptInFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOnWithAnotherMarker.kts b/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOnWithAnotherMarker.kts index 0048cae2e0fe..ba124c060056 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOnWithAnotherMarker.kts +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOnWithAnotherMarker.kts @@ -7,4 +7,4 @@ @RequiresOptIn annotation class MyExperimentalAPI -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MakeModuleOptInFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOnWithAnotherMarker.kts.after b/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOnWithAnotherMarker.kts.after index 8b06250420c0..f028cc323893 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOnWithAnotherMarker.kts.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/scripts/general/switchOnWithAnotherMarker.kts.after @@ -7,4 +7,4 @@ @RequiresOptIn annotation class MyExperimentalAPI -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MakeModuleOptInFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOn.kt b/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOn.kt index f3e6fed05b14..b5830af13c46 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOn.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOn.kt @@ -1,5 +1,4 @@ // "Opt in for 'RequiresOptIn' in module 'light_idea_test_case'" "true" -// IGNORE_K2 // COMPILER_ARGUMENTS: -version // COMPILER_ARGUMENTS_AFTER: -version -opt-in=kotlin.RequiresOptIn // DISABLE-ERRORS @@ -9,4 +8,5 @@ @RequiresOptIn annotation class MyExperimentalAPI -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MakeModuleOptInFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOn.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOn.kt.after index 488ddd18c776..72d0ad1b5519 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOn.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOn.kt.after @@ -1,5 +1,4 @@ // "Opt in for 'RequiresOptIn' in module 'light_idea_test_case'" "true" -// IGNORE_K2 // COMPILER_ARGUMENTS: -version // COMPILER_ARGUMENTS_AFTER: -version -opt-in=kotlin.RequiresOptIn // DISABLE-ERRORS @@ -9,4 +8,5 @@ @RequiresOptIn annotation class MyExperimentalAPI -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MakeModuleOptInFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOnWithAnotherMarker.kt b/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOnWithAnotherMarker.kt index 44c486fbd91a..89f8f3a60185 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOnWithAnotherMarker.kt +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOnWithAnotherMarker.kt @@ -1,5 +1,4 @@ // "Opt in for 'RequiresOptIn' in module 'light_idea_test_case'" "true" -// IGNORE_K2 // COMPILER_ARGUMENTS: -version -opt-in=AnotherMarker // COMPILER_ARGUMENTS_AFTER: -version -opt-in=AnotherMarker -opt-in=kotlin.RequiresOptIn // DISABLE-ERRORS @@ -9,4 +8,5 @@ @RequiresOptIn annotation class MyExperimentalAPI -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MakeModuleOptInFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix \ No newline at end of file diff --git a/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOnWithAnotherMarker.kt.after b/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOnWithAnotherMarker.kt.after index 3ccf410c4319..637dc1b1467c 100644 --- a/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOnWithAnotherMarker.kt.after +++ b/plugins/kotlin/idea/tests/testData/quickfix/optIn/switchOnWithAnotherMarker.kt.after @@ -1,5 +1,4 @@ // "Opt in for 'RequiresOptIn' in module 'light_idea_test_case'" "true" -// IGNORE_K2 // COMPILER_ARGUMENTS: -version -opt-in=AnotherMarker // COMPILER_ARGUMENTS_AFTER: -version -opt-in=AnotherMarker -opt-in=kotlin.RequiresOptIn // DISABLE-ERRORS @@ -9,4 +8,5 @@ @RequiresOptIn annotation class MyExperimentalAPI -// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.MakeModuleOptInFix \ No newline at end of file +// FUS_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix +// FUS_K2_QUICKFIX_NAME: org.jetbrains.kotlin.idea.quickfix.AddModuleOptInFix \ No newline at end of file