mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-04-09 15:52:05 +00:00
Use Variance instead of custom class in KtTypeArgumentWithVariance
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.idea.frontend.api
|
||||
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
sealed class KtTypeArgument
|
||||
|
||||
@@ -13,10 +14,5 @@ object KtStarProjectionTypeArgument : KtTypeArgument()
|
||||
|
||||
abstract class KtTypeArgumentWithVariance : KtTypeArgument() {
|
||||
abstract val type: KtType
|
||||
abstract val variance: KtTypeArgumentVariance
|
||||
abstract val variance: Variance
|
||||
}
|
||||
|
||||
enum class KtTypeArgumentVariance {
|
||||
COVARIANT, CONTRAVARIANT, INVARIANT
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.idea.frontend.api.components
|
||||
import org.jetbrains.kotlin.idea.frontend.api.*
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.*
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
abstract class KtTypeRenderer : KtAnalysisSessionComponent() {
|
||||
abstract fun render(type: KtType, options: KtTypeRendererOptions): String
|
||||
@@ -83,9 +84,9 @@ class KtDefaultTypeRenderer(override val analysisSession: KtAnalysisSession, ove
|
||||
}
|
||||
is KtTypeArgumentWithVariance -> {
|
||||
val varianceWithSpace = when (typeArgument.variance) {
|
||||
KtTypeArgumentVariance.COVARIANT -> "out "
|
||||
KtTypeArgumentVariance.CONTRAVARIANT -> "in "
|
||||
KtTypeArgumentVariance.INVARIANT -> ""
|
||||
Variance.OUT_VARIANCE -> "out "
|
||||
Variance.IN_VARIANCE -> "in "
|
||||
Variance.INVARIANT -> ""
|
||||
}
|
||||
append(varianceWithSpace)
|
||||
render(typeArgument.type, options)
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.idea.frontend.api.types.KtType
|
||||
import org.jetbrains.kotlin.idea.stubindex.PackageIndexUtil
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
import java.util.concurrent.ConcurrentMap
|
||||
|
||||
/**
|
||||
@@ -189,9 +190,9 @@ internal class KtSymbolByFirBuilder private constructor(
|
||||
}
|
||||
|
||||
private fun ProjectionKind.toVariance() = when (this) {
|
||||
ProjectionKind.OUT -> KtTypeArgumentVariance.COVARIANT
|
||||
ProjectionKind.IN -> KtTypeArgumentVariance.CONTRAVARIANT
|
||||
ProjectionKind.INVARIANT -> KtTypeArgumentVariance.INVARIANT
|
||||
ProjectionKind.OUT -> Variance.OUT_VARIANCE
|
||||
ProjectionKind.IN -> Variance.IN_VARIANCE
|
||||
ProjectionKind.INVARIANT -> Variance.INVARIANT
|
||||
ProjectionKind.STAR -> error("KtStarProjectionTypeArgument be directly created")
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.idea.frontend.api.symbols.KtTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.idea.frontend.api.types.*
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
internal interface KtFirType : KtType, ValidityTokenOwner {
|
||||
val coneType: ConeKotlinType
|
||||
@@ -103,5 +104,5 @@ internal class KtFirIntersectionType(
|
||||
|
||||
internal class KtFirTypeArgumentWithVariance(
|
||||
override val type: KtType,
|
||||
override val variance: KtTypeArgumentVariance
|
||||
override val variance: Variance
|
||||
) : KtTypeArgumentWithVariance()
|
||||
Reference in New Issue
Block a user