From 88d36234b710f2ef50db9d874e25fd2378f430ac Mon Sep 17 00:00:00 2001 From: Ignat Beresnev Date: Thu, 5 May 2022 20:16:05 +0300 Subject: Make javadoc pages generation deterministic (#2479) * Make javadoc pages generation deterministic * Rename `genericQuery` to avoid confusion with Generics --- .../dokka/javadoc/pages/JavadocPageNodes.kt | 10 ++++---- .../dokka/javadoc/pages/htmlPreprocessors.kt | 27 +++++++++++++++++++--- .../JavadocContentToTemplateMapTranslator.kt | 2 +- 3 files changed, 31 insertions(+), 8 deletions(-) (limited to 'plugins/javadoc/src/main/kotlin/org/jetbrains') diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/JavadocPageNodes.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/JavadocPageNodes.kt index 6c7691cd..cafc6c3e 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/JavadocPageNodes.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/pages/JavadocPageNodes.kt @@ -317,17 +317,19 @@ class DeprecatedNode(val name: String, val address: DRI, val description: List a } - return input.modified(children = input.children + sortedElements.mapIndexed { i, (_, set) -> - IndexPage(i + 1, set.sortedBy { it.getId().toLowerCase() }, keys, input.sourceSets()) - }) + + val indexNodeComparator = compareBy { it.getId().toLowerCase() } + .thenBy { it.getFullComparatorKey() } + + val indexPages = sortedElements.mapIndexed { idx, (_, set) -> + IndexPage( + id = idx + 1, + elements = set.sortedWith(indexNodeComparator), + keys = keys, + sourceSet = input.sourceSets() + ) + } + return input.modified(children = input.children + indexPages) + } + + private fun NavigableJavadocNode.getFullComparatorKey(): String { + return getDRI().let { dri -> + val packageName = dri.packageName.orEmpty() + val className = dri.classNames.orEmpty() + val callableName = dri.callable?.name.orEmpty() + val parameters = dri.callable?.signature().orEmpty() + + "$packageName/$className/$callableName/$parameters" + } } } diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt index a6eda405..45fa3f2e 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToTemplateMapTranslator.kt @@ -81,7 +81,7 @@ internal class JavadocContentToTemplateMapTranslator( "id" to node.name, "title" to "Deprecated", "kind" to "deprecated", - "sections" to node.elements.toList().sortedBy { (section, _) -> section.priority } + "sections" to node.elements.toList().sortedBy { (section, _) -> section.getPosition() } .map { (s, e) -> templateMapForDeprecatedPageSection(s, e) } ) -- cgit