[klib] Fix serialization of missing annotations

^KT-42490
^KT-44625
This commit is contained in:
Pavel Kunyavskiy
2022-12-12 17:27:41 +01:00
committed by Space Team
parent 90d702ed27
commit 17e9a6a781
21 changed files with 526 additions and 106 deletions
@@ -26,9 +26,13 @@ open class SerializerExtensionProtocol(
val constructorAnnotation: GeneratedExtension<ProtoBuf.Constructor, List<ProtoBuf.Annotation>>,
val classAnnotation: GeneratedExtension<ProtoBuf.Class, List<ProtoBuf.Annotation>>,
val functionAnnotation: GeneratedExtension<ProtoBuf.Function, List<ProtoBuf.Annotation>>,
val functionExtensionReceiverAnnotation: GeneratedExtension<ProtoBuf.Function, List<ProtoBuf.Annotation>>?,
val propertyAnnotation: GeneratedExtension<ProtoBuf.Property, List<ProtoBuf.Annotation>>,
val propertyGetterAnnotation: GeneratedExtension<ProtoBuf.Property, List<ProtoBuf.Annotation>>,
val propertySetterAnnotation: GeneratedExtension<ProtoBuf.Property, List<ProtoBuf.Annotation>>,
val propertyExtensionReceiverAnnotation: GeneratedExtension<ProtoBuf.Property, List<ProtoBuf.Annotation>>?,
val propertyBackingFieldAnnotation: GeneratedExtension<ProtoBuf.Property, List<ProtoBuf.Annotation>>?,
val propertyDelegatedFieldAnnotation: GeneratedExtension<ProtoBuf.Property, List<ProtoBuf.Annotation>>?,
val enumEntryAnnotation: GeneratedExtension<ProtoBuf.EnumEntry, List<ProtoBuf.Annotation>>,
val compileTimeValue: GeneratedExtension<ProtoBuf.Property, ProtoBuf.Annotation.Argument.Value>,
val parameterAnnotation: GeneratedExtension<ProtoBuf.ValueParameter, List<ProtoBuf.Annotation>>,
@@ -16,9 +16,13 @@ object BuiltInSerializerProtocol : SerializerExtensionProtocol(
BuiltInsProtoBuf.constructorAnnotation,
BuiltInsProtoBuf.classAnnotation,
BuiltInsProtoBuf.functionAnnotation,
functionExtensionReceiverAnnotation = null,
BuiltInsProtoBuf.propertyAnnotation,
BuiltInsProtoBuf.propertyGetterAnnotation,
BuiltInsProtoBuf.propertySetterAnnotation,
propertyExtensionReceiverAnnotation = null,
propertyBackingFieldAnnotation = null,
propertyDelegatedFieldAnnotation = null,
BuiltInsProtoBuf.enumEntryAnnotation,
BuiltInsProtoBuf.compileTimeValue,
BuiltInsProtoBuf.parameterAnnotation,
@@ -60,11 +60,19 @@ class AnnotationAndConstantLoaderImpl(
}
}
override fun loadPropertyBackingFieldAnnotations(container: ProtoContainer, proto: ProtoBuf.Property): List<AnnotationDescriptor> =
emptyList()
override fun loadPropertyBackingFieldAnnotations(container: ProtoContainer, proto: ProtoBuf.Property): List<AnnotationDescriptor> {
val annotations = protocol.propertyBackingFieldAnnotation?.let { proto.getExtension(it) }.orEmpty()
return annotations.map { annotationProto ->
deserializer.deserializeAnnotation(annotationProto, container.nameResolver)
}
}
override fun loadPropertyDelegateFieldAnnotations(container: ProtoContainer, proto: ProtoBuf.Property): List<AnnotationDescriptor> =
emptyList()
override fun loadPropertyDelegateFieldAnnotations(container: ProtoContainer, proto: ProtoBuf.Property): List<AnnotationDescriptor> {
val annotations = protocol.propertyDelegatedFieldAnnotation?.let {proto.getExtension(it) }.orEmpty()
return annotations.map { annotationProto ->
deserializer.deserializeAnnotation(annotationProto, container.nameResolver)
}
}
override fun loadEnumEntryAnnotations(container: ProtoContainer, proto: ProtoBuf.EnumEntry): List<AnnotationDescriptor> {
val annotations = proto.getExtension(protocol.enumEntryAnnotation).orEmpty()
@@ -90,7 +98,21 @@ class AnnotationAndConstantLoaderImpl(
container: ProtoContainer,
proto: MessageLite,
kind: AnnotatedCallableKind
): List<AnnotationDescriptor> = emptyList()
): List<AnnotationDescriptor> {
val annotations = when (proto) {
is ProtoBuf.Function -> protocol.functionExtensionReceiverAnnotation?.let { proto.getExtension(it) }
is ProtoBuf.Property -> when (kind) {
AnnotatedCallableKind.PROPERTY, AnnotatedCallableKind.PROPERTY_GETTER, AnnotatedCallableKind.PROPERTY_SETTER -> {
protocol.propertyExtensionReceiverAnnotation?.let { proto.getExtension(it) }
}
else -> error("Unsupported callable kind with property proto for receiver annotations: $kind")
}
else -> error("Unknown message: $proto")
}.orEmpty()
return annotations.map { annotationProto ->
deserializer.deserializeAnnotation(annotationProto, container.nameResolver)
}
}
override fun loadTypeAnnotations(proto: ProtoBuf.Type, nameResolver: NameResolver): List<AnnotationDescriptor> {
return proto.getExtension(protocol.typeAnnotation).orEmpty().map { deserializer.deserializeAnnotation(it, nameResolver) }