aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src
diff options
context:
space:
mode:
authorAndrzej Ratajczak <andrzej.ratajczak98@gmail.com>2020-08-25 14:51:53 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-08-27 17:35:04 +0200
commitb05eb93d345cccd0cae9393f99acd428012d1106 (patch)
treee5bbc7ec75b5b5034c3d6b3e7c9690a510150264 /plugins/base/src
parent1c6dabaee7764954a9783effa7463f9866a02066 (diff)
downloaddokka-b05eb93d345cccd0cae9393f99acd428012d1106.tar.gz
dokka-b05eb93d345cccd0cae9393f99acd428012d1106.tar.bz2
dokka-b05eb93d345cccd0cae9393f99acd428012d1106.zip
Add handling for generic type parameters variance
Diffstat (limited to 'plugins/base/src')
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt6
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt2
-rw-r--r--plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt38
-rw-r--r--plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt4
4 files changed, 26 insertions, 24 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
index 82eeb296..d6beb474 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
@@ -295,7 +295,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
private fun signature(t: DTypeParameter) =
t.sourceSets.map {
contentBuilder.contentFor(t, styles = t.stylesIfDeprecated(it), sourceSets = setOf(it)) {
- link(t.name, t.dri.withTargetToDeclaration())
+ signatureForProjection(t.variantTypeParameter.withNewDri(t.dri.withTargetToDeclaration()))
list(t.nontrivialBounds, prefix = " : ") { bound ->
signatureForProjection(bound)
}
@@ -333,8 +333,8 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
}
}
- is Variance -> group(styles = emptySet()) {
- text(p.kind.toString() + " ")
+ is Variance<*> -> group(styles = emptySet()) {
+ text("$p ".takeIf { it.isNotBlank() } ?: "")
signatureForProjection(p.inner, showFullyQualifiedName)
}
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt
index e8107177..c40c48a2 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt
@@ -55,7 +55,7 @@ object KotlinSignatureUtils : JvmSignatureUtils {
is JavaObject -> listOf(DriOfAny)
is Dynamic -> emptyList()
is UnresolvedBound -> emptyList()
- is Variance -> inner.drisOfAllNestedBounds
+ is Variance<*> -> inner.drisOfAllNestedBounds
is Star -> emptyList()
}
diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
index 05c99af1..fccbe716 100644
--- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt
@@ -11,7 +11,6 @@ import org.jetbrains.dokka.links.Callable
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.Nullable
import org.jetbrains.dokka.model.TypeConstructor
-import org.jetbrains.dokka.model.Variance
import org.jetbrains.dokka.model.doc.*
import org.jetbrains.dokka.model.properties.PropertyContainer
import org.jetbrains.dokka.plugability.DokkaContext
@@ -146,7 +145,7 @@ private class DokkaDescriptorVisitor(
visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(),
supertypes = info.supertypes.toSourceSetDependent(),
documentation = info.docs,
- generics = descriptor.declaredTypeParameters.map { it.toTypeParameter() },
+ generics = descriptor.declaredTypeParameters.map { it.toVariantTypeParameter() },
companion = descriptor.companion(driWithPlatform),
sourceSets = setOf(sourceSet),
extra = PropertyContainer.withAll(
@@ -254,7 +253,7 @@ private class DokkaDescriptorVisitor(
),
companion = descriptor.companionObjectDescriptor?.let { objectDescriptor(it, driWithPlatform) },
visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(),
- generics = descriptor.declaredTypeParameters.map { it.toTypeParameter() },
+ generics = descriptor.declaredTypeParameters.map { it.toVariantTypeParameter() },
constructors = descriptor.constructors.map { visitConstructorDescriptor(it, driWithPlatform) },
sources = descriptor.createSources()
)
@@ -284,7 +283,7 @@ private class DokkaDescriptorVisitor(
expectPresentInSet = sourceSet.takeIf { isExpect },
visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(),
supertypes = info.supertypes.toSourceSetDependent(),
- generics = descriptor.declaredTypeParameters.map { it.toTypeParameter() },
+ generics = descriptor.declaredTypeParameters.map { it.toVariantTypeParameter() },
documentation = info.docs,
modifier = descriptor.modifier().toSourceSetDependent(),
companion = descriptor.companion(driWithPlatform),
@@ -321,7 +320,7 @@ private class DokkaDescriptorVisitor(
type = descriptor.returnType!!.toBound(),
expectPresentInSet = sourceSet.takeIf { isExpect },
sourceSets = setOf(sourceSet),
- generics = descriptor.typeParameters.map { it.toTypeParameter() },
+ generics = descriptor.typeParameters.map { it.toVariantTypeParameter() },
extra = PropertyContainer.withAll(
(descriptor.additionalExtras() + descriptor.getAnnotationsWithBackingField()
.toAdditionalExtras()).toSet().toSourceSetDependent().toAdditionalModifiers(),
@@ -354,7 +353,7 @@ private class DokkaDescriptorVisitor(
expectPresentInSet = sourceSet.takeIf { isExpect },
sources = actual,
visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(),
- generics = descriptor.typeParameters.map { it.toTypeParameter() },
+ generics = descriptor.typeParameters.map { it.toVariantTypeParameter() },
documentation = descriptor.takeIf { it.kind != CallableMemberDescriptor.Kind.SYNTHESIZED }
?.resolveDescriptorData() ?: emptyMap(),
modifier = descriptor.modifier().toSourceSetDependent(),
@@ -402,7 +401,7 @@ private class DokkaDescriptorVisitor(
},
type = descriptor.returnType.toBound(),
modifier = descriptor.modifier().toSourceSetDependent(),
- generics = descriptor.typeParameters.map { it.toTypeParameter() },
+ generics = descriptor.typeParameters.map { it.toVariantTypeParameter() },
sourceSets = setOf(sourceSet),
extra = PropertyContainer.withAll<DFunction>(
descriptor.additionalExtras().toSourceSetDependent().toAdditionalModifiers(),
@@ -472,7 +471,7 @@ private class DokkaDescriptorVisitor(
visibility = descriptor.visibility.toDokkaVisibility().toSourceSetDependent(),
documentation = descriptor.resolveDescriptorData(),
type = descriptor.returnType!!.toBound(),
- generics = descriptor.typeParameters.map { it.toTypeParameter() },
+ generics = descriptor.typeParameters.map { it.toVariantTypeParameter() },
modifier = descriptor.modifier().toSourceSetDependent(),
expectPresentInSet = sourceSet.takeIf { isExpect },
receiver = descriptor.extensionReceiverParameter?.let {
@@ -501,7 +500,7 @@ private class DokkaDescriptorVisitor(
visibility = visibility.toDokkaVisibility().toSourceSetDependent(),
documentation = resolveDescriptorData(),
sourceSets = setOf(sourceSet),
- generics = descriptor.declaredTypeParameters.map { it.toTypeParameter() }
+ generics = descriptor.declaredTypeParameters.map { it.toVariantTypeParameter() }
)
}
@@ -588,10 +587,11 @@ private class DokkaDescriptorVisitor(
)
}
- private fun TypeParameterDescriptor.toTypeParameter() =
+ private fun TypeParameterDescriptor.toVariantTypeParameter() =
DTypeParameter(
- DRI.from(this).withPackageFallbackTo(fallbackPackageName()),
- name.identifier,
+ variantTypeParameter(
+ TypeParameter(DRI.from(this).withPackageFallbackTo(fallbackPackageName()), name.identifier)
+ ),
resolveDescriptorData(),
null,
upperBounds.map { it.toBound() },
@@ -621,12 +621,14 @@ private class DokkaDescriptorVisitor(
private fun TypeProjection.toProjection(): Projection =
if (isStarProjection) Star else formPossiblyVariant()
- private fun TypeProjection.formPossiblyVariant(): Projection = type.toBound().let {
- when (projectionKind) {
- org.jetbrains.kotlin.types.Variance.INVARIANT -> it
- org.jetbrains.kotlin.types.Variance.IN_VARIANCE -> Variance(Variance.Kind.In, it)
- org.jetbrains.kotlin.types.Variance.OUT_VARIANCE -> Variance(Variance.Kind.Out, it)
- }
+ private fun TypeProjection.formPossiblyVariant(): Projection = type.toBound().wrapWithVariance(projectionKind)
+
+ private fun TypeParameterDescriptor.variantTypeParameter(type: TypeParameter) = type.wrapWithVariance(variance)
+
+ private fun <T : Bound> T.wrapWithVariance(variance: org.jetbrains.kotlin.types.Variance) = when (variance) {
+ org.jetbrains.kotlin.types.Variance.INVARIANT -> Invariance(this)
+ org.jetbrains.kotlin.types.Variance.IN_VARIANCE -> Contravariance(this)
+ org.jetbrains.kotlin.types.Variance.OUT_VARIANCE -> Covariance(this)
}
private fun DeclarationDescriptor.getDocumentation() = findKDoc().let {
diff --git a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
index c9118920..c1ed4a08 100644
--- a/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
+++ b/plugins/base/src/main/kotlin/translators/psi/DefaultPsiToDocumentableTranslator.kt
@@ -380,8 +380,8 @@ class DefaultPsiToDocumentableTranslator(
}
private fun getVariance(type: PsiWildcardType): Projection = when {
- type.extendsBound != PsiType.NULL -> Variance(Variance.Kind.Out, getBound(type.extendsBound))
- type.superBound != PsiType.NULL -> Variance(Variance.Kind.In, getBound(type.superBound))
+ type.extendsBound != PsiType.NULL -> Covariance(getBound(type.extendsBound))
+ type.superBound != PsiType.NULL -> Contravariance(getBound(type.superBound))
else -> throw IllegalStateException("${type.presentableText} has incorrect bounds")
}