From ad9f1289015627997b822f99579750805ea2f553 Mon Sep 17 00:00:00 2001 From: Filip ZybaƂa Date: Wed, 10 Jun 2020 13:53:10 +0200 Subject: Fixed sources platform tags; tailrec and external modifiers; sorting. --- .../main/kotlin/signatures/JvmSignatureUtils.kt | 2 +- .../kotlin/signatures/KotlinSignatureProvider.kt | 55 ++++++++++++++++++---- .../main/kotlin/signatures/KotlinSignatureUtils.kt | 1 + .../pages/sourcelinks/SourceLinksTransformer.kt | 2 +- .../documentables/DefaultPageCreator.kt | 8 +++- .../documentables/PageContentBuilder.kt | 9 +++- 6 files changed, 63 insertions(+), 14 deletions(-) (limited to 'plugins/base/src/main/kotlin') diff --git a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt index f8141110..a7fc7570 100644 --- a/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/JvmSignatureUtils.kt @@ -13,7 +13,7 @@ interface JvmSignatureUtils { fun WithExtraProperties.modifiers(): SourceSetDependent> - fun Set.toSignatureString(): String = + fun Collection.toSignatureString(): String = joinToString("") { it.name.toLowerCase() + " " } fun WithExtraProperties.annotations(): SourceSetDependent> = diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt index ab3056ec..faca95ee 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureProvider.kt @@ -1,5 +1,6 @@ package org.jetbrains.dokka.base.signatures +import org.jetbrains.dokka.Platform import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder import org.jetbrains.dokka.links.* @@ -19,6 +20,13 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog private val ignoredVisibilities = setOf(JavaVisibility.Public, KotlinVisibility.Public) private val ignoredModifiers = setOf(JavaModifier.Final, KotlinModifier.Final) + private val ignoredExtraModifiers = setOf( + ExtraModifiers.KotlinOnlyModifiers.TailRec, + ExtraModifiers.KotlinOnlyModifiers.External + ) + private val platformSpecificModifiers : Map> = mapOf( + ExtraModifiers.KotlinOnlyModifiers.External to setOf(Platform.js) + ) override fun signature(documentable: Documentable): ContentNode = when (documentable) { is DFunction -> functionSignature(documentable) @@ -32,6 +40,20 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog ) } + private fun PageContentBuilder.DocumentableContentBuilder.processExtraModifiers (t: T) + where T: Documentable, T: WithExtraProperties { + sourceSetDependentText( + t.modifiers() + .mapValues { entry -> + entry.value.filter { + it !in ignoredExtraModifiers || entry.key.platform in (platformSpecificModifiers[it] ?: emptySet()) + } + } + ) { + it.toSignatureString() + } + } + private fun signature(e: DEnumEntry) = contentBuilder.contentFor( e, @@ -96,11 +118,26 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog } } when (c) { - is DClass -> text("class ") - is DInterface -> text("interface ") - is DEnum -> text("enum ") - is DObject -> text("object ") - is DAnnotation -> text("annotation class ") + is DClass -> { + processExtraModifiers(c) + text("class ") + } + is DInterface -> { + processExtraModifiers(c) + text("interface ") + } + is DEnum -> { + processExtraModifiers(c) + text("enum ") + } + is DObject -> { + processExtraModifiers(c) + text("object ") + } + is DAnnotation -> { + processExtraModifiers(c) + text("annotation class ") + } } link(c.name!!, c.dri) if (c is WithGenerics) { @@ -146,7 +183,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog if (it is JavaModifier.Empty) KotlinModifier.Open else it }?.name?.let { "$it " } ?: "" } - sourceSetDependentText(p.modifiers()) { it.toSignatureString() } + processExtraModifiers(p) p.setter?.let { text("var ") } ?: text("val ") list(p.generics, prefix = "<", suffix = "> ") { +buildSignature(it) @@ -169,7 +206,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog if (it is JavaModifier.Empty) KotlinModifier.Open else it }?.name?.let { "$it " } ?: "" } - sourceSetDependentText(f.modifiers()) { it.toSignatureString() } + processExtraModifiers(f) text("fun ") list(f.generics, prefix = "<", suffix = "> ") { +buildSignature(it) @@ -182,7 +219,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog text("(") list(f.parameters) { annotationsInline(it) - sourceSetDependentText(it.modifiers()) { it.toSignatureString() } + processExtraModifiers(it) text(it.name!!) text(": ") signatureForProjection(it.type) @@ -211,7 +248,7 @@ class KotlinSignatureProvider(ctcc: CommentsToContentConverter, logger: DokkaLog sourceSets = platforms.toSet() ) { sourceSetDependentText(t.visibility) { it.takeIf { it !in ignoredVisibilities }?.name?.let { "$it " } ?: "" } - sourceSetDependentText(t.modifiers()) { it.toSignatureString() } + processExtraModifiers(t) text("typealias ") signatureForProjection(t.type) text(" = ") diff --git a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt index 1f323473..c8ff3fac 100644 --- a/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt +++ b/plugins/base/src/main/kotlin/signatures/KotlinSignatureUtils.kt @@ -12,6 +12,7 @@ object KotlinSignatureUtils : JvmSignatureUtils { private val listBrackets = Pair('[', ']') private val classExtension = "::class" + override fun PageContentBuilder.DocumentableContentBuilder.annotationsBlock(d: Documentable) = annotationsBlockWithIgnored(d, emptySet(), strategy, listBrackets, classExtension) diff --git a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt index d987a5d5..8113d277 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt @@ -61,7 +61,7 @@ class SourceLinksTransformer(val context: DokkaContext, val builder: PageContent +ContentTable( emptyList(), sources.map { - buildGroup(node.dri, setOf(it.first)) { + buildGroup(node.dri, setOf(it.first), kind = ContentKind.Source) { +link("(source)", it.second) } }, diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index b69f60d2..bc3f79c8 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -180,7 +180,7 @@ open class DefaultPageCreator( } } if (c is DEnum) { - block("Entries", 2, ContentKind.Classlikes, c.entries, c.sourceSets.toSet(), extra = mainExtra + SimpleAttr.header("Entries"), styles = emptySet()) { + block("Entries", 2, ContentKind.Classlikes, c.entries, c.sourceSets.toSet(), needsSorting = false, extra = mainExtra + SimpleAttr.header("Entries"), styles = emptySet()) { link(it.name, it.dri) sourceSetDependentHint(it.dri, it.sourceSets.toSet(), kind = ContentKind.SourceSetDependantHint) { contentForBrief(it) @@ -201,6 +201,7 @@ open class DefaultPageCreator( (this[T::class] as List>?) ?.groupBy { it.second.name } ?.mapValues { (_, v) -> v.toMap() } + ?.toSortedMap(String.CASE_INSENSITIVE_ORDER) .orEmpty() private inline fun GroupedTags.isNotEmptyForTag(): Boolean = @@ -377,7 +378,10 @@ open class DefaultPageCreator( if (collection.any()) { header(2, name) table(kind, extra = extra) { - collection.groupBy { it.name }.map { (elementName, elements) -> // This groupBy should probably use LocationProvider + collection + .groupBy { it.name } + .toSortedMap(compareBy(nullsLast(String.CASE_INSENSITIVE_ORDER)){it}) + .map { (elementName, elements) -> // This groupBy should probably use LocationProvider buildGroup(elements.map { it.dri }.toSet(), elements.flatMap { it.sourceSets }.toSet(), kind = kind) { link(elementName.orEmpty(), elements.first().dri, kind = kind) divergentGroup( diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt index cbae588f..9d10620e 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt @@ -172,13 +172,20 @@ open class PageContentBuilder( styles: Set