FIR deserializer: use annotation info from enclosing class for companion object

This commit is contained in:
Jinseong Jeon
2020-07-06 15:54:25 -07:00
committed by Dmitriy Novozhilov
parent 81345bcc26
commit a18bd1bb75
4 changed files with 16 additions and 4 deletions
@@ -7,7 +7,7 @@ public final class Class : R|kotlin/Any| {
public constructor(): R|test/Class|
public final companion object Companion : R|kotlin/Any| {
public final var property: R|kotlin/Int|
@FIELD:R|test/Anno|() public final var property: R|kotlin/Int|
public get(): R|kotlin/Int|
public set(value: R|kotlin/Int|): R|kotlin/Unit|
@@ -30,12 +30,16 @@ class JvmBinaryAnnotationDeserializer(
kotlinBinaryClass: KotlinJvmBinaryClass,
byteContent: ByteArray?
) : AbstractAnnotationDeserializer(session) {
// TODO: In order to properly load annotations on fields inside a companion object,
// we need binary classes for both the companion class and the enclosing class.
private val annotationInfo by lazy(LazyThreadSafetyMode.PUBLICATION) {
session.loadMemberAnnotations(kotlinBinaryClass, byteContent)
}
override fun inheritAnnotationInfo(parent: AbstractAnnotationDeserializer) {
if (parent is JvmBinaryAnnotationDeserializer) {
annotationInfo.memberAnnotations.putAll(parent.annotationInfo.memberAnnotations)
}
}
override fun loadTypeAnnotations(typeProto: ProtoBuf.Type, nameResolver: NameResolver): List<FirAnnotationCall> {
val annotations = typeProto.getExtension(JvmProtoBuf.typeAnnotation).orEmpty()
return annotations.map { deserializeAnnotation(it, nameResolver) }
@@ -244,7 +248,7 @@ class JvmBinaryAnnotationDeserializer(
}
// TODO: Rename this once property constants are recorded as well
private data class MemberAnnotations(val memberAnnotations: Map<MemberSignature, MutableList<FirAnnotationCall>>)
private data class MemberAnnotations(val memberAnnotations: MutableMap<MemberSignature, MutableList<FirAnnotationCall>>)
// TODO: better to be in KotlinDeserializedJvmSymbolsProvider?
private fun FirSession.loadMemberAnnotations(kotlinBinaryClass: KotlinJvmBinaryClass, byteContent: ByteArray?): MemberAnnotations {
@@ -42,6 +42,9 @@ abstract class AbstractAnnotationDeserializer(
) {
protected val protocol = BuiltInSerializerProtocol
open fun inheritAnnotationInfo(parent: AbstractAnnotationDeserializer) {
}
enum class CallableKind {
PROPERTY,
PROPERTY_GETTER,
@@ -89,6 +89,11 @@ fun deserializeClassToSymbol(
FirConstDeserializer(session, (containerSource as? KotlinJvmBinarySourceElement)?.binaryClass),
containerSource
)
if (status.isCompanion) {
parentContext?.let {
context.annotationDeserializer.inheritAnnotationInfo(it.annotationDeserializer)
}
}
buildRegularClass {
this.session = session
origin = FirDeclarationOrigin.Library