Extract common code (TypeSystemContext)

This commit is contained in:
Simon Ogorodnik
2019-02-15 03:48:58 +03:00
committed by Mikhail Glukhikh
parent 2c7b05a67b
commit 85cd4f3cdf
2 changed files with 25 additions and 27 deletions
@@ -121,13 +121,7 @@ interface ClassicTypeSystemContext : TypeSystemContext {
return this.projectionKind.convertVariance() 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 { override fun TypeArgumentMarker.getType(): KotlinTypeMarker {
require(this is TypeProjection, this::errorMessage) require(this is TypeProjection, this::errorMessage)
@@ -189,23 +183,6 @@ interface ClassicTypeSystemContext : TypeSystemContext {
classDescriptor.kind != ClassKind.ANNOTATION_CLASS 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 { override fun SimpleTypeMarker.asArgumentList(): TypeArgumentListMarker {
require(this is SimpleType, this::errorMessage) require(this is SimpleType, this::errorMessage)
return this return this
@@ -258,3 +235,11 @@ interface ClassicTypeSystemContext : TypeSystemContext {
private inline fun Any.errorMessage(): String { private inline fun Any.errorMessage(): String {
return "ClassicTypeSystemContext couldn't handle: $this, ${this::class}" return "ClassicTypeSystemContext couldn't handle: $this, ${this::class}"
} }
fun Variance.convertVariance(): TypeVariance {
return when (this) {
Variance.INVARIANT -> TypeVariance.INV
Variance.IN_VARIANCE -> TypeVariance.IN
Variance.OUT_VARIANCE -> TypeVariance.OUT
}
}
@@ -114,8 +114,21 @@ interface TypeSystemContext : TypeSystemOptimizationContext {
fun SimpleTypeMarker.asArgumentList(): TypeArgumentListMarker 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.isAnyConstructor(): Boolean
fun TypeConstructorMarker.isNothingConstructor(): Boolean fun TypeConstructorMarker.isNothingConstructor(): Boolean