diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/expectactual/ExpectActualUtils.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/expectactual/ExpectActualUtils.kt index 10b4c96a578..37f7df75e43 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/expectactual/ExpectActualUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/expectactual/ExpectActualUtils.kt @@ -299,10 +299,22 @@ private fun KtCallableDeclaration.repairOverride(descriptor: CallableDescriptor, private fun KtCallableDeclaration.repairAnnotationEntries(descriptor: CallableDescriptor, checker: TypeAccessibilityChecker) { for (annotation in descriptor.annotations) { if (annotation.isValidInModule(checker)) { - val entry = annotation.source.safeAs()?.psi.safeAs() ?: continue - addAnnotationEntry(entry) + checkAndAdd(annotation, checker, this) } } + + val extension = descriptor.extensionReceiverParameter ?: return + val receiver = receiverTypeReference ?: return + for (annotation in extension.annotations) { + checkAndAdd(annotation, checker, receiver) + } +} + +private fun checkAndAdd(annotationDescriptor: AnnotationDescriptor, checker: TypeAccessibilityChecker, target: KtModifierListOwner) { + if (annotationDescriptor.isValidInModule(checker)) { + val entry = annotationDescriptor.source.safeAs()?.psi.safeAs() ?: return + target.addAnnotationEntry(entry) + } } private fun AnnotationDescriptor.isValidInModule(checker: TypeAccessibilityChecker): Boolean { diff --git a/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/common/SimpleA.kt b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/common/SimpleA.kt new file mode 100644 index 00000000000..2fdd274a214 --- /dev/null +++ b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/common/SimpleA.kt @@ -0,0 +1 @@ +annotation class SimpleA \ No newline at end of file diff --git a/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/common/myExtension.kt.after b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/common/myExtension.kt.after new file mode 100644 index 00000000000..d9fb6aaaae0 --- /dev/null +++ b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/common/myExtension.kt.after @@ -0,0 +1 @@ +expect fun @receiver:SimpleA String.myExtension() \ No newline at end of file diff --git a/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/jvm/Utils.kt b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/jvm/Utils.kt new file mode 100644 index 00000000000..8d33975dd82 --- /dev/null +++ b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/jvm/Utils.kt @@ -0,0 +1,4 @@ +// "Create expected function in common module testModule_Common" "true" +// DISABLE-ERRORS + +actual fun @receiver:SimpleA String.myExtension() { println(this) } \ No newline at end of file diff --git a/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/jvm/Utils.kt.after b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/jvm/Utils.kt.after new file mode 100644 index 00000000000..8d33975dd82 --- /dev/null +++ b/idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/jvm/Utils.kt.after @@ -0,0 +1,4 @@ +// "Create expected function in common module testModule_Common" "true" +// DISABLE-ERRORS + +actual fun @receiver:SimpleA String.myExtension() { println(this) } \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiModuleTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiModuleTestGenerated.java index e158fdb4482..ecb19a3c1db 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiModuleTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixMultiModuleTestGenerated.java @@ -477,6 +477,11 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul runTest("idea/testData/multiModuleQuickFix/createExpect/sealedClass/"); } + @TestMetadata("topLevelFunctionWithAnnotations") + public void testTopLevelFunctionWithAnnotations() throws Exception { + runTest("idea/testData/multiModuleQuickFix/createExpect/topLevelFunctionWithAnnotations/"); + } + @TestMetadata("topLevelPropertyWithTypeParam") public void testTopLevelPropertyWithTypeParam() throws Exception { runTest("idea/testData/multiModuleQuickFix/createExpect/topLevelPropertyWithTypeParam/");