From 9deb9473d2402c02ce5578080d9ed51d1f3c1e34 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Thu, 21 Jun 2018 11:09:07 +0300 Subject: [PATCH] Minor. Reformat TypeDeserializer.kt --- .../deserialization/TypeDeserializer.kt | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) 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 643d0340c97..8ca59ceb346 100644 --- a/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt +++ b/core/deserialization/src/org/jetbrains/kotlin/serialization/deserialization/TypeDeserializer.kt @@ -19,24 +19,24 @@ import org.jetbrains.kotlin.types.* import java.util.* class TypeDeserializer( - private val c: DeserializationContext, - private val parent: TypeDeserializer?, - typeParameterProtos: List, - private val debugName: String + private val c: DeserializationContext, + private val parent: TypeDeserializer?, + typeParameterProtos: List, + private val debugName: String ) { - private val classDescriptors: (Int) -> ClassDescriptor? = c.storageManager.createMemoizedFunctionWithNullableValues { - fqNameIndex -> computeClassDescriptor(fqNameIndex) + private val classDescriptors: (Int) -> ClassDescriptor? = c.storageManager.createMemoizedFunctionWithNullableValues { fqNameIndex -> + computeClassDescriptor(fqNameIndex) } - private val typeAliasDescriptors: (Int) -> ClassifierDescriptor? = c.storageManager.createMemoizedFunctionWithNullableValues { - fqNameIndex -> computeTypeAliasDescriptor(fqNameIndex) - } + private val typeAliasDescriptors: (Int) -> ClassifierDescriptor? = + c.storageManager.createMemoizedFunctionWithNullableValues { fqNameIndex -> + computeTypeAliasDescriptor(fqNameIndex) + } private val typeParameterDescriptors = if (typeParameterProtos.isEmpty()) { mapOf() - } - else { + } else { val result = LinkedHashMap() for ((index, proto) in typeParameterProtos.withIndex()) { result[proto.id] = DeserializedTypeParameterDescriptor(c, proto, index) @@ -45,7 +45,7 @@ class TypeDeserializer( } val ownTypeParameters: List - get() = typeParameterDescriptors.values.toList() + 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 { @@ -75,13 +75,13 @@ class TypeDeserializer( val annotations = DeserializedAnnotationsWithPossibleTargets(c.storageManager) { c.components.annotationAndConstantLoader.loadTypeAnnotations(proto, c.nameResolver) - .map { AnnotationWithTarget(it, null) } - .plus(additionalAnnotations.getAllAnnotations()) - .toList() + .map { AnnotationWithTarget(it, null) } + .plus(additionalAnnotations.getAllAnnotations()) + .toList() } fun ProtoBuf.Type.collectAllArguments(): List = - argumentList + outerType(c.typeTable)?.collectAllArguments().orEmpty() + argumentList + outerType(c.typeTable)?.collectAllArguments().orEmpty() val arguments = proto.collectAllArguments().mapIndexed { index, proto -> typeArgument(constructor.parameters.getOrNull(index), proto) @@ -89,8 +89,7 @@ class TypeDeserializer( val simpleType = if (Flags.SUSPEND_TYPE.get(proto.flags)) { createSuspendFunctionType(annotations, constructor, arguments, proto.nullable, c.components.configuration.releaseCoroutines) - } - else { + } else { KotlinTypeFactory.simpleType(annotations, constructor, arguments, proto.nullable) } @@ -113,7 +112,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) @@ -142,20 +141,26 @@ class TypeDeserializer( 1 -> { val arity = arguments.size - 1 if (arity >= 0) { - KotlinTypeFactory.simpleType(annotations, functionTypeConstructor.builtIns.getSuspendFunction(arity).typeConstructor, arguments, nullable) - } - else { + KotlinTypeFactory.simpleType( + annotations, + functionTypeConstructor.builtIns.getSuspendFunction(arity).typeConstructor, + arguments, + nullable + ) + } else { null } } else -> null } - return result ?: ErrorUtils.createErrorTypeWithArguments("Bad suspend function in metadata with constructor: $functionTypeConstructor", arguments) + return result ?: ErrorUtils.createErrorTypeWithArguments( + "Bad suspend function in metadata with constructor: $functionTypeConstructor", + arguments + ) } private fun typeParameterTypeConstructor(typeParameterId: Int): TypeConstructor? = - typeParameterDescriptors.get(typeParameterId)?.typeConstructor ?: - parent?.typeParameterTypeConstructor(typeParameterId) + typeParameterDescriptors.get(typeParameterId)?.typeConstructor ?: parent?.typeParameterTypeConstructor(typeParameterId) private fun computeClassDescriptor(fqNameIndex: Int): ClassDescriptor? { val id = c.nameResolver.getClassId(fqNameIndex) @@ -178,8 +183,7 @@ class TypeDeserializer( return if (id.isLocal) { // TODO: support deserialization of local type aliases (see KT-13692) return null - } - else { + } else { c.components.moduleDescriptor.findTypeAliasAcrossModuleDependencies(id) } } @@ -193,8 +197,7 @@ class TypeDeserializer( } val projection = ProtoEnumFlags.variance(typeArgumentProto.projection) - val type = typeArgumentProto.type(c.typeTable) ?: - return TypeProjectionImpl(ErrorUtils.createErrorType("No type recorded")) + val type = typeArgumentProto.type(c.typeTable) ?: return TypeProjectionImpl(ErrorUtils.createErrorType("No type recorded")) return TypeProjectionImpl(projection, type(type)) }