diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-08-25 14:51:53 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-27 17:35:04 +0200 |
commit | b05eb93d345cccd0cae9393f99acd428012d1106 (patch) | |
tree | e5bbc7ec75b5b5034c3d6b3e7c9690a510150264 /core/src/main/kotlin/model/Documentable.kt | |
parent | 1c6dabaee7764954a9783effa7463f9866a02066 (diff) | |
download | dokka-b05eb93d345cccd0cae9393f99acd428012d1106.tar.gz dokka-b05eb93d345cccd0cae9393f99acd428012d1106.tar.bz2 dokka-b05eb93d345cccd0cae9393f99acd428012d1106.zip |
Add handling for generic type parameters variance
Diffstat (limited to 'core/src/main/kotlin/model/Documentable.kt')
-rw-r--r-- | core/src/main/kotlin/model/Documentable.kt | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/core/src/main/kotlin/model/Documentable.kt b/core/src/main/kotlin/model/Documentable.kt index c9bf7760..2ea4a328 100644 --- a/core/src/main/kotlin/model/Documentable.kt +++ b/core/src/main/kotlin/model/Documentable.kt @@ -309,14 +309,27 @@ data class DParameter( } data class DTypeParameter( - override val dri: DRI, - override val name: String, + val variantTypeParameter: Variance<TypeParameter>, override val documentation: SourceSetDependent<DocumentationNode>, override val expectPresentInSet: DokkaSourceSet?, val bounds: List<Bound>, override val sourceSets: Set<DokkaSourceSet>, override val extra: PropertyContainer<DTypeParameter> = PropertyContainer.empty() ) : Documentable(), WithExtraProperties<DTypeParameter> { + + constructor( + dri: DRI, + name: String, + documentation: SourceSetDependent<DocumentationNode>, + expectPresentInSet: DokkaSourceSet?, + bounds: List<Bound>, + sourceSets: Set<DokkaSourceSet>, + extra: PropertyContainer<DTypeParameter> = PropertyContainer.empty() + ) : this(Invariance(TypeParameter(dri, name)), documentation, expectPresentInSet, bounds, sourceSets, extra) + + override val dri: DRI by variantTypeParameter.inner::dri + override val name: String by variantTypeParameter.inner::name + override val children: List<Nothing> get() = emptyList() @@ -352,8 +365,18 @@ data class TypeConstructor( ) : Bound() data class Nullable(val inner: Bound) : Bound() -data class Variance(val kind: Kind, val inner: Bound) : Projection() { - enum class Kind { In, Out } + +sealed class Variance<out T : Bound> : Projection() { + abstract val inner: T +} +data class Covariance<out T : Bound>(override val inner: T) : Variance<T>() { + override fun toString() = "out" +} +data class Contravariance<out T : Bound>(override val inner: T) : Variance<T>() { + override fun toString() = "in" +} +data class Invariance<out T : Bound>(override val inner: T) : Variance<T>() { + override fun toString() = "" } data class PrimitiveJavaType(val name: String) : Bound() @@ -366,6 +389,12 @@ enum class FunctionModifiers { NONE, FUNCTION, EXTENSION } +fun Variance<TypeParameter>.withNewDri(dri: DRI) = when(this) { + is Contravariance -> Contravariance(TypeParameter(dri, inner.name)) + is Covariance -> Covariance(TypeParameter(dri, inner.name)) + is Invariance -> Invariance(TypeParameter(dri, inner.name)) +} + private fun String.shorten(maxLength: Int) = lineSequence().first().let { if (it.length != length || it.length > maxLength) it.take(maxLength - 3) + "..." else it } |