Minor: reformat CapturedTypeApproximation.kt according to code style
This commit is contained in:
@@ -29,14 +29,14 @@ import org.jetbrains.kotlin.types.typeUtil.builtIns
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
data class ApproximationBounds<out T>(
|
data class ApproximationBounds<out T>(
|
||||||
val lower: T,
|
val lower: T,
|
||||||
val upper: T
|
val upper: T
|
||||||
)
|
)
|
||||||
|
|
||||||
private class TypeArgument(
|
private class TypeArgument(
|
||||||
val typeParameter: TypeParameterDescriptor,
|
val typeParameter: TypeParameterDescriptor,
|
||||||
val inProjection: KotlinType,
|
val inProjection: KotlinType,
|
||||||
val outProjection: KotlinType
|
val outProjection: KotlinType
|
||||||
) {
|
) {
|
||||||
val isConsistent: Boolean
|
val isConsistent: Boolean
|
||||||
get() = KotlinTypeChecker.DEFAULT.isSubtypeOf(inProjection, outProjection)
|
get() = KotlinTypeChecker.DEFAULT.isSubtypeOf(inProjection, outProjection)
|
||||||
@@ -48,8 +48,10 @@ private fun TypeArgument.toTypeProjection(): TypeProjection {
|
|||||||
classifierNamePolicy = ClassifierNamePolicy.FULLY_QUALIFIED
|
classifierNamePolicy = ClassifierNamePolicy.FULLY_QUALIFIED
|
||||||
}
|
}
|
||||||
"Only consistent enhanced type projection can be converted to type projection, but " +
|
"Only consistent enhanced type projection can be converted to type projection, but " +
|
||||||
"[${descriptorRenderer.render(typeParameter)}: <${descriptorRenderer.renderType(inProjection)}, ${descriptorRenderer.renderType(outProjection)}>]" +
|
"[${descriptorRenderer.render(typeParameter)}: <${descriptorRenderer.renderType(inProjection)}, ${descriptorRenderer.renderType(
|
||||||
" was found"
|
outProjection
|
||||||
|
)}>]" +
|
||||||
|
" was found"
|
||||||
}
|
}
|
||||||
fun removeProjectionIfRedundant(variance: Variance) = if (variance == typeParameter.variance) Variance.INVARIANT else variance
|
fun removeProjectionIfRedundant(variance: Variance) = if (variance == typeParameter.variance) Variance.INVARIANT else variance
|
||||||
return when {
|
return when {
|
||||||
@@ -62,11 +64,11 @@ private fun TypeArgument.toTypeProjection(): TypeProjection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun TypeProjection.toTypeArgument(typeParameter: TypeParameterDescriptor) =
|
private fun TypeProjection.toTypeArgument(typeParameter: TypeParameterDescriptor) =
|
||||||
when (TypeSubstitutor.combine(typeParameter.variance, this)) {
|
when (TypeSubstitutor.combine(typeParameter.variance, this)) {
|
||||||
Variance.INVARIANT -> TypeArgument(typeParameter, type, type)
|
Variance.INVARIANT -> TypeArgument(typeParameter, type, type)
|
||||||
Variance.IN_VARIANCE -> TypeArgument(typeParameter, type, typeParameter.builtIns.nullableAnyType)
|
Variance.IN_VARIANCE -> TypeArgument(typeParameter, type, typeParameter.builtIns.nullableAnyType)
|
||||||
Variance.OUT_VARIANCE -> TypeArgument(typeParameter, typeParameter.builtIns.nothingType, type)
|
Variance.OUT_VARIANCE -> TypeArgument(typeParameter, typeParameter.builtIns.nothingType, type)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun approximateCapturedTypesIfNecessary(typeProjection: TypeProjection?, approximateContravariant: Boolean): TypeProjection? {
|
fun approximateCapturedTypesIfNecessary(typeProjection: TypeProjection?, approximateContravariant: Boolean): TypeProjection? {
|
||||||
if (typeProjection == null) return null
|
if (typeProjection == null) return null
|
||||||
@@ -112,14 +114,15 @@ fun approximateCapturedTypes(type: KotlinType): ApproximationBounds<KotlinType>
|
|||||||
val boundsForFlexibleUpper = approximateCapturedTypes(type.upperIfFlexible())
|
val boundsForFlexibleUpper = approximateCapturedTypes(type.upperIfFlexible())
|
||||||
|
|
||||||
return ApproximationBounds(
|
return ApproximationBounds(
|
||||||
KotlinTypeFactory.flexibleType(
|
KotlinTypeFactory.flexibleType(
|
||||||
boundsForFlexibleLower.lower.lowerIfFlexible(),
|
boundsForFlexibleLower.lower.lowerIfFlexible(),
|
||||||
boundsForFlexibleUpper.lower.upperIfFlexible()
|
boundsForFlexibleUpper.lower.upperIfFlexible()
|
||||||
).inheritEnhancement(type),
|
).inheritEnhancement(type),
|
||||||
KotlinTypeFactory.flexibleType(
|
KotlinTypeFactory.flexibleType(
|
||||||
boundsForFlexibleLower.upper.lowerIfFlexible(),
|
boundsForFlexibleLower.upper.lowerIfFlexible(),
|
||||||
boundsForFlexibleUpper.upper.upperIfFlexible()
|
boundsForFlexibleUpper.upper.upperIfFlexible()
|
||||||
).inheritEnhancement(type))
|
).inheritEnhancement(type)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val typeConstructor = type.constructor
|
val typeConstructor = type.constructor
|
||||||
@@ -146,8 +149,7 @@ fun approximateCapturedTypes(type: KotlinType): ApproximationBounds<KotlinType>
|
|||||||
if (typeProjection.isStarProjection) {
|
if (typeProjection.isStarProjection) {
|
||||||
lowerBoundArguments.add(typeArgument)
|
lowerBoundArguments.add(typeArgument)
|
||||||
upperBoundArguments.add(typeArgument)
|
upperBoundArguments.add(typeArgument)
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
val (lower, upper) = approximateProjection(typeArgument)
|
val (lower, upper) = approximateProjection(typeArgument)
|
||||||
lowerBoundArguments.add(lower)
|
lowerBoundArguments.add(lower)
|
||||||
upperBoundArguments.add(upper)
|
upperBoundArguments.add(upper)
|
||||||
@@ -155,8 +157,9 @@ fun approximateCapturedTypes(type: KotlinType): ApproximationBounds<KotlinType>
|
|||||||
}
|
}
|
||||||
val lowerBoundIsTrivial = lowerBoundArguments.any { !it.isConsistent }
|
val lowerBoundIsTrivial = lowerBoundArguments.any { !it.isConsistent }
|
||||||
return ApproximationBounds(
|
return ApproximationBounds(
|
||||||
if (lowerBoundIsTrivial) type.builtIns.nothingType else type.replaceTypeArguments(lowerBoundArguments),
|
if (lowerBoundIsTrivial) type.builtIns.nothingType else type.replaceTypeArguments(lowerBoundArguments),
|
||||||
type.replaceTypeArguments(upperBoundArguments))
|
type.replaceTypeArguments(upperBoundArguments)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun KotlinType.replaceTypeArguments(newTypeArguments: List<TypeArgument>): KotlinType {
|
private fun KotlinType.replaceTypeArguments(newTypeArguments: List<TypeArgument>): KotlinType {
|
||||||
@@ -168,6 +171,7 @@ private fun approximateProjection(typeArgument: TypeArgument): ApproximationBoun
|
|||||||
val (inLower, inUpper) = approximateCapturedTypes(typeArgument.inProjection)
|
val (inLower, inUpper) = approximateCapturedTypes(typeArgument.inProjection)
|
||||||
val (outLower, outUpper) = approximateCapturedTypes(typeArgument.outProjection)
|
val (outLower, outUpper) = approximateCapturedTypes(typeArgument.outProjection)
|
||||||
return ApproximationBounds(
|
return ApproximationBounds(
|
||||||
lower = TypeArgument(typeArgument.typeParameter, inUpper, outLower),
|
lower = TypeArgument(typeArgument.typeParameter, inUpper, outLower),
|
||||||
upper = TypeArgument(typeArgument.typeParameter, inLower, outUpper))
|
upper = TypeArgument(typeArgument.typeParameter, inLower, outUpper)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user