CreateExpect: should save receiver annotations

#KT-32694 Fixed
This commit is contained in:
Dmitry Gridin
2019-08-22 17:15:39 +07:00
parent 42ef9d634a
commit 5928a36fa2
6 changed files with 29 additions and 2 deletions
@@ -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<KotlinSourceElement>()?.psi.safeAs<KtAnnotationEntry>() ?: 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<KotlinSourceElement>()?.psi.safeAs<KtAnnotationEntry>() ?: return
target.addAnnotationEntry(entry)
}
}
private fun AnnotationDescriptor.isValidInModule(checker: TypeAccessibilityChecker): Boolean {
@@ -0,0 +1 @@
annotation class SimpleA
@@ -0,0 +1 @@
expect fun @receiver:SimpleA String.myExtension()
@@ -0,0 +1,4 @@
// "Create expected function in common module testModule_Common" "true"
// DISABLE-ERRORS
actual fun @receiver:SimpleA String.<caret>myExtension() { println(this) }
@@ -0,0 +1,4 @@
// "Create expected function in common module testModule_Common" "true"
// DISABLE-ERRORS
actual fun @receiver:SimpleA String.<caret>myExtension() { println(this) }
@@ -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/");