diff options
author | sebastian.sellmair <sebastian.sellmair@jetbrains.com> | 2020-06-26 17:01:48 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-07-02 13:14:08 +0200 |
commit | ae8b4481b56d6bac4a3feb6a427e77afdbe36b2f (patch) | |
tree | 2708bb3718be7a9d351bfcecb0a0e45d5485691b /plugins | |
parent | 7b8d341efbaf96abe6c5c848bccfd74d7ddce606 (diff) | |
download | dokka-ae8b4481b56d6bac4a3feb6a427e77afdbe36b2f.tar.gz dokka-ae8b4481b56d6bac4a3feb6a427e77afdbe36b2f.tar.bz2 dokka-ae8b4481b56d6bac4a3feb6a427e77afdbe36b2f.zip |
Show fully qualified name for typealias targets to different packages
Diffstat (limited to 'plugins')
4 files changed, 191 insertions, 17 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 + } + } +} diff --git a/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt b/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt index 20aba2e8..6cb8b0f4 100644 --- a/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt +++ b/plugins/base/src/test/kotlin/content/signatures/ContentForSignaturesTest.kt @@ -1,13 +1,15 @@ package content.signatures import matchers.content.* -import org.jetbrains.dokka.pages.ContentPage -import org.jetbrains.dokka.pages.PackagePageNode +import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.doc.Text +import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.testApi.testRunner.AbstractCoreTest import org.junit.jupiter.api.Test import utils.ParamAttributes import utils.bareSignature import utils.propertySignature +import utils.typealiasSignature class ContentForSignaturesTest : AbstractCoreTest() { @@ -370,4 +372,85 @@ class ContentForSignaturesTest : AbstractCoreTest() { } } } -}
\ No newline at end of file + + @Test + fun `typealias to String`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |typealias Alias = String + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } as PackagePageNode + page.content.assertNode { + typealiasSignature("Alias", "String") + } + } + } + } + + @Test + fun `typealias to Int`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |typealias Alias = Int + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } as PackagePageNode + page.content.assertNode { + typealiasSignature("Alias", "Int") + } + } + } + } + + @Test + fun `typealias to type in same package`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + | + |typealias Alias = X + |class X + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } as PackagePageNode + page.content.assertNode { + typealiasSignature("Alias", "X") + } + } + } + } + + @Test + fun `typealias to type in different package`() { + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + |import other.X + |typealias Alias = X + | + |/src/main/kotlin/test/source2.kt + |package other + |class X + """.trimIndent(), testConfiguration + ) { + pagesTransformationStage = { module -> + val page = module.children.single { it.name == "test" } as PackagePageNode + page.content.assertNode { + typealiasSignature("Alias", "other.X") + } + } + } + } +} diff --git a/plugins/base/src/test/kotlin/utils/contentUtils.kt b/plugins/base/src/test/kotlin/utils/contentUtils.kt index 90813cf8..7fcd8e89 100644 --- a/plugins/base/src/test/kotlin/utils/contentUtils.kt +++ b/plugins/base/src/test/kotlin/utils/contentUtils.kt @@ -167,6 +167,49 @@ fun ContentMatcherBuilder<*>.propertySignature( } } + +fun ContentMatcherBuilder<*>.typealiasSignature(name: String, expressionTarget: String) { + group { + header { +"Package test" } + skipAllNotMatching() + } + group { + group { + skipAllNotMatching() + header { +"Types" } + table { + group { + link { +name } + divergentGroup { + divergentInstance { + group { + group { + group { + group { + +"typealias " + group { + link { +name } + skipAllNotMatching() + } + +" = " + group { + link { +expressionTarget } + } + } + } + } + } + } + skipAllNotMatching() + } + } + skipAllNotMatching() + } + skipAllNotMatching() + } + } +} + fun ContentMatcherBuilder<*>.pWrapped(text: String) = group {// TODO: remove it when double wrapping for descriptions will be resolved group { +text } @@ -197,4 +240,4 @@ data class ParamAttributes( val annotations: Map<String, Set<String>>, val keywords: Set<String>, val type: String -)
\ No newline at end of file +) |