Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to utilize Comparators instead of String keys #2489

Merged
merged 2 commits into from May 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -4,6 +4,7 @@ import org.jetbrains.dokka.base.renderers.sourceSets
import org.jetbrains.dokka.base.transformers.documentables.deprecatedAnnotation
import org.jetbrains.dokka.base.transformers.documentables.isDeprecated
import org.jetbrains.dokka.base.transformers.documentables.isException
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.BooleanValue
import org.jetbrains.dokka.model.Documentable
import org.jetbrains.dokka.pages.*
Expand Down Expand Up @@ -91,9 +92,7 @@ object IndexGenerator : PageTransformer {
val keys = elements.keys.sortedBy { it }
val sortedElements = elements.entries.sortedBy { (a, _) -> a }

val indexNodeComparator = compareBy<NavigableJavadocNode> { it.getId().toLowerCase() }
.thenBy { it.getFullComparatorKey() }

val indexNodeComparator = getIndexNodeComparator()
val indexPages = sortedElements.mapIndexed { idx, (_, set) ->
IndexPage(
id = idx + 1,
Expand All @@ -105,15 +104,14 @@ object IndexGenerator : PageTransformer {
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()
private fun getIndexNodeComparator(): Comparator<NavigableJavadocNode> {
val driComparator = compareBy<DRI> { it.packageName }
.thenBy { it.classNames }
.thenBy { it.callable?.name.orEmpty() }
.thenBy { it.callable?.signature().orEmpty() }

"$packageName/$className/$callableName/$parameters"
}
return compareBy<NavigableJavadocNode> { it.getId().toLowerCase() }
.thenBy(driComparator) { it.getDRI() }
}
}

Expand Down