Minor, take ProtoContainer in AnnotationAndConstantLoader#loadClassAnnotations

This commit is contained in:
Alexander Udalov
2016-04-06 15:26:40 +03:00
parent 2ab68d53fa
commit ac92be12c6
7 changed files with 16 additions and 24 deletions
@@ -24,8 +24,7 @@ import org.jetbrains.kotlin.types.KotlinType
// TODO: simplify this interface
interface AnnotationAndConstantLoader<A : Any, C : Any, T : Any> {
fun loadClassAnnotations(
classProto: ProtoBuf.Class,
nameResolver: NameResolver
container: ProtoContainer.Class
): List<A>
fun loadCallableAnnotations(
@@ -32,12 +32,9 @@ class AnnotationAndConstantLoaderImpl(
) : AnnotationAndConstantLoader<AnnotationDescriptor, ConstantValue<*>, AnnotationWithTarget> {
private val deserializer = AnnotationDeserializer(module, notFoundClasses)
override fun loadClassAnnotations(
classProto: ProtoBuf.Class,
nameResolver: NameResolver
): List<AnnotationDescriptor> {
val annotations = classProto.getExtension(protocol.classAnnotation).orEmpty()
return annotations.map { proto -> deserializer.deserializeAnnotation(proto, nameResolver) }
override fun loadClassAnnotations(container: ProtoContainer.Class): List<AnnotationDescriptor> {
val annotations = container.classProto.getExtension(protocol.classAnnotation).orEmpty()
return annotations.map { proto -> deserializer.deserializeAnnotation(proto, container.nameResolver) }
}
override fun loadCallableAnnotations(
@@ -241,9 +241,7 @@ class MemberDeserializer(private val c: DeserializationContext) {
private fun DeclarationDescriptor.asProtoContainer(): ProtoContainer? = when (this) {
is PackageFragmentDescriptor -> ProtoContainer.Package(fqName, c.nameResolver, c.typeTable, c.packagePartSource)
is DeserializedClassDescriptor -> ProtoContainer.Class(
classProto, c.nameResolver, c.typeTable, (containingDeclaration as? ClassDescriptor)?.kind
)
is DeserializedClassDescriptor -> thisAsProtoContainer
else -> null // TODO: support annotations on lambdas and their parameters
}
}
@@ -73,12 +73,15 @@ class DeserializedClassDescriptor(
private val constructors = c.storageManager.createLazyValue { computeConstructors() }
private val companionObjectDescriptor = c.storageManager.createNullableLazyValue { computeCompanionObjectDescriptor() }
internal val thisAsProtoContainer =
ProtoContainer.Class(classProto, c.nameResolver, c.typeTable, (containingDeclaration as? ClassDescriptor)?.kind)
private val annotations =
if (!Flags.HAS_ANNOTATIONS.get(classProto.flags)) {
Annotations.EMPTY
}
else DeserializedAnnotations(c.storageManager) {
c.components.annotationAndConstantLoader.loadClassAnnotations(classProto, c.nameResolver)
c.components.annotationAndConstantLoader.loadClassAnnotations(thisAsProtoContainer)
}
override fun getContainingDeclaration(): DeclarationDescriptor = containingDeclaration
@@ -284,8 +287,6 @@ class DeserializedClassDescriptor(
private inner class EnumEntryClassDescriptors {
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> {
name ->
@@ -294,7 +295,7 @@ class DeserializedClassDescriptor(
EnumEntrySyntheticClassDescriptor.create(
c.storageManager, this@DeserializedClassDescriptor, name, enumMemberNames,
DeserializedAnnotations(c.storageManager) {
c.components.annotationAndConstantLoader.loadEnumEntryAnnotations(protoContainer, proto)
c.components.annotationAndConstantLoader.loadEnumEntryAnnotations(thisAsProtoContainer, proto)
},
SourceElement.NO_SOURCE
)