From 53432eaf994ac9140057795a7434d5132e93a6af Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Mon, 21 Jan 2019 12:06:23 +0300 Subject: [PATCH] Minor: reformat `CapturedTypeApproximation.kt` according to code style --- .../kotlin/types/CapturedTypeApproximation.kt | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/CapturedTypeApproximation.kt b/core/descriptors/src/org/jetbrains/kotlin/types/CapturedTypeApproximation.kt index facfa252fd6..e5517443612 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/CapturedTypeApproximation.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/CapturedTypeApproximation.kt @@ -29,14 +29,14 @@ import org.jetbrains.kotlin.types.typeUtil.builtIns import java.util.* data class ApproximationBounds( - val lower: T, - val upper: T + val lower: T, + val upper: T ) private class TypeArgument( - val typeParameter: TypeParameterDescriptor, - val inProjection: KotlinType, - val outProjection: KotlinType + val typeParameter: TypeParameterDescriptor, + val inProjection: KotlinType, + val outProjection: KotlinType ) { val isConsistent: Boolean get() = KotlinTypeChecker.DEFAULT.isSubtypeOf(inProjection, outProjection) @@ -48,8 +48,10 @@ private fun TypeArgument.toTypeProjection(): TypeProjection { classifierNamePolicy = ClassifierNamePolicy.FULLY_QUALIFIED } "Only consistent enhanced type projection can be converted to type projection, but " + - "[${descriptorRenderer.render(typeParameter)}: <${descriptorRenderer.renderType(inProjection)}, ${descriptorRenderer.renderType(outProjection)}>]" + - " was found" + "[${descriptorRenderer.render(typeParameter)}: <${descriptorRenderer.renderType(inProjection)}, ${descriptorRenderer.renderType( + outProjection + )}>]" + + " was found" } fun removeProjectionIfRedundant(variance: Variance) = if (variance == typeParameter.variance) Variance.INVARIANT else variance return when { @@ -62,11 +64,11 @@ private fun TypeArgument.toTypeProjection(): TypeProjection { } private fun TypeProjection.toTypeArgument(typeParameter: TypeParameterDescriptor) = - when (TypeSubstitutor.combine(typeParameter.variance, this)) { - Variance.INVARIANT -> TypeArgument(typeParameter, type, type) - Variance.IN_VARIANCE -> TypeArgument(typeParameter, type, typeParameter.builtIns.nullableAnyType) - Variance.OUT_VARIANCE -> TypeArgument(typeParameter, typeParameter.builtIns.nothingType, type) - } + when (TypeSubstitutor.combine(typeParameter.variance, this)) { + Variance.INVARIANT -> TypeArgument(typeParameter, type, type) + Variance.IN_VARIANCE -> TypeArgument(typeParameter, type, typeParameter.builtIns.nullableAnyType) + Variance.OUT_VARIANCE -> TypeArgument(typeParameter, typeParameter.builtIns.nothingType, type) + } fun approximateCapturedTypesIfNecessary(typeProjection: TypeProjection?, approximateContravariant: Boolean): TypeProjection? { if (typeProjection == null) return null @@ -112,14 +114,15 @@ fun approximateCapturedTypes(type: KotlinType): ApproximationBounds val boundsForFlexibleUpper = approximateCapturedTypes(type.upperIfFlexible()) return ApproximationBounds( - KotlinTypeFactory.flexibleType( - boundsForFlexibleLower.lower.lowerIfFlexible(), - boundsForFlexibleUpper.lower.upperIfFlexible() - ).inheritEnhancement(type), - KotlinTypeFactory.flexibleType( - boundsForFlexibleLower.upper.lowerIfFlexible(), - boundsForFlexibleUpper.upper.upperIfFlexible() - ).inheritEnhancement(type)) + KotlinTypeFactory.flexibleType( + boundsForFlexibleLower.lower.lowerIfFlexible(), + boundsForFlexibleUpper.lower.upperIfFlexible() + ).inheritEnhancement(type), + KotlinTypeFactory.flexibleType( + boundsForFlexibleLower.upper.lowerIfFlexible(), + boundsForFlexibleUpper.upper.upperIfFlexible() + ).inheritEnhancement(type) + ) } val typeConstructor = type.constructor @@ -146,8 +149,7 @@ fun approximateCapturedTypes(type: KotlinType): ApproximationBounds if (typeProjection.isStarProjection) { lowerBoundArguments.add(typeArgument) upperBoundArguments.add(typeArgument) - } - else { + } else { val (lower, upper) = approximateProjection(typeArgument) lowerBoundArguments.add(lower) upperBoundArguments.add(upper) @@ -155,8 +157,9 @@ fun approximateCapturedTypes(type: KotlinType): ApproximationBounds } val lowerBoundIsTrivial = lowerBoundArguments.any { !it.isConsistent } return ApproximationBounds( - if (lowerBoundIsTrivial) type.builtIns.nothingType else type.replaceTypeArguments(lowerBoundArguments), - type.replaceTypeArguments(upperBoundArguments)) + if (lowerBoundIsTrivial) type.builtIns.nothingType else type.replaceTypeArguments(lowerBoundArguments), + type.replaceTypeArguments(upperBoundArguments) + ) } private fun KotlinType.replaceTypeArguments(newTypeArguments: List): KotlinType { @@ -168,6 +171,7 @@ private fun approximateProjection(typeArgument: TypeArgument): ApproximationBoun val (inLower, inUpper) = approximateCapturedTypes(typeArgument.inProjection) val (outLower, outUpper) = approximateCapturedTypes(typeArgument.outProjection) return ApproximationBounds( - lower = TypeArgument(typeArgument.typeParameter, inUpper, outLower), - upper = TypeArgument(typeArgument.typeParameter, inLower, outUpper)) + lower = TypeArgument(typeArgument.typeParameter, inUpper, outLower), + upper = TypeArgument(typeArgument.typeParameter, inLower, outUpper) + ) }