Use AnnotationSplitter for annotations on extension receiver

Instead of using `@receiver:`-targeted annotations on the receiver type,
use normal annotations of the ReceiverParameterDescriptor instance
everywhere
This commit is contained in:
Alexander Udalov
2018-08-08 18:54:49 +02:00
parent 823a24e0a3
commit 0e5544a491
10 changed files with 54 additions and 99 deletions
@@ -7,8 +7,6 @@ package org.jetbrains.kotlin.serialization.deserialization
import org.jetbrains.kotlin.builtins.isSuspendFunctionType
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.AnnotationUseSiteTarget
import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.annotations.AnnotationsImpl
import org.jetbrains.kotlin.descriptors.impl.PropertyGetterDescriptorImpl
@@ -63,8 +61,8 @@ class MemberDeserializer(private val c: DeserializationContext) {
local.typeDeserializer.type(proto.returnType(c.typeTable)),
local.typeDeserializer.ownTypeParameters,
getDispatchReceiverParameter(),
proto.receiverType(c.typeTable)?.let { local.typeDeserializer.type(it, receiverAnnotations) }?.let { receiverType ->
DescriptorFactory.createExtensionReceiverParameterForCallable(property, receiverType, Annotations.EMPTY)
proto.receiverType(c.typeTable)?.let(local.typeDeserializer::type)?.let { receiverType ->
DescriptorFactory.createExtensionReceiverParameterForCallable(property, receiverType, receiverAnnotations)
}
)
@@ -257,8 +255,8 @@ class MemberDeserializer(private val c: DeserializationContext) {
val local = c.childContext(function, proto.typeParameterList)
function.initializeWithCoroutinesExperimentalityStatus(
proto.receiverType(c.typeTable)?.let { local.typeDeserializer.type(it, receiverAnnotations) }?.let { receiverType ->
DescriptorFactory.createExtensionReceiverParameterForCallable(function, receiverType, Annotations.EMPTY)
proto.receiverType(c.typeTable)?.let(local.typeDeserializer::type)?.let { receiverType ->
DescriptorFactory.createExtensionReceiverParameterForCallable(function, receiverType, receiverAnnotations)
},
getDispatchReceiverParameter(),
local.typeDeserializer.ownTypeParameters,
@@ -351,20 +349,12 @@ class MemberDeserializer(private val c: DeserializationContext) {
}
}
private fun getReceiverParameterAnnotations(
proto: MessageLite,
kind: AnnotatedCallableKind,
receiverTargetedKind: AnnotatedCallableKind = kind
): Annotations {
return DeserializedAnnotationsWithPossibleTargets(c.storageManager) {
private fun getReceiverParameterAnnotations(proto: MessageLite, kind: AnnotatedCallableKind): Annotations =
DeserializedAnnotations(c.storageManager) {
c.containingDeclaration.asProtoContainer()?.let {
c.components.annotationAndConstantLoader
.loadExtensionReceiverParameterAnnotations(it, proto, receiverTargetedKind)
.map { annotation -> AnnotationWithTarget(annotation, AnnotationUseSiteTarget.RECEIVER) }
.toList()
c.components.annotationAndConstantLoader.loadExtensionReceiverParameterAnnotations(it, proto, kind)
}.orEmpty()
}
}
private fun valueParameters(
valueParameters: List<ProtoBuf.ValueParameter>,
@@ -7,14 +7,13 @@ package org.jetbrains.kotlin.serialization.deserialization
import org.jetbrains.kotlin.builtins.*
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.AnnotationWithTarget
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.metadata.ProtoBuf
import org.jetbrains.kotlin.metadata.deserialization.*
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotationsWithPossibleTargets
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedAnnotations
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedTypeParameterDescriptor
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.typeUtil.builtIns
@@ -52,18 +51,18 @@ class TypeDeserializer(
get() = typeParameterDescriptors.values.toList()
// TODO: don't load identical types from TypeTable more than once
fun type(proto: ProtoBuf.Type, additionalAnnotations: Annotations = Annotations.EMPTY): KotlinType {
fun type(proto: ProtoBuf.Type): KotlinType {
if (proto.hasFlexibleTypeCapabilitiesId()) {
val id = c.nameResolver.getString(proto.flexibleTypeCapabilitiesId)
val lowerBound = simpleType(proto, additionalAnnotations)
val upperBound = simpleType(proto.flexibleUpperBound(c.typeTable)!!, additionalAnnotations)
val lowerBound = simpleType(proto)
val upperBound = simpleType(proto.flexibleUpperBound(c.typeTable)!!)
return c.components.flexibleTypeDeserializer.create(proto, id, lowerBound, upperBound)
}
return simpleType(proto, additionalAnnotations)
return simpleType(proto)
}
fun simpleType(proto: ProtoBuf.Type, additionalAnnotations: Annotations = Annotations.EMPTY): SimpleType {
fun simpleType(proto: ProtoBuf.Type): SimpleType {
val localClassifierType = when {
proto.hasClassName() -> computeLocalClassifierReplacementType(proto.className)
proto.hasTypeAliasName() -> computeLocalClassifierReplacementType(proto.typeAliasName)
@@ -77,11 +76,8 @@ class TypeDeserializer(
return ErrorUtils.createErrorTypeWithCustomConstructor(constructor.toString(), constructor)
}
val annotations = DeserializedAnnotationsWithPossibleTargets(c.storageManager) {
val annotations = DeserializedAnnotations(c.storageManager) {
c.components.annotationAndConstantLoader.loadTypeAnnotations(proto, c.nameResolver)
.map { AnnotationWithTarget(it, null) }
.plus(additionalAnnotations.getAllAnnotations())
.toList()
}
fun ProtoBuf.Type.collectAllArguments(): List<ProtoBuf.Type.Argument> =
@@ -98,7 +94,7 @@ class TypeDeserializer(
}
val abbreviatedTypeProto = proto.abbreviatedType(c.typeTable) ?: return simpleType
return simpleType.withAbbreviation(simpleType(abbreviatedTypeProto, additionalAnnotations))
return simpleType.withAbbreviation(simpleType(abbreviatedTypeProto))
}
private fun typeConstructor(proto: ProtoBuf.Type): TypeConstructor {
@@ -18,7 +18,6 @@ package org.jetbrains.kotlin.serialization.deserialization.descriptors
import org.jetbrains.kotlin.descriptors.SourceElement
import org.jetbrains.kotlin.descriptors.SupertypeLoopChecker
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.AbstractLazyTypeParameterDescriptor
import org.jetbrains.kotlin.metadata.ProtoBuf
import org.jetbrains.kotlin.metadata.deserialization.upperBounds
@@ -45,9 +44,7 @@ class DeserializedTypeParameterDescriptor(
if (upperBounds.isEmpty()) {
return listOf(this.builtIns.defaultBound)
}
return upperBounds.map {
c.typeDeserializer.type(it, Annotations.EMPTY)
}
return upperBounds.map(c.typeDeserializer::type)
}
override fun reportSupertypeLoopError(type: KotlinType) = throw IllegalStateException(