Load default values for annotation members from classfiles

so that defaults are available to synthetic implementations.

#KT-48181 Fixed

Implementation is for JVM IR; other backends & FIR need to be supported
separately.
This commit is contained in:
Leonid Startsev
2021-11-19 15:32:28 +03:00
committed by Space
parent e8868a2eff
commit 767c570af4
18 changed files with 339 additions and 109 deletions
@@ -78,4 +78,10 @@ interface AnnotationAndConstantLoader<out A : Any, out C : Any> {
proto: ProtoBuf.Property,
expectedType: KotlinType
): C?
fun loadAnnotationDefaultValue(
container: ProtoContainer,
proto: ProtoBuf.Property,
expectedType: KotlinType
): C?
}
@@ -104,4 +104,13 @@ class AnnotationAndConstantLoaderImpl(
val value = proto.getExtensionOrNull(protocol.compileTimeValue) ?: return null
return deserializer.resolveValue(expectedType, value, container.nameResolver)
}
override fun loadAnnotationDefaultValue(
container: ProtoContainer,
proto: ProtoBuf.Property,
expectedType: KotlinType
): ConstantValue<*>? {
// Implement this method to properly support Annotations Instantiation feature
return null
}
}
@@ -140,6 +140,15 @@ class MemberDeserializer(private val c: DeserializationContext) {
)
}
if ((c.containingDeclaration as? ClassDescriptor)?.kind == ClassKind.ANNOTATION_CLASS) {
property.setCompileTimeInitializer(
c.storageManager.createNullableLazyValue {
val container = c.containingDeclaration.asProtoContainer()!!
c.components.annotationAndConstantLoader.loadAnnotationDefaultValue(container, proto, property.returnType)
}
)
}
property.initialize(
getter, setter,
FieldDescriptorImpl(getPropertyFieldAnnotations(proto, isDelegate = false), property),