From 85cd4f3cdf1f3f068fc35f96975bc4c2a9acaf69 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Fri, 15 Feb 2019 03:48:58 +0300 Subject: [PATCH] Extract common code (TypeSystemContext) --- .../types/checker/ClassicTypeSystemContext.kt | 35 ++++++------------- .../kotlin/types/model/TypeSystemContext.kt | 17 +++++++-- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt index fbc2663fe5b..89e530ba668 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/checker/ClassicTypeSystemContext.kt @@ -121,13 +121,7 @@ interface ClassicTypeSystemContext : TypeSystemContext { return this.projectionKind.convertVariance() } - private fun Variance.convertVariance(): TypeVariance { - return when (this) { - Variance.INVARIANT -> TypeVariance.INV - Variance.IN_VARIANCE -> TypeVariance.IN - Variance.OUT_VARIANCE -> TypeVariance.OUT - } - } + override fun TypeArgumentMarker.getType(): KotlinTypeMarker { require(this is TypeProjection, this::errorMessage) @@ -189,23 +183,6 @@ interface ClassicTypeSystemContext : TypeSystemContext { classDescriptor.kind != ClassKind.ANNOTATION_CLASS } - - override fun TypeArgumentListMarker.get(index: Int): TypeArgumentMarker { - return when (this) { - is SimpleTypeMarker -> getArgument(index) - is ArgumentList -> get(index) - else -> error("unknown type argument list type: $this, ${this::class}") - } - } - - override fun TypeArgumentListMarker.size(): Int { - return when (this) { - is SimpleTypeMarker -> argumentsCount() - is ArgumentList -> size - else -> error("unknown type argument list type: $this, ${this::class}") - } - } - override fun SimpleTypeMarker.asArgumentList(): TypeArgumentListMarker { require(this is SimpleType, this::errorMessage) return this @@ -257,4 +234,12 @@ interface ClassicTypeSystemContext : TypeSystemContext { @Suppress("NOTHING_TO_INLINE") private inline fun Any.errorMessage(): String { return "ClassicTypeSystemContext couldn't handle: $this, ${this::class}" -} \ No newline at end of file +} + +fun Variance.convertVariance(): TypeVariance { + return when (this) { + Variance.INVARIANT -> TypeVariance.INV + Variance.IN_VARIANCE -> TypeVariance.IN + Variance.OUT_VARIANCE -> TypeVariance.OUT + } +} diff --git a/core/type-system/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt b/core/type-system/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt index f8ece07e32c..193b0e32220 100644 --- a/core/type-system/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt +++ b/core/type-system/src/org/jetbrains/kotlin/types/model/TypeSystemContext.kt @@ -114,8 +114,21 @@ interface TypeSystemContext : TypeSystemOptimizationContext { fun SimpleTypeMarker.asArgumentList(): TypeArgumentListMarker - fun TypeArgumentListMarker.size(): Int - operator fun TypeArgumentListMarker.get(index: Int): TypeArgumentMarker + operator fun TypeArgumentListMarker.get(index: Int): TypeArgumentMarker { + return when (this) { + is SimpleTypeMarker -> getArgument(index) + is ArgumentList -> get(index) + else -> error("unknown type argument list type: $this, ${this::class}") + } + } + + fun TypeArgumentListMarker.size(): Int { + return when (this) { + is SimpleTypeMarker -> argumentsCount() + is ArgumentList -> size + else -> error("unknown type argument list type: $this, ${this::class}") + } + } fun TypeConstructorMarker.isAnyConstructor(): Boolean fun TypeConstructorMarker.isNothingConstructor(): Boolean