FIR deserializer: use annotation info from enclosing class for companion object
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
81345bcc26
commit
a18bd1bb75
+1
-1
@@ -7,7 +7,7 @@ public final class Class : R|kotlin/Any| {
|
|||||||
public constructor(): R|test/Class|
|
public constructor(): R|test/Class|
|
||||||
|
|
||||||
public final companion object Companion : R|kotlin/Any| {
|
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 get(): R|kotlin/Int|
|
||||||
public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
public set(value: R|kotlin/Int|): R|kotlin/Unit|
|
||||||
|
|
||||||
|
|||||||
+7
-3
@@ -30,12 +30,16 @@ class JvmBinaryAnnotationDeserializer(
|
|||||||
kotlinBinaryClass: KotlinJvmBinaryClass,
|
kotlinBinaryClass: KotlinJvmBinaryClass,
|
||||||
byteContent: ByteArray?
|
byteContent: ByteArray?
|
||||||
) : AbstractAnnotationDeserializer(session) {
|
) : 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) {
|
private val annotationInfo by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||||
session.loadMemberAnnotations(kotlinBinaryClass, byteContent)
|
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> {
|
override fun loadTypeAnnotations(typeProto: ProtoBuf.Type, nameResolver: NameResolver): List<FirAnnotationCall> {
|
||||||
val annotations = typeProto.getExtension(JvmProtoBuf.typeAnnotation).orEmpty()
|
val annotations = typeProto.getExtension(JvmProtoBuf.typeAnnotation).orEmpty()
|
||||||
return annotations.map { deserializeAnnotation(it, nameResolver) }
|
return annotations.map { deserializeAnnotation(it, nameResolver) }
|
||||||
@@ -244,7 +248,7 @@ class JvmBinaryAnnotationDeserializer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Rename this once property constants are recorded as well
|
// 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?
|
// TODO: better to be in KotlinDeserializedJvmSymbolsProvider?
|
||||||
private fun FirSession.loadMemberAnnotations(kotlinBinaryClass: KotlinJvmBinaryClass, byteContent: ByteArray?): MemberAnnotations {
|
private fun FirSession.loadMemberAnnotations(kotlinBinaryClass: KotlinJvmBinaryClass, byteContent: ByteArray?): MemberAnnotations {
|
||||||
|
|||||||
+3
@@ -42,6 +42,9 @@ abstract class AbstractAnnotationDeserializer(
|
|||||||
) {
|
) {
|
||||||
protected val protocol = BuiltInSerializerProtocol
|
protected val protocol = BuiltInSerializerProtocol
|
||||||
|
|
||||||
|
open fun inheritAnnotationInfo(parent: AbstractAnnotationDeserializer) {
|
||||||
|
}
|
||||||
|
|
||||||
enum class CallableKind {
|
enum class CallableKind {
|
||||||
PROPERTY,
|
PROPERTY,
|
||||||
PROPERTY_GETTER,
|
PROPERTY_GETTER,
|
||||||
|
|||||||
+5
@@ -89,6 +89,11 @@ fun deserializeClassToSymbol(
|
|||||||
FirConstDeserializer(session, (containerSource as? KotlinJvmBinarySourceElement)?.binaryClass),
|
FirConstDeserializer(session, (containerSource as? KotlinJvmBinarySourceElement)?.binaryClass),
|
||||||
containerSource
|
containerSource
|
||||||
)
|
)
|
||||||
|
if (status.isCompanion) {
|
||||||
|
parentContext?.let {
|
||||||
|
context.annotationDeserializer.inheritAnnotationInfo(it.annotationDeserializer)
|
||||||
|
}
|
||||||
|
}
|
||||||
buildRegularClass {
|
buildRegularClass {
|
||||||
this.session = session
|
this.session = session
|
||||||
origin = FirDeclarationOrigin.Library
|
origin = FirDeclarationOrigin.Library
|
||||||
|
|||||||
Reference in New Issue
Block a user