K2: fix field annotation handling around serialization

#KT-57135 Fixed
This commit is contained in:
Mikhail Glukhikh
2023-03-23 14:10:08 +01:00
committed by Space Team
parent dc38ce24f7
commit f6bf7560a6
15 changed files with 30 additions and 21 deletions
@@ -331,7 +331,7 @@ class FirElementSerializer private constructor(
var hasSetter = false
val hasAnnotations = property.nonSourceAnnotations(session).isNotEmpty()
// TODO: hasAnnotations(descriptor) || hasAnnotations(descriptor.backingField) || hasAnnotations(descriptor.delegateField)
|| property.backingField?.nonSourceAnnotations(session)?.isNotEmpty() == true
val modality = property.modality!!
val defaultAccessorFlags = Flags.getAccessorFlags(
@@ -59,20 +59,18 @@ abstract class FirSerializerExtensionBase(
versionRequirementTable: MutableVersionRequirementTable?,
childSerializer: FirElementSerializer
) {
val regularPropertyAnnotations = mutableListOf<FirAnnotation>()
val fieldPropertyAnnotations = mutableListOf<FirAnnotation>()
val delegatePropertyAnnotations = mutableListOf<FirAnnotation>()
for (annotation in property.nonSourceAnnotations(session)) {
for (annotation in property.backingField?.nonSourceAnnotations(session).orEmpty()) {
val destination = when (annotation.useSiteTarget) {
AnnotationUseSiteTarget.FIELD -> fieldPropertyAnnotations
AnnotationUseSiteTarget.PROPERTY_DELEGATE_FIELD -> delegatePropertyAnnotations
else -> regularPropertyAnnotations
else -> fieldPropertyAnnotations
}
destination += annotation
}
regularPropertyAnnotations.serializeAnnotations(proto, protocol.propertyAnnotation)
property.nonSourceAnnotations(session).serializeAnnotations(proto, protocol.propertyAnnotation)
fieldPropertyAnnotations.serializeAnnotations(proto, protocol.propertyBackingFieldAnnotation)
delegatePropertyAnnotations.serializeAnnotations(proto, protocol.propertyDelegatedFieldAnnotation)