Minor, take ProtoContainer in AnnotationAndConstantLoader#loadClassAnnotations
This commit is contained in:
+3
-4
@@ -66,13 +66,12 @@ abstract class AbstractBinaryClassAnnotationAndConstantLoader<A : Any, C : Any,
|
|||||||
return loadAnnotation(annotationClassId, source, result)
|
return loadAnnotation(annotationClassId, source, result)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadClassAnnotations(classProto: ProtoBuf.Class, nameResolver: NameResolver): List<A> {
|
override fun loadClassAnnotations(container: ProtoContainer.Class): List<A> {
|
||||||
val classId = nameResolver.getClassId(classProto.fqName)
|
val kotlinClass = kotlinClassFinder.findKotlinClass(container.classId)
|
||||||
val kotlinClass = kotlinClassFinder.findKotlinClass(classId)
|
|
||||||
if (kotlinClass == null) {
|
if (kotlinClass == null) {
|
||||||
// This means that the resource we're constructing the descriptor from is no longer present: KotlinClassFinder had found the
|
// This means that the resource we're constructing the descriptor from is no longer present: KotlinClassFinder had found the
|
||||||
// class earlier, but it can't now
|
// class earlier, but it can't now
|
||||||
errorReporter.reportLoadingError("Kotlin class for loading class annotations is not found: ${classId.asSingleFqName()}", null)
|
errorReporter.reportLoadingError("Kotlin class for loading class annotations is not found: ${container.debugFqName()}", null)
|
||||||
return listOf()
|
return listOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -24,8 +24,7 @@ import org.jetbrains.kotlin.types.KotlinType
|
|||||||
// TODO: simplify this interface
|
// TODO: simplify this interface
|
||||||
interface AnnotationAndConstantLoader<A : Any, C : Any, T : Any> {
|
interface AnnotationAndConstantLoader<A : Any, C : Any, T : Any> {
|
||||||
fun loadClassAnnotations(
|
fun loadClassAnnotations(
|
||||||
classProto: ProtoBuf.Class,
|
container: ProtoContainer.Class
|
||||||
nameResolver: NameResolver
|
|
||||||
): List<A>
|
): List<A>
|
||||||
|
|
||||||
fun loadCallableAnnotations(
|
fun loadCallableAnnotations(
|
||||||
|
|||||||
+3
-6
@@ -32,12 +32,9 @@ class AnnotationAndConstantLoaderImpl(
|
|||||||
) : AnnotationAndConstantLoader<AnnotationDescriptor, ConstantValue<*>, AnnotationWithTarget> {
|
) : AnnotationAndConstantLoader<AnnotationDescriptor, ConstantValue<*>, AnnotationWithTarget> {
|
||||||
private val deserializer = AnnotationDeserializer(module, notFoundClasses)
|
private val deserializer = AnnotationDeserializer(module, notFoundClasses)
|
||||||
|
|
||||||
override fun loadClassAnnotations(
|
override fun loadClassAnnotations(container: ProtoContainer.Class): List<AnnotationDescriptor> {
|
||||||
classProto: ProtoBuf.Class,
|
val annotations = container.classProto.getExtension(protocol.classAnnotation).orEmpty()
|
||||||
nameResolver: NameResolver
|
return annotations.map { proto -> deserializer.deserializeAnnotation(proto, container.nameResolver) }
|
||||||
): List<AnnotationDescriptor> {
|
|
||||||
val annotations = classProto.getExtension(protocol.classAnnotation).orEmpty()
|
|
||||||
return annotations.map { proto -> deserializer.deserializeAnnotation(proto, nameResolver) }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun loadCallableAnnotations(
|
override fun loadCallableAnnotations(
|
||||||
|
|||||||
+1
-3
@@ -241,9 +241,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
|
|||||||
|
|
||||||
private fun DeclarationDescriptor.asProtoContainer(): ProtoContainer? = when (this) {
|
private fun DeclarationDescriptor.asProtoContainer(): ProtoContainer? = when (this) {
|
||||||
is PackageFragmentDescriptor -> ProtoContainer.Package(fqName, c.nameResolver, c.typeTable, c.packagePartSource)
|
is PackageFragmentDescriptor -> ProtoContainer.Package(fqName, c.nameResolver, c.typeTable, c.packagePartSource)
|
||||||
is DeserializedClassDescriptor -> ProtoContainer.Class(
|
is DeserializedClassDescriptor -> thisAsProtoContainer
|
||||||
classProto, c.nameResolver, c.typeTable, (containingDeclaration as? ClassDescriptor)?.kind
|
|
||||||
)
|
|
||||||
else -> null // TODO: support annotations on lambdas and their parameters
|
else -> null // TODO: support annotations on lambdas and their parameters
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-4
@@ -73,12 +73,15 @@ class DeserializedClassDescriptor(
|
|||||||
private val constructors = c.storageManager.createLazyValue { computeConstructors() }
|
private val constructors = c.storageManager.createLazyValue { computeConstructors() }
|
||||||
private val companionObjectDescriptor = c.storageManager.createNullableLazyValue { computeCompanionObjectDescriptor() }
|
private val companionObjectDescriptor = c.storageManager.createNullableLazyValue { computeCompanionObjectDescriptor() }
|
||||||
|
|
||||||
|
internal val thisAsProtoContainer =
|
||||||
|
ProtoContainer.Class(classProto, c.nameResolver, c.typeTable, (containingDeclaration as? ClassDescriptor)?.kind)
|
||||||
|
|
||||||
private val annotations =
|
private val annotations =
|
||||||
if (!Flags.HAS_ANNOTATIONS.get(classProto.flags)) {
|
if (!Flags.HAS_ANNOTATIONS.get(classProto.flags)) {
|
||||||
Annotations.EMPTY
|
Annotations.EMPTY
|
||||||
}
|
}
|
||||||
else DeserializedAnnotations(c.storageManager) {
|
else DeserializedAnnotations(c.storageManager) {
|
||||||
c.components.annotationAndConstantLoader.loadClassAnnotations(classProto, c.nameResolver)
|
c.components.annotationAndConstantLoader.loadClassAnnotations(thisAsProtoContainer)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getContainingDeclaration(): DeclarationDescriptor = containingDeclaration
|
override fun getContainingDeclaration(): DeclarationDescriptor = containingDeclaration
|
||||||
@@ -284,8 +287,6 @@ class DeserializedClassDescriptor(
|
|||||||
|
|
||||||
private inner class EnumEntryClassDescriptors {
|
private inner class EnumEntryClassDescriptors {
|
||||||
private val enumEntryProtos = classProto.enumEntryList.associateBy { c.nameResolver.getName(it.name) }
|
private val enumEntryProtos = classProto.enumEntryList.associateBy { c.nameResolver.getName(it.name) }
|
||||||
private val protoContainer =
|
|
||||||
ProtoContainer.Class(classProto, c.nameResolver, c.typeTable, (containingDeclaration as? ClassDescriptor)?.kind)
|
|
||||||
|
|
||||||
val enumEntryByName = c.storageManager.createMemoizedFunctionWithNullableValues<Name, ClassDescriptor> {
|
val enumEntryByName = c.storageManager.createMemoizedFunctionWithNullableValues<Name, ClassDescriptor> {
|
||||||
name ->
|
name ->
|
||||||
@@ -294,7 +295,7 @@ class DeserializedClassDescriptor(
|
|||||||
EnumEntrySyntheticClassDescriptor.create(
|
EnumEntrySyntheticClassDescriptor.create(
|
||||||
c.storageManager, this@DeserializedClassDescriptor, name, enumMemberNames,
|
c.storageManager, this@DeserializedClassDescriptor, name, enumMemberNames,
|
||||||
DeserializedAnnotations(c.storageManager) {
|
DeserializedAnnotations(c.storageManager) {
|
||||||
c.components.annotationAndConstantLoader.loadEnumEntryAnnotations(protoContainer, proto)
|
c.components.annotationAndConstantLoader.loadEnumEntryAnnotations(thisAsProtoContainer, proto)
|
||||||
},
|
},
|
||||||
SourceElement.NO_SOURCE
|
SourceElement.NO_SOURCE
|
||||||
)
|
)
|
||||||
|
|||||||
+2
-4
@@ -31,10 +31,8 @@ class AnnotationLoaderForStubBuilderImpl(
|
|||||||
private val protocol: SerializerExtensionProtocol
|
private val protocol: SerializerExtensionProtocol
|
||||||
) : AnnotationAndConstantLoader<ClassId, Unit, ClassIdWithTarget> {
|
) : AnnotationAndConstantLoader<ClassId, Unit, ClassIdWithTarget> {
|
||||||
|
|
||||||
override fun loadClassAnnotations(
|
override fun loadClassAnnotations(container: ProtoContainer.Class): List<ClassId> =
|
||||||
classProto: ProtoBuf.Class, nameResolver: NameResolver
|
container.classProto.getExtension(protocol.classAnnotation).orEmpty().map { container.nameResolver.getClassId(it.id) }
|
||||||
): List<ClassId> =
|
|
||||||
classProto.getExtension(protocol.classAnnotation).orEmpty().map { nameResolver.getClassId(it.id) }
|
|
||||||
|
|
||||||
override fun loadCallableAnnotations(
|
override fun loadCallableAnnotations(
|
||||||
container: ProtoContainer,
|
container: ProtoContainer,
|
||||||
|
|||||||
+1
-1
@@ -90,7 +90,7 @@ private class ClassClsStubBuilder(
|
|||||||
val classOrObjectStub = doCreateClassOrObjectStub()
|
val classOrObjectStub = doCreateClassOrObjectStub()
|
||||||
val modifierList = createModifierListForClass(classOrObjectStub)
|
val modifierList = createModifierListForClass(classOrObjectStub)
|
||||||
if (Flags.HAS_ANNOTATIONS.get(classProto.flags)) {
|
if (Flags.HAS_ANNOTATIONS.get(classProto.flags)) {
|
||||||
createAnnotationStubs(c.components.annotationLoader.loadClassAnnotations(classProto, c.nameResolver), modifierList)
|
createAnnotationStubs(c.components.annotationLoader.loadClassAnnotations(thisAsProtoContainer), modifierList)
|
||||||
}
|
}
|
||||||
return classOrObjectStub
|
return classOrObjectStub
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user