From 53a57e8e1bfbf2a0ad15e29db696739eccd7a710 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 11 Jul 2018 18:38:23 +0200 Subject: [PATCH] Reformat module 'deserialization', fix warnings/inspections --- .../SerializerExtensionProtocol.kt | 22 +-- ...ractDeserializedPackageFragmentProvider.kt | 6 +- .../AnnotationAndConstantLoader.kt | 42 ++--- .../AnnotationAndConstantLoaderImpl.kt | 51 +++--- .../deserialization/AnnotationDeserializer.kt | 78 ++++----- .../deserialization/ClassDeserializer.kt | 21 ++- .../deserialization/ContractDeserializer.kt | 18 +- .../DeserializedPackageFragment.kt | 6 +- .../FlexibleTypeDeserializer.kt | 4 +- .../IncompatibleVersionErrorData.kt | 8 +- .../deserialization/MemberDeserializer.kt | 2 +- .../MetadataPackageFragmentProvider.kt | 64 +++---- .../ProtoBasedClassDataFinder.kt | 12 +- .../deserialization/ProtoContainer.kt | 24 +-- .../deserialization/TypeDeserializer.kt | 18 +- .../serialization/deserialization/context.kt | 86 +++++----- .../descriptors/DeserializedAnnotations.kt | 18 +- .../DeserializedClassDescriptor.kt | 102 ++++++----- .../DeserializedMemberDescriptor.kt | 162 +++++++++--------- .../descriptors/DeserializedMemberScope.kt | 66 +++---- .../DeserializedPackageMemberScope.kt | 29 ++-- .../DeserializedTypeParameterDescriptor.kt | 9 +- 22 files changed, 423 insertions(+), 425 deletions(-) diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/SerializerExtensionProtocol.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/SerializerExtensionProtocol.kt index 80e2f9176b0..1ce16c97315 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/SerializerExtensionProtocol.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/SerializerExtensionProtocol.kt @@ -21,15 +21,15 @@ import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite import org.jetbrains.kotlin.protobuf.GeneratedMessageLite.GeneratedExtension open class SerializerExtensionProtocol( - val extensionRegistry: ExtensionRegistryLite, - val packageFqName: GeneratedExtension, - val constructorAnnotation: GeneratedExtension>, - val classAnnotation: GeneratedExtension>, - val functionAnnotation: GeneratedExtension>, - val propertyAnnotation: GeneratedExtension>, - val enumEntryAnnotation: GeneratedExtension>, - val compileTimeValue: GeneratedExtension, - val parameterAnnotation: GeneratedExtension>, - val typeAnnotation: GeneratedExtension>, - val typeParameterAnnotation: GeneratedExtension> + val extensionRegistry: ExtensionRegistryLite, + val packageFqName: GeneratedExtension, + val constructorAnnotation: GeneratedExtension>, + val classAnnotation: GeneratedExtension>, + val functionAnnotation: GeneratedExtension>, + val propertyAnnotation: GeneratedExtension>, + val enumEntryAnnotation: GeneratedExtension>, + val compileTimeValue: GeneratedExtension, + val parameterAnnotation: GeneratedExtension>, + val typeAnnotation: GeneratedExtension>, + val typeParameterAnnotation: GeneratedExtension> ) diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AbstractDeserializedPackageFragmentProvider.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AbstractDeserializedPackageFragmentProvider.kt index 6d2152cb857..275674056fd 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AbstractDeserializedPackageFragmentProvider.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AbstractDeserializedPackageFragmentProvider.kt @@ -24,9 +24,9 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.storage.StorageManager abstract class AbstractDeserializedPackageFragmentProvider( - protected val storageManager: StorageManager, - protected val finder: KotlinMetadataFinder, - protected val moduleDescriptor: ModuleDescriptor + protected val storageManager: StorageManager, + protected val finder: KotlinMetadataFinder, + protected val moduleDescriptor: ModuleDescriptor ) : PackageFragmentProvider { protected lateinit var components: DeserializationComponents diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoader.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoader.kt index 17027f12578..d3fbbe53e65 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoader.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoader.kt @@ -25,47 +25,47 @@ import org.jetbrains.kotlin.types.KotlinType // TODO: simplify this interface interface AnnotationAndConstantLoader { fun loadClassAnnotations( - container: ProtoContainer.Class + container: ProtoContainer.Class ): List fun loadCallableAnnotations( - container: ProtoContainer, - proto: MessageLite, - kind: AnnotatedCallableKind + container: ProtoContainer, + proto: MessageLite, + kind: AnnotatedCallableKind ): List fun loadEnumEntryAnnotations( - container: ProtoContainer, - proto: ProtoBuf.EnumEntry + container: ProtoContainer, + proto: ProtoBuf.EnumEntry ): List fun loadValueParameterAnnotations( - container: ProtoContainer, - callableProto: MessageLite, - kind: AnnotatedCallableKind, - parameterIndex: Int, - proto: ProtoBuf.ValueParameter + container: ProtoContainer, + callableProto: MessageLite, + kind: AnnotatedCallableKind, + parameterIndex: Int, + proto: ProtoBuf.ValueParameter ): List fun loadExtensionReceiverParameterAnnotations( - container: ProtoContainer, - proto: MessageLite, - kind: AnnotatedCallableKind + container: ProtoContainer, + proto: MessageLite, + kind: AnnotatedCallableKind ): List fun loadTypeAnnotations( - proto: ProtoBuf.Type, - nameResolver: NameResolver + proto: ProtoBuf.Type, + nameResolver: NameResolver ): List fun loadTypeParameterAnnotations( - proto: ProtoBuf.TypeParameter, - nameResolver: NameResolver + proto: ProtoBuf.TypeParameter, + nameResolver: NameResolver ): List fun loadPropertyConstant( - container: ProtoContainer, - proto: ProtoBuf.Property, - expectedType: KotlinType + container: ProtoContainer, + proto: ProtoBuf.Property, + expectedType: KotlinType ): C? } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoaderImpl.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoaderImpl.kt index d68b663a6e3..18eae62bc01 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoaderImpl.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationAndConstantLoaderImpl.kt @@ -29,9 +29,9 @@ import org.jetbrains.kotlin.serialization.SerializerExtensionProtocol import org.jetbrains.kotlin.types.KotlinType class AnnotationAndConstantLoaderImpl( - module: ModuleDescriptor, - notFoundClasses: NotFoundClasses, - private val protocol: SerializerExtensionProtocol + module: ModuleDescriptor, + notFoundClasses: NotFoundClasses, + private val protocol: SerializerExtensionProtocol ) : AnnotationAndConstantLoader, AnnotationWithTarget> { private val deserializer = AnnotationDeserializer(module, notFoundClasses) @@ -41,9 +41,9 @@ class AnnotationAndConstantLoaderImpl( } override fun loadCallableAnnotations( - container: ProtoContainer, - proto: MessageLite, - kind: AnnotatedCallableKind + container: ProtoContainer, + proto: MessageLite, + kind: AnnotatedCallableKind ): List { val annotations = when (proto) { is ProtoBuf.Constructor -> proto.getExtension(protocol.constructorAnnotation) @@ -51,32 +51,35 @@ class AnnotationAndConstantLoaderImpl( is ProtoBuf.Property -> proto.getExtension(protocol.propertyAnnotation) else -> error("Unknown message: $proto") }.orEmpty() - return annotations.map { proto -> AnnotationWithTarget(deserializer.deserializeAnnotation(proto, container.nameResolver), null) } + return annotations.map { annotationProto -> + AnnotationWithTarget(deserializer.deserializeAnnotation(annotationProto, container.nameResolver), null) + } } - override fun loadEnumEntryAnnotations( - container: ProtoContainer, - proto: ProtoBuf.EnumEntry - ): List { + override fun loadEnumEntryAnnotations(container: ProtoContainer, proto: ProtoBuf.EnumEntry): List { val annotations = proto.getExtension(protocol.enumEntryAnnotation).orEmpty() - return annotations.map { proto -> deserializer.deserializeAnnotation(proto, container.nameResolver) } + return annotations.map { annotationProto -> + deserializer.deserializeAnnotation(annotationProto, container.nameResolver) + } } override fun loadValueParameterAnnotations( - container: ProtoContainer, - callableProto: MessageLite, - kind: AnnotatedCallableKind, - parameterIndex: Int, - proto: ProtoBuf.ValueParameter + container: ProtoContainer, + callableProto: MessageLite, + kind: AnnotatedCallableKind, + parameterIndex: Int, + proto: ProtoBuf.ValueParameter ): List { val annotations = proto.getExtension(protocol.parameterAnnotation).orEmpty() - return annotations.map { proto -> deserializer.deserializeAnnotation(proto, container.nameResolver) } + return annotations.map { annotationProto -> + deserializer.deserializeAnnotation(annotationProto, container.nameResolver) + } } override fun loadExtensionReceiverParameterAnnotations( - container: ProtoContainer, - proto: MessageLite, - kind: AnnotatedCallableKind + container: ProtoContainer, + proto: MessageLite, + kind: AnnotatedCallableKind ): List = emptyList() override fun loadTypeAnnotations(proto: ProtoBuf.Type, nameResolver: NameResolver): List { @@ -87,11 +90,7 @@ class AnnotationAndConstantLoaderImpl( return proto.getExtension(protocol.typeParameterAnnotation).orEmpty().map { deserializer.deserializeAnnotation(it, nameResolver) } } - override fun loadPropertyConstant( - container: ProtoContainer, - proto: ProtoBuf.Property, - expectedType: KotlinType - ): ConstantValue<*>? { + override fun loadPropertyConstant(container: ProtoContainer, proto: ProtoBuf.Property, expectedType: KotlinType): ConstantValue<*>? { val value = proto.getExtensionOrNull(protocol.compileTimeValue) ?: return null return deserializer.resolveValue(expectedType, value, container.nameResolver) } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationDeserializer.kt index 51e989a698c..05bca7339aa 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/AnnotationDeserializer.kt @@ -55,19 +55,15 @@ class AnnotationDeserializer(private val module: ModuleDescriptor, private val n } private fun resolveArgument( - proto: Argument, - parameterByName: Map, - nameResolver: NameResolver + proto: Argument, + parameterByName: Map, + nameResolver: NameResolver ): Pair>? { val parameter = parameterByName[nameResolver.getName(proto.nameId)] ?: return null return Pair(nameResolver.getName(proto.nameId), resolveValue(parameter.type, proto.value, nameResolver)) } - fun resolveValue( - expectedType: KotlinType, - value: Value, - nameResolver: NameResolver - ): ConstantValue<*> { + fun resolveValue(expectedType: KotlinType, value: Value, nameResolver: NameResolver): ConstantValue<*> { val isUnsigned = Flags.IS_UNSIGNED.get(value.flags) val result: ConstantValue<*> = when (value.type) { @@ -96,25 +92,24 @@ class AnnotationDeserializer(private val module: ModuleDescriptor, private val n val arrayElements = value.arrayElementList val actualArrayType = - if (arrayElements.isNotEmpty()) { - val actualElementType = resolveArrayElementType(arrayElements.first(), nameResolver) - builtIns.getPrimitiveArrayKotlinTypeByPrimitiveKotlinType(actualElementType) ?: - builtIns.getArrayType(Variance.INVARIANT, actualElementType) - } - else { - // In the case of empty array, no element has the element type, so we fall back to the expected type, if any. - // This is not very accurate when annotation class has been changed without recompiling clients, - // but should not in fact matter because the value is empty anyway - if (expectedIsArray) expectedType else builtIns.getArrayType(Variance.INVARIANT, builtIns.anyType) - } + if (arrayElements.isNotEmpty()) { + val actualElementType = resolveArrayElementType(arrayElements.first(), nameResolver) + builtIns.getPrimitiveArrayKotlinTypeByPrimitiveKotlinType(actualElementType) + ?: builtIns.getArrayType(Variance.INVARIANT, actualElementType) + } else { + // In the case of empty array, no element has the element type, so we fall back to the expected type, if any. + // This is not very accurate when annotation class has been changed without recompiling clients, + // but should not in fact matter because the value is empty anyway + if (expectedIsArray) expectedType else builtIns.getArrayType(Variance.INVARIANT, builtIns.anyType) + } val expectedElementType = builtIns.getArrayElementType(if (expectedIsArray) expectedType else actualArrayType) ConstantValueFactory.createArrayValue( - arrayElements.map { - resolveValue(expectedElementType, it, nameResolver) - }, - actualArrayType + arrayElements.map { + resolveValue(expectedElementType, it, nameResolver) + }, + actualArrayType ) } else -> error("Unsupported annotation argument type: ${value.type} (expected $expectedType)") @@ -122,8 +117,7 @@ class AnnotationDeserializer(private val module: ModuleDescriptor, private val n return if (result.getType(module).isSubtypeOf(expectedType)) { result - } - else { + } else { // This means that an annotation class has been changed incompatibly without recompiling clients ErrorValue.create("Unexpected argument value") } @@ -142,24 +136,24 @@ class AnnotationDeserializer(private val module: ModuleDescriptor, private val n } private fun resolveArrayElementType(value: Value, nameResolver: NameResolver): SimpleType = - with(builtIns) { - when (value.type) { - Type.BYTE -> byteType - Type.CHAR -> charType - Type.SHORT -> shortType - Type.INT -> intType - Type.LONG -> longType - Type.FLOAT -> floatType - Type.DOUBLE -> doubleType - Type.BOOLEAN -> booleanType - Type.STRING -> stringType - Type.CLASS -> error("Arrays of class literals are not supported yet") // TODO: support arrays of class literals - Type.ENUM -> resolveClass(nameResolver.getClassId(value.classId)).defaultType - Type.ANNOTATION -> resolveClass(nameResolver.getClassId(value.annotation.id)).defaultType - Type.ARRAY -> error("Array of arrays is impossible") - else -> error("Unknown type: ${value.type}") - } + with(builtIns) { + when (value.type) { + Type.BYTE -> byteType + Type.CHAR -> charType + Type.SHORT -> shortType + Type.INT -> intType + Type.LONG -> longType + Type.FLOAT -> floatType + Type.DOUBLE -> doubleType + Type.BOOLEAN -> booleanType + Type.STRING -> stringType + Type.CLASS -> error("Arrays of class literals are not supported yet") // TODO: support arrays of class literals + Type.ENUM -> resolveClass(nameResolver.getClassId(value.classId)).defaultType + Type.ANNOTATION -> resolveClass(nameResolver.getClassId(value.annotation.id)).defaultType + Type.ARRAY -> error("Array of arrays is impossible") + else -> error("Unknown type: ${value.type}") } + } private fun resolveClass(classId: ClassId): ClassDescriptor { return module.findNonGenericClassAcrossDependencies(classId, notFoundClasses) diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ClassDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ClassDeserializer.kt index 867167b48e1..84984c59897 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ClassDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ClassDeserializer.kt @@ -25,7 +25,7 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ class ClassDeserializer(private val components: DeserializationComponents) { private val classes: (ClassKey) -> ClassDescriptor? = - components.storageManager.createMemoizedFunctionWithNullableValues { key -> createClass(key) } + components.storageManager.createMemoizedFunctionWithNullableValues { key -> createClass(key) } // Additional ClassData parameter is needed to avoid calling ClassDataFinder#findClassData() // if it is already computed at the call site @@ -40,8 +40,8 @@ class ClassDeserializer(private val components: DeserializationComponents) { if (classId in BLACK_LIST) return null val (nameResolver, classProto, sourceElement) = key.classData - ?: components.classDataFinder.findClassData(classId) - ?: return null + ?: components.classDataFinder.findClassData(classId) + ?: return null val outerClassId = classId.outerClassId val outerContext = if (outerClassId != null) { @@ -51,17 +51,16 @@ class ClassDeserializer(private val components: DeserializationComponents) { if (!outerClass.hasNestedClass(classId.shortClassName)) return null outerClass.c - } - else { + } else { val fragments = components.packageFragmentProvider.getPackageFragments(classId.packageFqName) val fragment = fragments.firstOrNull { it !is DeserializedPackageFragment || it.hasTopLevelClass(classId.shortClassName) } - ?: return null + ?: return null components.createContext( - fragment, nameResolver, - TypeTable(classProto.typeTable), - VersionRequirementTable.create(classProto.versionRequirementTable), - containerSource = null + fragment, nameResolver, + TypeTable(classProto.typeTable), + VersionRequirementTable.create(classProto.versionRequirementTable), + containerSource = null ) } @@ -83,7 +82,7 @@ class ClassDeserializer(private val components: DeserializationComponents) { * but the metadata is still serialized for kotlin-reflect 1.0 to work (see BuiltInsSerializer.kt). */ val BLACK_LIST = setOf( - ClassId.topLevel(KotlinBuiltIns.FQ_NAMES.cloneable.toSafe()) + ClassId.topLevel(KotlinBuiltIns.FQ_NAMES.cloneable.toSafe()) ) } } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ContractDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ContractDeserializer.kt index 638d48f5e6c..541daeed133 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ContractDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ContractDeserializer.kt @@ -22,22 +22,22 @@ import org.jetbrains.kotlin.metadata.deserialization.TypeTable interface ContractDeserializer { fun deserializeContractFromFunction( - proto: ProtoBuf.Function, - ownerFunction: FunctionDescriptor, - typeTable: TypeTable, - typeDeserializer: TypeDeserializer + proto: ProtoBuf.Function, + ownerFunction: FunctionDescriptor, + typeTable: TypeTable, + typeDeserializer: TypeDeserializer ): Pair, ContractProvider>? companion object { val DEFAULT = object : ContractDeserializer { override fun deserializeContractFromFunction( - proto: ProtoBuf.Function, - ownerFunction: FunctionDescriptor, - typeTable: TypeTable, - typeDeserializer: TypeDeserializer + proto: ProtoBuf.Function, + ownerFunction: FunctionDescriptor, + typeTable: TypeTable, + typeDeserializer: TypeDeserializer ): Pair, Nothing>? = null } } } -interface ContractProvider \ No newline at end of file +interface ContractProvider diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedPackageFragment.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedPackageFragment.kt index 1db06368394..571a4561760 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedPackageFragment.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/DeserializedPackageFragment.kt @@ -24,9 +24,9 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ import org.jetbrains.kotlin.storage.StorageManager abstract class DeserializedPackageFragment( - fqName: FqName, - protected val storageManager: StorageManager, - module: ModuleDescriptor + fqName: FqName, + protected val storageManager: StorageManager, + module: ModuleDescriptor ) : PackageFragmentDescriptorImpl(module, fqName) { abstract fun initialize(components: DeserializationComponents) diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/FlexibleTypeDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/FlexibleTypeDeserializer.kt index 669060f3423..32aa338204f 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/FlexibleTypeDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/FlexibleTypeDeserializer.kt @@ -24,7 +24,7 @@ interface FlexibleTypeDeserializer { fun create(proto: ProtoBuf.Type, flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType object ThrowException : FlexibleTypeDeserializer { - override fun create(proto: ProtoBuf.Type, flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType - = throw IllegalArgumentException("This method should not be used.") + override fun create(proto: ProtoBuf.Type, flexibleId: String, lowerBound: SimpleType, upperBound: SimpleType): KotlinType = + throw IllegalArgumentException("This method should not be used.") } } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/IncompatibleVersionErrorData.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/IncompatibleVersionErrorData.kt index 3d3ba1fb3ec..999ad2a6119 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/IncompatibleVersionErrorData.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/IncompatibleVersionErrorData.kt @@ -20,8 +20,8 @@ import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion import org.jetbrains.kotlin.name.ClassId data class IncompatibleVersionErrorData( - val actualVersion: T, - val expectedVersion: T, - val filePath: String, - val classId: ClassId + val actualVersion: T, + val expectedVersion: T, + val filePath: String, + val classId: ClassId ) diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt index c4205d1a0fa..d3d6913bc56 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MemberDeserializer.kt @@ -276,7 +276,7 @@ class MemberDeserializer(private val c: DeserializationContext) { c.containingDeclaration.asProtoContainer()?.let { c.components.annotationAndConstantLoader .loadExtensionReceiverParameterAnnotations(it, proto, receiverTargetedKind) - .map { AnnotationWithTarget(it, AnnotationUseSiteTarget.RECEIVER) } + .map { annotation -> AnnotationWithTarget(annotation, AnnotationUseSiteTarget.RECEIVER) } .toList() }.orEmpty() } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MetadataPackageFragmentProvider.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MetadataPackageFragmentProvider.kt index 0c64b1de98c..b4bd95c2e25 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MetadataPackageFragmentProvider.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/MetadataPackageFragmentProvider.kt @@ -36,36 +36,36 @@ import org.jetbrains.kotlin.storage.StorageManager import java.io.InputStream class MetadataPackageFragmentProvider( - storageManager: StorageManager, - finder: KotlinMetadataFinder, - moduleDescriptor: ModuleDescriptor, - notFoundClasses: NotFoundClasses, - private val metadataPartProvider: MetadataPartProvider + storageManager: StorageManager, + finder: KotlinMetadataFinder, + moduleDescriptor: ModuleDescriptor, + notFoundClasses: NotFoundClasses, + private val metadataPartProvider: MetadataPartProvider ) : AbstractDeserializedPackageFragmentProvider(storageManager, finder, moduleDescriptor) { init { components = DeserializationComponents( - storageManager, - moduleDescriptor, - DeserializationConfiguration.Default, // TODO - DeserializedClassDataFinder(this), - AnnotationAndConstantLoaderImpl(moduleDescriptor, notFoundClasses, BuiltInSerializerProtocol), - this, - LocalClassifierTypeSettings.Default, - ErrorReporter.DO_NOTHING, - LookupTracker.DO_NOTHING, - FlexibleTypeDeserializer.ThrowException, - emptyList(), - notFoundClasses, - ContractDeserializer.DEFAULT, - AdditionalClassPartsProvider.None, PlatformDependentDeclarationFilter.All, - BuiltInSerializerProtocol.extensionRegistry + storageManager, + moduleDescriptor, + DeserializationConfiguration.Default, // TODO + DeserializedClassDataFinder(this), + AnnotationAndConstantLoaderImpl(moduleDescriptor, notFoundClasses, BuiltInSerializerProtocol), + this, + LocalClassifierTypeSettings.Default, + ErrorReporter.DO_NOTHING, + LookupTracker.DO_NOTHING, + FlexibleTypeDeserializer.ThrowException, + emptyList(), + notFoundClasses, + ContractDeserializer.DEFAULT, + AdditionalClassPartsProvider.None, PlatformDependentDeclarationFilter.All, + BuiltInSerializerProtocol.extensionRegistry ) } override fun findPackage(fqName: FqName): DeserializedPackageFragment? = - if (finder.hasMetadataPackage(fqName)) - MetadataPackageFragment(fqName, storageManager, moduleDescriptor, metadataPartProvider, finder) - else null + if (finder.hasMetadataPackage(fqName)) + MetadataPackageFragment(fqName, storageManager, moduleDescriptor, metadataPartProvider, finder) + else null } class MetadataPackageFragment( @@ -104,15 +104,15 @@ class MetadataPackageFragment( val (proto, nameResolver) = readProto(stream) scopes.add(DeserializedPackageMemberScope( - this, proto.`package`, nameResolver, containerSource = null, components = components, classNames = { emptyList() } + this, proto.`package`, nameResolver, containerSource = null, components = components, classNames = { emptyList() } )) } // Also add the deserialized scope that can load all classes from this package scopes.add(object : DeserializedPackageMemberScope( - this, ProtoBuf.Package.getDefaultInstance(), - NameResolverImpl(ProtoBuf.StringTable.getDefaultInstance(), ProtoBuf.QualifiedNameTable.getDefaultInstance()), - containerSource = null, components = components, classNames = { emptyList() } + this, ProtoBuf.Package.getDefaultInstance(), + NameResolverImpl(ProtoBuf.StringTable.getDefaultInstance(), ProtoBuf.QualifiedNameTable.getDefaultInstance()), + containerSource = null, components = components, classNames = { emptyList() } ) { override fun hasClass(name: Name): Boolean = hasTopLevelClass(name) override fun definitelyDoesNotContainName(name: Name) = false @@ -135,9 +135,9 @@ class MetadataPackageFragment( if (!version.isCompatible()) { // TODO: report a proper diagnostic throw UnsupportedOperationException( - "Kotlin metadata definition format version is not supported: " + - "expected ${BuiltInsBinaryVersion.INSTANCE}, actual $version. " + - "Please update Kotlin" + "Kotlin metadata definition format version is not supported: " + + "expected ${BuiltInsBinaryVersion.INSTANCE}, actual $version. " + + "Please update Kotlin" ) } @@ -147,7 +147,7 @@ class MetadataPackageFragment( } companion object { - val DOT_METADATA_FILE_EXTENSION = ".kotlin_metadata" - val METADATA_FILE_EXTENSION = "kotlin_metadata" + const val METADATA_FILE_EXTENSION = "kotlin_metadata" + const val DOT_METADATA_FILE_EXTENSION = ".$METADATA_FILE_EXTENSION" } } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoBasedClassDataFinder.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoBasedClassDataFinder.kt index 76d36faf825..436857313b7 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoBasedClassDataFinder.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoBasedClassDataFinder.kt @@ -22,14 +22,14 @@ import org.jetbrains.kotlin.metadata.deserialization.NameResolver import org.jetbrains.kotlin.name.ClassId class ProtoBasedClassDataFinder( - proto: ProtoBuf.PackageFragment, - private val nameResolver: NameResolver, - private val classSource: (ClassId) -> SourceElement = { SourceElement.NO_SOURCE } + proto: ProtoBuf.PackageFragment, + private val nameResolver: NameResolver, + private val classSource: (ClassId) -> SourceElement = { SourceElement.NO_SOURCE } ) : ClassDataFinder { private val classIdToProto = - proto.class_List.associateBy { klass -> - nameResolver.getClassId(klass.fqName) - } + proto.class_List.associateBy { klass -> + nameResolver.getClassId(klass.fqName) + } internal val allClassIds: Collection get() = classIdToProto.keys diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoContainer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoContainer.kt index 7e926d09e4e..a5bf2504ee9 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoContainer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/ProtoContainer.kt @@ -25,16 +25,16 @@ import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName sealed class ProtoContainer( - val nameResolver: NameResolver, - val typeTable: TypeTable, - val source: SourceElement? + val nameResolver: NameResolver, + val typeTable: TypeTable, + val source: SourceElement? ) { class Class( - val classProto: ProtoBuf.Class, - nameResolver: NameResolver, - typeTable: TypeTable, - source: SourceElement?, - val outerClass: ProtoContainer.Class? + val classProto: ProtoBuf.Class, + nameResolver: NameResolver, + typeTable: TypeTable, + source: SourceElement?, + val outerClass: ProtoContainer.Class? ) : ProtoContainer(nameResolver, typeTable, source) { val classId: ClassId = nameResolver.getClassId(classProto.fqName) @@ -45,10 +45,10 @@ sealed class ProtoContainer( } class Package( - val fqName: FqName, - nameResolver: NameResolver, - typeTable: TypeTable, - source: SourceElement? + val fqName: FqName, + nameResolver: NameResolver, + typeTable: TypeTable, + source: SourceElement? ) : ProtoContainer(nameResolver, typeTable, source) { override fun debugFqName(): FqName = fqName } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt index 56bd4c9455d..5ae05161b28 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt @@ -86,8 +86,8 @@ class TypeDeserializer( fun ProtoBuf.Type.collectAllArguments(): List = argumentList + outerType(c.typeTable)?.collectAllArguments().orEmpty() - val arguments = proto.collectAllArguments().mapIndexed { index, proto -> - typeArgument(constructor.parameters.getOrNull(index), proto) + val arguments = proto.collectAllArguments().mapIndexed { index, argumentProto -> + typeArgument(constructor.parameters.getOrNull(index), argumentProto) }.toList() val simpleType = if (Flags.SUSPEND_TYPE.get(proto.flags)) { @@ -115,7 +115,7 @@ class TypeDeserializer( proto.hasClassName() -> (classDescriptors(proto.className) ?: notFoundClass(proto.className)).typeConstructor proto.hasTypeParameter() -> typeParameterTypeConstructor(proto.typeParameter) - ?: ErrorUtils.createErrorTypeConstructor("Unknown type parameter ${proto.typeParameter}") + ?: ErrorUtils.createErrorTypeConstructor("Unknown type parameter ${proto.typeParameter}") proto.hasTypeParameterName() -> { val container = c.containingDeclaration val name = c.nameResolver.getString(proto.typeParameterName) @@ -171,12 +171,10 @@ class TypeDeserializer( // kotlin.suspend is still built with LV=1.2, thus it references old Continuation // And otherwise, once stdlib is compiled with 1.3 one may want to stay at LV=1.2 if (c.containingDeclaration.safeAs()?.fqNameOrNull() == KOTLIN_SUSPEND_BUILT_IN_FUNCTION_FQ_NAME) { - transformRuntimeFunctionTypeToSuspendFunction(functionType, false)?.let { - if (!it.isSuspendFunctionType) { - transformRuntimeFunctionTypeToSuspendFunction(functionType, true)?.let { return it } - } else { - return it - } + transformRuntimeFunctionTypeToSuspendFunction(functionType, false)?.let { oldSuspend -> + if (oldSuspend.isSuspendFunctionType) return oldSuspend + + transformRuntimeFunctionTypeToSuspendFunction(functionType, true)?.let { newSuspend -> return newSuspend } } } @@ -186,7 +184,7 @@ class TypeDeserializer( } private fun typeParameterTypeConstructor(typeParameterId: Int): TypeConstructor? = - typeParameterDescriptors.get(typeParameterId)?.typeConstructor ?: parent?.typeParameterTypeConstructor(typeParameterId) + typeParameterDescriptors[typeParameterId]?.typeConstructor ?: parent?.typeParameterTypeConstructor(typeParameterId) private fun computeClassDescriptor(fqNameIndex: Int): ClassDescriptor? { val id = c.nameResolver.getClassId(fqNameIndex) diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/context.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/context.kt index b53b7d725e9..831ee0ecb49 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/context.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/context.kt @@ -34,63 +34,67 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ import org.jetbrains.kotlin.storage.StorageManager class DeserializationComponents( - val storageManager: StorageManager, - val moduleDescriptor: ModuleDescriptor, - val configuration: DeserializationConfiguration, - val classDataFinder: ClassDataFinder, - val annotationAndConstantLoader: AnnotationAndConstantLoader, AnnotationWithTarget>, - val packageFragmentProvider: PackageFragmentProvider, - val localClassifierTypeSettings: LocalClassifierTypeSettings, - val errorReporter: ErrorReporter, - val lookupTracker: LookupTracker, - val flexibleTypeDeserializer: FlexibleTypeDeserializer, - val fictitiousClassDescriptorFactories: Iterable, - val notFoundClasses: NotFoundClasses, - val contractDeserializer: ContractDeserializer, - val additionalClassPartsProvider: AdditionalClassPartsProvider = AdditionalClassPartsProvider.None, - val platformDependentDeclarationFilter: PlatformDependentDeclarationFilter = PlatformDependentDeclarationFilter.All, - val extensionRegistryLite: ExtensionRegistryLite + val storageManager: StorageManager, + val moduleDescriptor: ModuleDescriptor, + val configuration: DeserializationConfiguration, + val classDataFinder: ClassDataFinder, + val annotationAndConstantLoader: AnnotationAndConstantLoader, AnnotationWithTarget>, + val packageFragmentProvider: PackageFragmentProvider, + val localClassifierTypeSettings: LocalClassifierTypeSettings, + val errorReporter: ErrorReporter, + val lookupTracker: LookupTracker, + val flexibleTypeDeserializer: FlexibleTypeDeserializer, + val fictitiousClassDescriptorFactories: Iterable, + val notFoundClasses: NotFoundClasses, + val contractDeserializer: ContractDeserializer, + val additionalClassPartsProvider: AdditionalClassPartsProvider = AdditionalClassPartsProvider.None, + val platformDependentDeclarationFilter: PlatformDependentDeclarationFilter = PlatformDependentDeclarationFilter.All, + val extensionRegistryLite: ExtensionRegistryLite ) { val classDeserializer: ClassDeserializer = ClassDeserializer(this) fun deserializeClass(classId: ClassId): ClassDescriptor? = classDeserializer.deserializeClass(classId) fun createContext( - descriptor: PackageFragmentDescriptor, - nameResolver: NameResolver, - typeTable: TypeTable, - versionRequirementTable: VersionRequirementTable, - containerSource: DeserializedContainerSource? + descriptor: PackageFragmentDescriptor, + nameResolver: NameResolver, + typeTable: TypeTable, + versionRequirementTable: VersionRequirementTable, + containerSource: DeserializedContainerSource? ): DeserializationContext = - DeserializationContext(this, nameResolver, descriptor, typeTable, versionRequirementTable, containerSource, - parentTypeDeserializer = null, typeParameters = listOf()) + DeserializationContext( + this, nameResolver, descriptor, typeTable, versionRequirementTable, containerSource, + parentTypeDeserializer = null, typeParameters = listOf() + ) } class DeserializationContext( - val components: DeserializationComponents, - val nameResolver: NameResolver, - val containingDeclaration: DeclarationDescriptor, - val typeTable: TypeTable, - val versionRequirementTable: VersionRequirementTable, - val containerSource: DeserializedContainerSource?, - parentTypeDeserializer: TypeDeserializer?, - typeParameters: List + val components: DeserializationComponents, + val nameResolver: NameResolver, + val containingDeclaration: DeclarationDescriptor, + val typeTable: TypeTable, + val versionRequirementTable: VersionRequirementTable, + val containerSource: DeserializedContainerSource?, + parentTypeDeserializer: TypeDeserializer?, + typeParameters: List ) { - val typeDeserializer = TypeDeserializer(this, parentTypeDeserializer, typeParameters, - "Deserializer for ${containingDeclaration.name}") + val typeDeserializer: TypeDeserializer = TypeDeserializer( + this, parentTypeDeserializer, typeParameters, + "Deserializer for ${containingDeclaration.name}" + ) - val memberDeserializer = MemberDeserializer(this) + val memberDeserializer: MemberDeserializer = MemberDeserializer(this) val storageManager: StorageManager get() = components.storageManager fun childContext( - descriptor: DeclarationDescriptor, - typeParameterProtos: List, - nameResolver: NameResolver = this.nameResolver, - typeTable: TypeTable = this.typeTable - ) = DeserializationContext( - components, nameResolver, descriptor, typeTable, versionRequirementTable, this.containerSource, - parentTypeDeserializer = this.typeDeserializer, typeParameters = typeParameterProtos + descriptor: DeclarationDescriptor, + typeParameterProtos: List, + nameResolver: NameResolver = this.nameResolver, + typeTable: TypeTable = this.typeTable + ): DeserializationContext = DeserializationContext( + components, nameResolver, descriptor, typeTable, versionRequirementTable, this.containerSource, + parentTypeDeserializer = this.typeDeserializer, typeParameters = typeParameterProtos ) } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedAnnotations.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedAnnotations.kt index a68e2b4511e..469e11274c3 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedAnnotations.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedAnnotations.kt @@ -24,8 +24,8 @@ import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.getValue open class DeserializedAnnotations( - storageManager: StorageManager, - compute: () -> List + storageManager: StorageManager, + compute: () -> List ) : Annotations { private val annotations by storageManager.createLazyValue(compute) @@ -39,22 +39,22 @@ open class DeserializedAnnotations( } class NonEmptyDeserializedAnnotations( - storageManager: StorageManager, - compute: () -> List + storageManager: StorageManager, + compute: () -> List ) : DeserializedAnnotations(storageManager, compute) { override fun isEmpty(): Boolean = false } open class DeserializedAnnotationsWithPossibleTargets( - storageManager: StorageManager, - compute: () -> List + storageManager: StorageManager, + compute: () -> List ) : Annotations { private val annotations by storageManager.createLazyValue(compute) override fun isEmpty(): Boolean = annotations.isEmpty() override fun findAnnotation(fqName: FqName): AnnotationDescriptor? = - annotations.firstOrNull { (annotation, target) -> target == null && annotation.fqName == fqName }?.annotation + annotations.firstOrNull { (annotation, target) -> target == null && annotation.fqName == fqName }?.annotation override fun getUseSiteTargetedAnnotations(): List = annotations.filter { it.target != null } @@ -66,8 +66,8 @@ open class DeserializedAnnotationsWithPossibleTargets( } class NonEmptyDeserializedAnnotationsWithPossibleTargets( - storageManager: StorageManager, - compute: () -> List + storageManager: StorageManager, + compute: () -> List ) : DeserializedAnnotationsWithPossibleTargets(storageManager, compute) { override fun isEmpty(): Boolean = false } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedClassDescriptor.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedClassDescriptor.kt index cd8844cb7f4..8aa2789b9d3 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedClassDescriptor.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedClassDescriptor.kt @@ -30,13 +30,13 @@ import org.jetbrains.kotlin.types.TypeConstructor import java.util.* class DeserializedClassDescriptor( - outerContext: DeserializationContext, - val classProto: ProtoBuf.Class, - nameResolver: NameResolver, - private val sourceElement: SourceElement + outerContext: DeserializationContext, + val classProto: ProtoBuf.Class, + nameResolver: NameResolver, + private val sourceElement: SourceElement ) : AbstractClassDescriptor( - outerContext.storageManager, - nameResolver.getClassId(classProto.fqName).shortClassName + outerContext.storageManager, + nameResolver.getClassId(classProto.fqName).shortClassName ) { private val classId = nameResolver.getClassId(classProto.fqName) @@ -58,20 +58,19 @@ class DeserializedClassDescriptor( private val sealedSubclasses = c.storageManager.createLazyValue { computeSubclassesForSealedClass() } internal val thisAsProtoContainer: ProtoContainer.Class = ProtoContainer.Class( - classProto, c.nameResolver, c.typeTable, sourceElement, - (containingDeclaration as? DeserializedClassDescriptor)?.thisAsProtoContainer + classProto, c.nameResolver, c.typeTable, sourceElement, + (containingDeclaration as? DeserializedClassDescriptor)?.thisAsProtoContainer ) val versionRequirement: VersionRequirement? get() = VersionRequirement.create(classProto, c.nameResolver, c.versionRequirementTable) override val annotations = - if (!Flags.HAS_ANNOTATIONS.get(classProto.flags)) { - Annotations.EMPTY - } - else NonEmptyDeserializedAnnotations(c.storageManager) { - c.components.annotationAndConstantLoader.loadClassAnnotations(thisAsProtoContainer).toList() - } + if (!Flags.HAS_ANNOTATIONS.get(classProto.flags)) { + Annotations.EMPTY + } else NonEmptyDeserializedAnnotations(c.storageManager) { + c.components.annotationAndConstantLoader.loadClassAnnotations(thisAsProtoContainer).toList() + } override fun getContainingDeclaration(): DeclarationDescriptor = containingDeclaration @@ -116,13 +115,13 @@ class DeserializedClassDescriptor( override fun getUnsubstitutedPrimaryConstructor(): ClassConstructorDescriptor? = primaryConstructor() private fun computeConstructors(): Collection = - computeSecondaryConstructors() + listOfNotNull(unsubstitutedPrimaryConstructor) + - c.components.additionalClassPartsProvider.getConstructors(this) + computeSecondaryConstructors() + listOfNotNull(unsubstitutedPrimaryConstructor) + + c.components.additionalClassPartsProvider.getConstructors(this) private fun computeSecondaryConstructors(): List = - classProto.constructorList.filter { Flags.IS_SECONDARY.get(it.flags) }.map { - c.memberDeserializer.loadConstructor(it, false) - } + classProto.constructorList.filter { Flags.IS_SECONDARY.get(it.flags) }.map { + c.memberDeserializer.loadConstructor(it, false) + } override fun getConstructors() = constructors() @@ -136,7 +135,7 @@ class DeserializedClassDescriptor( override fun getCompanionObjectDescriptor(): ClassDescriptor? = companionObjectDescriptor() internal fun hasNestedClass(name: Name): Boolean = - name in memberScope.classNames + name in memberScope.classNames private fun computeSubclassesForSealedClass(): Collection { if (modality != Modality.SEALED) return emptyList() @@ -176,8 +175,8 @@ class DeserializedClassDescriptor( if (unresolved.isNotEmpty()) { c.components.errorReporter.reportIncompleteHierarchy( - this@DeserializedClassDescriptor, - unresolved.map { it.classId?.asSingleFqName()?.asString() ?: it.name.asString() } + this@DeserializedClassDescriptor, + unresolved.map { it.classId?.asSingleFqName()?.asString() ?: it.name.asString() } ) } @@ -198,8 +197,8 @@ class DeserializedClassDescriptor( } private inner class DeserializedClassMemberScope : DeserializedMemberScope( - c, classProto.functionList, classProto.propertyList, classProto.typeAliasList, - classProto.nestedClassNameList.map(c.nameResolver::getName).let { { it } } // workaround KT-13454 + c, classProto.functionList, classProto.propertyList, classProto.typeAliasList, + classProto.nestedClassNameList.map(c.nameResolver::getName).let { { it } } // workaround KT-13454 ) { private val classDescriptor: DeserializedClassDescriptor get() = this@DeserializedClassDescriptor @@ -208,7 +207,7 @@ class DeserializedClassDescriptor( } override fun getContributedDescriptors( - kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean + kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean ): Collection = allDescriptors() override fun getContributedFunctions(name: Name, location: LookupLocation): Collection { @@ -243,20 +242,32 @@ class DeserializedClassDescriptor( generateFakeOverrides(name, fromSupertypes, descriptors) } - private fun generateFakeOverrides(name: Name, fromSupertypes: Collection, result: MutableCollection) { + private fun generateFakeOverrides( + name: Name, + fromSupertypes: Collection, + result: MutableCollection + ) { val fromCurrent = ArrayList(result) - OverridingUtil.generateOverridesInFunctionGroup(name, fromSupertypes, fromCurrent, classDescriptor, object : NonReportingOverrideStrategy() { - override fun addFakeOverride(fakeOverride: CallableMemberDescriptor) { - // TODO: report "cannot infer visibility" - OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, null) - @Suppress("UNCHECKED_CAST") - result.add(fakeOverride as D) - } + OverridingUtil.generateOverridesInFunctionGroup( + name, + fromSupertypes, + fromCurrent, + classDescriptor, + object : NonReportingOverrideStrategy() { + override fun addFakeOverride(fakeOverride: CallableMemberDescriptor) { + // TODO: report "cannot infer visibility" + OverridingUtil.resolveUnknownVisibilityForMember(fakeOverride, null) + @Suppress("UNCHECKED_CAST") + result.add(fakeOverride as D) + } - override fun conflict(fromSuper: CallableMemberDescriptor, fromCurrent: CallableMemberDescriptor) { - // TODO report conflicts - } - }) + override fun conflict( + fromSuper: CallableMemberDescriptor, + fromCurrent: CallableMemberDescriptor + ) { + // TODO report conflicts + } + }) } override fun getNonDeclaredFunctionNames(): Set { @@ -291,16 +302,15 @@ class DeserializedClassDescriptor( private inner class EnumEntryClassDescriptors { private val enumEntryProtos = classProto.enumEntryList.associateBy { c.nameResolver.getName(it.name) } - private val enumEntryByName = c.storageManager.createMemoizedFunctionWithNullableValues { - name -> + private val enumEntryByName = c.storageManager.createMemoizedFunctionWithNullableValues { name -> enumEntryProtos[name]?.let { proto -> EnumEntrySyntheticClassDescriptor.create( - c.storageManager, this@DeserializedClassDescriptor, name, enumMemberNames, - DeserializedAnnotations(c.storageManager) { - c.components.annotationAndConstantLoader.loadEnumEntryAnnotations(thisAsProtoContainer, proto).toList() - }, - SourceElement.NO_SOURCE + c.storageManager, this@DeserializedClassDescriptor, name, enumMemberNames, + DeserializedAnnotations(c.storageManager) { + c.components.annotationAndConstantLoader.loadEnumEntryAnnotations(thisAsProtoContainer, proto).toList() + }, + SourceElement.NO_SOURCE ) } } @@ -323,10 +333,10 @@ class DeserializedClassDescriptor( } return classProto.functionList.mapTo(result) { c.nameResolver.getName(it.name) } + - classProto.propertyList.mapTo(result) { c.nameResolver.getName(it.name) } + classProto.propertyList.mapTo(result) { c.nameResolver.getName(it.name) } } fun all(): Collection = - enumEntryProtos.keys.mapNotNull { name -> findEnumEntry(name) } + enumEntryProtos.keys.mapNotNull { name -> findEnumEntry(name) } } } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberDescriptor.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberDescriptor.kt index b604e00c1da..85ff2c7c44b 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberDescriptor.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberDescriptor.kt @@ -58,33 +58,34 @@ interface DeserializedContainerSource : SourceElement { interface DeserializedCallableMemberDescriptor : DeserializedMemberDescriptor, CallableMemberDescriptor class DeserializedSimpleFunctionDescriptor( - containingDeclaration: DeclarationDescriptor, - original: SimpleFunctionDescriptor?, - annotations: Annotations, - name: Name, - kind: CallableMemberDescriptor.Kind, - override val proto: ProtoBuf.Function, - override val nameResolver: NameResolver, - override val typeTable: TypeTable, - override val versionRequirementTable: VersionRequirementTable, - override val containerSource: DeserializedContainerSource?, - source: SourceElement? = null + containingDeclaration: DeclarationDescriptor, + original: SimpleFunctionDescriptor?, + annotations: Annotations, + name: Name, + kind: CallableMemberDescriptor.Kind, + override val proto: ProtoBuf.Function, + override val nameResolver: NameResolver, + override val typeTable: TypeTable, + override val versionRequirementTable: VersionRequirementTable, + override val containerSource: DeserializedContainerSource?, + source: SourceElement? = null ) : DeserializedCallableMemberDescriptor, SimpleFunctionDescriptorImpl( - containingDeclaration, original, annotations, name, kind, - source ?: SourceElement.NO_SOURCE) { + containingDeclaration, original, annotations, name, kind, + source ?: SourceElement.NO_SOURCE + ) { override fun createSubstitutedCopy( - newOwner: DeclarationDescriptor, - original: FunctionDescriptor?, - kind: CallableMemberDescriptor.Kind, - newName: Name?, - annotations: Annotations, - source: SourceElement + newOwner: DeclarationDescriptor, + original: FunctionDescriptor?, + kind: CallableMemberDescriptor.Kind, + newName: Name?, + annotations: Annotations, + source: SourceElement ): FunctionDescriptorImpl { return DeserializedSimpleFunctionDescriptor( - newOwner, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind, - proto, nameResolver, typeTable, versionRequirementTable, containerSource, source + newOwner, original as SimpleFunctionDescriptor?, annotations, newName ?: name, kind, + proto, nameResolver, typeTable, versionRequirementTable, containerSource, source ) } } @@ -109,20 +110,20 @@ class DeserializedPropertyDescriptor( override val versionRequirementTable: VersionRequirementTable, override val containerSource: DeserializedContainerSource? ) : DeserializedCallableMemberDescriptor, PropertyDescriptorImpl( - containingDeclaration, original, annotations, modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, - isLateInit, isConst, isExpect, false, isExternal, isDelegated + containingDeclaration, original, annotations, modality, visibility, isVar, name, kind, SourceElement.NO_SOURCE, + isLateInit, isConst, isExpect, false, isExternal, isDelegated ) { override fun createSubstitutedCopy( - newOwner: DeclarationDescriptor, - newModality: Modality, - newVisibility: Visibility, - original: PropertyDescriptor?, - kind: CallableMemberDescriptor.Kind, - newName: Name + newOwner: DeclarationDescriptor, + newModality: Modality, + newVisibility: Visibility, + original: PropertyDescriptor?, + kind: CallableMemberDescriptor.Kind, + newName: Name ): PropertyDescriptorImpl { return DeserializedPropertyDescriptor( - newOwner, original, annotations, newModality, newVisibility, isVar, newName, kind, isLateInit, isConst, isExternal, - @Suppress("DEPRECATION") isDelegated, isExpect, proto, nameResolver, typeTable, versionRequirementTable, containerSource + newOwner, original, annotations, newModality, newVisibility, isVar, newName, kind, isLateInit, isConst, isExternal, + @Suppress("DEPRECATION") isDelegated, isExpect, proto, nameResolver, typeTable, versionRequirementTable, containerSource ) } @@ -130,31 +131,31 @@ class DeserializedPropertyDescriptor( } class DeserializedClassConstructorDescriptor( - containingDeclaration: ClassDescriptor, - original: ConstructorDescriptor?, - annotations: Annotations, - isPrimary: Boolean, - kind: CallableMemberDescriptor.Kind, - override val proto: ProtoBuf.Constructor, - override val nameResolver: NameResolver, - override val typeTable: TypeTable, - override val versionRequirementTable: VersionRequirementTable, - override val containerSource: DeserializedContainerSource?, - source: SourceElement? = null + containingDeclaration: ClassDescriptor, + original: ConstructorDescriptor?, + annotations: Annotations, + isPrimary: Boolean, + kind: CallableMemberDescriptor.Kind, + override val proto: ProtoBuf.Constructor, + override val nameResolver: NameResolver, + override val typeTable: TypeTable, + override val versionRequirementTable: VersionRequirementTable, + override val containerSource: DeserializedContainerSource?, + source: SourceElement? = null ) : DeserializedCallableMemberDescriptor, - ClassConstructorDescriptorImpl(containingDeclaration, original, annotations, isPrimary, kind, source ?: SourceElement.NO_SOURCE) { + ClassConstructorDescriptorImpl(containingDeclaration, original, annotations, isPrimary, kind, source ?: SourceElement.NO_SOURCE) { override fun createSubstitutedCopy( - newOwner: DeclarationDescriptor, - original: FunctionDescriptor?, - kind: CallableMemberDescriptor.Kind, - newName: Name?, - annotations: Annotations, - source: SourceElement + newOwner: DeclarationDescriptor, + original: FunctionDescriptor?, + kind: CallableMemberDescriptor.Kind, + newName: Name?, + annotations: Annotations, + source: SourceElement ): DeserializedClassConstructorDescriptor { return DeserializedClassConstructorDescriptor( - newOwner as ClassDescriptor, original as ConstructorDescriptor?, annotations, isPrimary, kind, - proto, nameResolver, typeTable, versionRequirementTable, containerSource, source + newOwner as ClassDescriptor, original as ConstructorDescriptor?, annotations, isPrimary, kind, + proto, nameResolver, typeTable, versionRequirementTable, containerSource, source ) } @@ -164,33 +165,33 @@ class DeserializedClassConstructorDescriptor( override fun isTailrec(): Boolean = false - override fun isSuspend(): Boolean = false + override fun isSuspend(): Boolean = false } class DeserializedTypeAliasDescriptor( - override val storageManager: StorageManager, - containingDeclaration: DeclarationDescriptor, - annotations: Annotations, - name: Name, - visibility: Visibility, - override val proto: ProtoBuf.TypeAlias, - override val nameResolver: NameResolver, - override val typeTable: TypeTable, - override val versionRequirementTable: VersionRequirementTable, - override val containerSource: DeserializedContainerSource? + override val storageManager: StorageManager, + containingDeclaration: DeclarationDescriptor, + annotations: Annotations, + name: Name, + visibility: Visibility, + override val proto: ProtoBuf.TypeAlias, + override val nameResolver: NameResolver, + override val typeTable: TypeTable, + override val versionRequirementTable: VersionRequirementTable, + override val containerSource: DeserializedContainerSource? ) : AbstractTypeAliasDescriptor(containingDeclaration, annotations, name, SourceElement.NO_SOURCE, visibility), - DeserializedMemberDescriptor { + DeserializedMemberDescriptor { override lateinit var constructors: Collection private set override lateinit var underlyingType: SimpleType private set override lateinit var expandedType: SimpleType private set private lateinit var typeConstructorParameters: List - private lateinit var defaultTypeImpl: SimpleType private set + private lateinit var defaultTypeImpl: SimpleType fun initialize( - declaredTypeParameters: List, - underlyingType: SimpleType, - expandedType: SimpleType + declaredTypeParameters: List, + underlyingType: SimpleType, + expandedType: SimpleType ) { initialize(declaredTypeParameters) this.underlyingType = underlyingType @@ -203,31 +204,22 @@ class DeserializedTypeAliasDescriptor( override val classDescriptor: ClassDescriptor? get() = if (expandedType.isError) null else expandedType.constructor.declarationDescriptor as? ClassDescriptor - override fun getDefaultType(): SimpleType = - defaultTypeImpl + override fun getDefaultType(): SimpleType = defaultTypeImpl override fun substitute(substitutor: TypeSubstitutor): TypeAliasDescriptor { if (substitutor.isEmpty) return this val substituted = DeserializedTypeAliasDescriptor( - storageManager, - containingDeclaration, - annotations, - name, - visibility, - proto, - nameResolver, - typeTable, - versionRequirementTable, - containerSource + storageManager, containingDeclaration, annotations, name, visibility, + proto, nameResolver, typeTable, versionRequirementTable, containerSource + ) + substituted.initialize( + declaredTypeParameters, + substitutor.safeSubstitute(underlyingType, Variance.INVARIANT).asSimpleType(), + substitutor.safeSubstitute(expandedType, Variance.INVARIANT).asSimpleType() ) - substituted.initialize(declaredTypeParameters, - substitutor.safeSubstitute(underlyingType, Variance.INVARIANT).asSimpleType(), - substitutor.safeSubstitute(expandedType, Variance.INVARIANT).asSimpleType()) return substituted } - override fun getTypeConstructorTypeParameters(): List = - typeConstructorParameters - + override fun getTypeConstructorTypeParameters(): List = typeConstructorParameters } diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberScope.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberScope.kt index 58581d39c34..b72a69dbbb4 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberScope.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedMemberScope.kt @@ -38,11 +38,11 @@ import java.io.ByteArrayOutputStream import java.util.* abstract class DeserializedMemberScope protected constructor( - protected val c: DeserializationContext, - functionList: Collection, - propertyList: Collection, - typeAliasList: Collection, - classNames: () -> Collection + protected val c: DeserializationContext, + functionList: Collection, + propertyList: Collection, + typeAliasList: Collection, + classNames: () -> Collection ) : MemberScopeImpl() { private val functionProtosBytes = functionList.groupByName { it.name }.packToByteArray() @@ -63,11 +63,11 @@ abstract class DeserializedMemberScope protected constructor( } private val functions = - c.storageManager.createMemoizedFunction> { computeFunctions(it) } + c.storageManager.createMemoizedFunction> { computeFunctions(it) } private val properties = - c.storageManager.createMemoizedFunction> { computeProperties(it) } + c.storageManager.createMemoizedFunction> { computeProperties(it) } private val typeAliasByName = - c.storageManager.createMemoizedFunctionWithNullableValues { createTypeAlias(it) } + c.storageManager.createMemoizedFunctionWithNullableValues { createTypeAlias(it) } private val functionNamesLazy by c.storageManager.createLazyValue { functionProtosBytes.keys + getNonDeclaredFunctionNames() @@ -90,7 +90,7 @@ abstract class DeserializedMemberScope protected constructor( } private inline fun Collection.groupByName( - getNameIndex: (M) -> Int + getNameIndex: (M) -> Int ) = groupBy { c.nameResolver.getName(getNameIndex(it)) } private fun computeFunctions(name: Name) = @@ -166,9 +166,9 @@ abstract class DeserializedMemberScope protected constructor( } protected fun computeDescriptors( - kindFilter: DescriptorKindFilter, - nameFilter: (Name) -> Boolean, - location: LookupLocation + kindFilter: DescriptorKindFilter, + nameFilter: (Name) -> Boolean, + location: LookupLocation ): Collection { //NOTE: descriptors should be in the same order they were serialized in // see MemberComparator @@ -200,33 +200,33 @@ abstract class DeserializedMemberScope protected constructor( } private fun addFunctionsAndProperties( - result: MutableCollection, - kindFilter: DescriptorKindFilter, - nameFilter: (Name) -> Boolean, - location: LookupLocation + result: MutableCollection, + kindFilter: DescriptorKindFilter, + nameFilter: (Name) -> Boolean, + location: LookupLocation ) { if (kindFilter.acceptsKinds(DescriptorKindFilter.VARIABLES_MASK)) { addMembers( - getVariableNames(), - nameFilter, - result + getVariableNames(), + nameFilter, + result ) { getContributedVariables(it, location) } } if (kindFilter.acceptsKinds(DescriptorKindFilter.FUNCTIONS_MASK)) { addMembers( - getFunctionNames(), - nameFilter, - result + getFunctionNames(), + nameFilter, + result ) { getContributedFunctions(it, location) } } } private inline fun addMembers( - names: Collection, - nameFilter: (Name) -> Boolean, - result: MutableCollection, - descriptorsByName: (Name) -> Collection + names: Collection, + nameFilter: (Name) -> Boolean, + result: MutableCollection, + descriptorsByName: (Name) -> Collection ) { val subResult = ArrayList() for (name in names) { @@ -240,17 +240,17 @@ abstract class DeserializedMemberScope protected constructor( } override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? = - when { - hasClass(name) -> deserializeClass(name) - name in typeAliasNames -> typeAliasByName(name) - else -> null - } + when { + hasClass(name) -> deserializeClass(name) + name in typeAliasNames -> typeAliasByName(name) + else -> null + } private fun deserializeClass(name: Name): ClassDescriptor? = - c.components.deserializeClass(createClassId(name)) + c.components.deserializeClass(createClassId(name)) protected open fun hasClass(name: Name): Boolean = - name in classNames + name in classNames protected abstract fun createClassId(name: Name): ClassId diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedPackageMemberScope.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedPackageMemberScope.kt index 88fc5ffa73e..b09e3b21c1d 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedPackageMemberScope.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedPackageMemberScope.kt @@ -32,29 +32,30 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.serialization.deserialization.DeserializationComponents open class DeserializedPackageMemberScope( - private val packageDescriptor: PackageFragmentDescriptor, - proto: ProtoBuf.Package, - nameResolver: NameResolver, - containerSource: DeserializedContainerSource?, - components: DeserializationComponents, - classNames: () -> Collection + private val packageDescriptor: PackageFragmentDescriptor, + proto: ProtoBuf.Package, + nameResolver: NameResolver, + containerSource: DeserializedContainerSource?, + components: DeserializationComponents, + classNames: () -> Collection ) : DeserializedMemberScope( - components.createContext(packageDescriptor, nameResolver, TypeTable(proto.typeTable), - VersionRequirementTable.create(proto.versionRequirementTable), containerSource), - proto.functionList, proto.propertyList, proto.typeAliasList, classNames + components.createContext( + packageDescriptor, nameResolver, TypeTable(proto.typeTable), + VersionRequirementTable.create(proto.versionRequirementTable), containerSource + ), + proto.functionList, proto.propertyList, proto.typeAliasList, classNames ) { private val packageFqName = packageDescriptor.fqName - override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) - = computeDescriptors(kindFilter, nameFilter, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS) + - c.components.fictitiousClassDescriptorFactories.flatMap { it.getAllContributedClassesIfPossible(packageFqName) } + override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) = + computeDescriptors(kindFilter, nameFilter, NoLookupLocation.WHEN_GET_ALL_DESCRIPTORS) + + c.components.fictitiousClassDescriptorFactories.flatMap { it.getAllContributedClassesIfPossible(packageFqName) } override fun hasClass(name: Name) = - super.hasClass(name) || c.components.fictitiousClassDescriptorFactories.any { it.shouldCreateClass(packageFqName, name) } + super.hasClass(name) || c.components.fictitiousClassDescriptorFactories.any { it.shouldCreateClass(packageFqName, name) } override fun createClassId(name: Name) = ClassId(packageFqName, name) - override fun getContributedClassifier(name: Name, location: LookupLocation): ClassifierDescriptor? { recordLookup(name, location) return super.getContributedClassifier(name, location) diff --git a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedTypeParameterDescriptor.kt b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedTypeParameterDescriptor.kt index 4c457dc2cd3..3af4b64ab1a 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedTypeParameterDescriptor.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/descriptors/DeserializedTypeParameterDescriptor.kt @@ -29,9 +29,9 @@ import org.jetbrains.kotlin.serialization.deserialization.getName import org.jetbrains.kotlin.types.KotlinType class DeserializedTypeParameterDescriptor( - private val c: DeserializationContext, - private val proto: ProtoBuf.TypeParameter, - index: Int + private val c: DeserializationContext, + private val proto: ProtoBuf.TypeParameter, + index: Int ) : AbstractLazyTypeParameterDescriptor( c.storageManager, c.containingDeclaration, c.nameResolver.getName(proto.name), ProtoEnumFlags.variance(proto.variance), proto.reified, index, SourceElement.NO_SOURCE, SupertypeLoopChecker.EMPTY @@ -51,5 +51,6 @@ class DeserializedTypeParameterDescriptor( } override fun reportSupertypeLoopError(type: KotlinType) = throw IllegalStateException( - "There should be no cycles for deserialized type parameters, but found for: $this") + "There should be no cycles for deserialized type parameters, but found for: $this" + ) }