aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-06-26 17:01:48 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-07-02 13:14:08 +0200
commitae8b4481b56d6bac4a3feb6a427e77afdbe36b2f (patch)
tree2708bb3718be7a9d351bfcecb0a0e45d5485691b /plugins/base/src/main/kotlin
parent7b8d341efbaf96abe6c5c848bccfd74d7ddce606 (diff)
downloaddokka-ae8b4481b56d6bac4a3feb6a427e77afdbe36b2f.tar.gz
dokka-ae8b4481b56d6bac4a3feb6a427e77afdbe36b2f.tar.bz2
dokka-ae8b4481b56d6bac4a3feb6a427e77afdbe36b2f.zip
Show fully qualified name for typealias targets to different packages
Diffstat (limited to 'plugins/base/src/main/kotlin')
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt53
-rw-r--r--plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt21
2 files changed, 61 insertions, 13 deletions
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
index 493aa403..14c130a2 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt
@@ -2,6 +2,8 @@ package org.jetbrains.dokka.base.signatures
import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
import org.jetbrains.dokka.Platform
+import org.jetbrains.dokka.base.signatures.KotlinSignatureUtils.dri
+import org.jetbrains.dokka.base.signatures.KotlinSignatureUtils.driOrNull
import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder
import org.jetbrains.dokka.links.*
@@ -190,7 +192,12 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
private fun propertySignature(p: DProperty) =
p.sourceSets.map {
- contentBuilder.contentFor(p, ContentKind.Symbol, setOf(TextStyle.Monospace) + p.stylesIfDeprecated(it), sourceSets = setOf(it)) {
+ contentBuilder.contentFor(
+ p,
+ ContentKind.Symbol,
+ setOf(TextStyle.Monospace) + p.stylesIfDeprecated(it),
+ sourceSets = setOf(it)
+ ) {
annotationsBlock(p)
text(p.visibility[it].takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "")
text(
@@ -215,12 +222,17 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
private fun functionSignature(f: DFunction) =
f.sourceSets.map {
- contentBuilder.contentFor(f, ContentKind.Symbol, setOf(TextStyle.Monospace) + f.stylesIfDeprecated(it), sourceSets = setOf(it)) {
+ contentBuilder.contentFor(
+ f,
+ ContentKind.Symbol,
+ setOf(TextStyle.Monospace) + f.stylesIfDeprecated(it),
+ sourceSets = setOf(it)
+ ) {
annotationsBlock(f)
text(f.visibility[it]?.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "")
text(f.modifier[it]?.takeIf { it !in ignoredModifiers }?.let {
- if (it is JavaModifier.Empty) KotlinModifier.Open else it
- }?.name?.let { "$it " } ?: ""
+ if (it is JavaModifier.Empty) KotlinModifier.Open else it
+ }?.name?.let { "$it " } ?: ""
)
text(f.modifiers()[it]?.toSignatureString() ?: "")
text("fun ")
@@ -270,7 +282,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
text("typealias ")
signatureForProjection(t.type)
text(" = ")
- signatureForProjection(type)
+ signatureForTypealiasTarget(t, type)
}
}
}
@@ -286,7 +298,20 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
}
}
- private fun PageContentBuilder.DocumentableContentBuilder.signatureForProjection(p: Projection): Unit =
+ private fun PageContentBuilder.DocumentableContentBuilder.signatureForTypealiasTarget(
+ typeAlias: DTypeAlias, bound: Bound
+ ) {
+ signatureForProjection(
+ p = bound,
+ showFullyQualifiedName =
+ bound.driOrNull?.packageName != typeAlias.dri.packageName &&
+ bound.driOrNull?.packageName != "kotlin"
+ )
+ }
+
+ private fun PageContentBuilder.DocumentableContentBuilder.signatureForProjection(
+ p: Projection, showFullyQualifiedName: Boolean = false
+ ): Unit =
when (p) {
is OtherParameter -> link(p.name, p.declarationDRI)
@@ -294,27 +319,31 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
+funType(mainDRI.single(), mainSourcesetData, p)
else
group(styles = emptySet()) {
- link(p.dri.classNames.orEmpty(), p.dri)
+ val linkText = if (showFullyQualifiedName && p.dri.packageName != null) {
+ "${p.dri.packageName}.${p.dri.classNames.orEmpty()}"
+ } else p.dri.classNames.orEmpty()
+
+ link(linkText, p.dri)
list(p.projections, prefix = "<", suffix = ">") {
- signatureForProjection(it)
+ signatureForProjection(it, showFullyQualifiedName)
}
}
is Variance -> group(styles = emptySet()) {
text(p.kind.toString() + " ")
- signatureForProjection(p.inner)
+ signatureForProjection(p.inner, showFullyQualifiedName)
}
is Star -> text("*")
is Nullable -> group(styles = emptySet()) {
- signatureForProjection(p.inner)
+ signatureForProjection(p.inner, showFullyQualifiedName)
text("?")
}
is JavaObject -> link("Any", DriOfAny)
is Void -> link("Unit", DriOfUnit)
- is PrimitiveJavaType -> signatureForProjection(p.translateToKotlin())
+ is PrimitiveJavaType -> signatureForProjection(p.translateToKotlin(), showFullyQualifiedName)
is Dynamic -> text("dynamic")
is UnresolvedBound -> text(p.name)
}
@@ -342,7 +371,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog
}
private fun PrimitiveJavaType.translateToKotlin() = TypeConstructor(
- dri = DRI("kotlin", name.capitalize()),
+ dri = dri,
projections = emptyList()
)
diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt
index 4fcb9761..0a10875a 100644
--- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt
+++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt
@@ -2,6 +2,8 @@ package org.jetbrains.dokka.base.signatures
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder
import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.links.DriOfAny
+import org.jetbrains.dokka.links.DriOfUnit
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.properties.WithExtraProperties
@@ -26,4 +28,21 @@ object KotlinSignatureUtils : JvmSignatureUtils {
extra[AdditionalModifiers]?.content?.entries?.map {
it.key to it.value.filterIsInstance<ExtraModifiers.KotlinOnlyModifiers>().toSet()
}?.toMap() ?: emptyMap()
-} \ No newline at end of file
+
+
+ val PrimitiveJavaType.dri: DRI get() = DRI("kotlin", name.capitalize())
+
+ val Bound.driOrNull: DRI?
+ get() {
+ return when (this) {
+ is OtherParameter -> this.declarationDRI
+ is TypeConstructor -> this.dri
+ is Nullable -> this.inner.driOrNull
+ is PrimitiveJavaType -> this.dri
+ is Void -> DriOfUnit
+ is JavaObject -> DriOfAny
+ is Dynamic -> null
+ is UnresolvedBound -> null
+ }
+ }
+}