Minor: reformat CapturedTypeConstructor.kt according to code style

This commit is contained in:
Dmitriy Novozhilov
2019-01-21 14:26:21 +03:00
parent 53432eaf99
commit 667f5032b6
@@ -28,8 +28,8 @@ import org.jetbrains.kotlin.types.checker.NewCapturedTypeConstructor
import org.jetbrains.kotlin.types.typeUtil.builtIns import org.jetbrains.kotlin.types.typeUtil.builtIns
class CapturedTypeConstructor( class CapturedTypeConstructor(
val typeProjection: TypeProjection val typeProjection: TypeProjection
): TypeConstructor { ) : TypeConstructor {
var newTypeConstructor: NewCapturedTypeConstructor? = null var newTypeConstructor: NewCapturedTypeConstructor? = null
init { init {
@@ -60,17 +60,18 @@ class CapturedTypeConstructor(
} }
class CapturedType( class CapturedType(
val typeProjection: TypeProjection, val typeProjection: TypeProjection,
override val constructor: CapturedTypeConstructor = CapturedTypeConstructor(typeProjection), override val constructor: CapturedTypeConstructor = CapturedTypeConstructor(typeProjection),
override val isMarkedNullable: Boolean = false, override val isMarkedNullable: Boolean = false,
override val annotations: Annotations = Annotations.EMPTY override val annotations: Annotations = Annotations.EMPTY
): SimpleType(), SubtypingRepresentatives { ) : SimpleType(), SubtypingRepresentatives {
override val arguments: List<TypeProjection> override val arguments: List<TypeProjection>
get() = listOf() get() = listOf()
override val memberScope: MemberScope override val memberScope: MemberScope
get() = ErrorUtils.createErrorScope( get() = ErrorUtils.createErrorScope(
"No member resolution should be done on captured type, it used only during constraint system resolution", true) "No member resolution should be done on captured type, it used only during constraint system resolution", true
)
override val subTypeRepresentative: KotlinType override val subTypeRepresentative: KotlinType
get() = representative(OUT_VARIANCE, builtIns.nullableAnyType) get() = representative(OUT_VARIANCE, builtIns.nullableAnyType)
@@ -90,26 +91,28 @@ class CapturedType(
return CapturedType(typeProjection, constructor, newNullability, annotations) return CapturedType(typeProjection, constructor, newNullability, annotations)
} }
override fun replaceAnnotations(newAnnotations: Annotations): CapturedType = CapturedType(typeProjection, constructor, isMarkedNullable, newAnnotations) override fun replaceAnnotations(newAnnotations: Annotations): CapturedType =
CapturedType(typeProjection, constructor, isMarkedNullable, newAnnotations)
} }
fun createCapturedType(typeProjection: TypeProjection): KotlinType fun createCapturedType(typeProjection: TypeProjection): KotlinType = CapturedType(typeProjection)
= CapturedType(typeProjection)
fun KotlinType.isCaptured(): Boolean = constructor is CapturedTypeConstructor fun KotlinType.isCaptured(): Boolean = constructor is CapturedTypeConstructor
fun TypeSubstitution.wrapWithCapturingSubstitution(needApproximation: Boolean = true): TypeSubstitution = fun TypeSubstitution.wrapWithCapturingSubstitution(needApproximation: Boolean = true): TypeSubstitution =
if (this is IndexedParametersSubstitution) if (this is IndexedParametersSubstitution)
IndexedParametersSubstitution( IndexedParametersSubstitution(
this.parameters, this.parameters,
this.arguments.zip(this.parameters).map { this.arguments.zip(this.parameters).map {
it.first.createCapturedIfNeeded(it.second) it.first.createCapturedIfNeeded(it.second)
}.toTypedArray(), }.toTypedArray(),
approximateCapturedTypes = needApproximation) approximateCapturedTypes = needApproximation
)
else else
object : DelegatedTypeSubstitution(this@wrapWithCapturingSubstitution) { object : DelegatedTypeSubstitution(this@wrapWithCapturingSubstitution) {
override fun approximateContravariantCapturedTypes() = needApproximation override fun approximateContravariantCapturedTypes() = needApproximation
override fun get(key: KotlinType) = super.get(key)?.createCapturedIfNeeded(key.constructor.declarationDescriptor as? TypeParameterDescriptor) override fun get(key: KotlinType) =
super.get(key)?.createCapturedIfNeeded(key.constructor.declarationDescriptor as? TypeParameterDescriptor)
} }
private fun TypeProjection.createCapturedIfNeeded(typeParameterDescriptor: TypeParameterDescriptor?): TypeProjection { private fun TypeProjection.createCapturedIfNeeded(typeParameterDescriptor: TypeParameterDescriptor?): TypeProjection {