From 2ca99df241b0fe51f533c7b1d2da416677929867 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Mon, 13 Jul 2020 15:12:18 +0200 Subject: Refactor tab map creation --- .../kotlin/renderers/DefaultTabSortingStrategy.kt | 28 ++++++++++++---------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'plugins/base') diff --git a/plugins/base/src/main/kotlin/renderers/DefaultTabSortingStrategy.kt b/plugins/base/src/main/kotlin/renderers/DefaultTabSortingStrategy.kt index b40f9afe..3b849fec 100644 --- a/plugins/base/src/main/kotlin/renderers/DefaultTabSortingStrategy.kt +++ b/plugins/base/src/main/kotlin/renderers/DefaultTabSortingStrategy.kt @@ -5,20 +5,22 @@ import org.jetbrains.dokka.pages.ContentNode import org.jetbrains.dokka.pages.Kind import org.jetbrains.dokka.utilities.DokkaLogger +private val kindsOrder = listOf( + ContentKind.Classlikes, + ContentKind.Constructors, + ContentKind.Functions, + ContentKind.Properties, + ContentKind.Extensions, + ContentKind.Parameters, + ContentKind.Inheritors, + ContentKind.Source, + ContentKind.Sample, + ContentKind.Comment +) + class DefaultTabSortingStrategy : TabSortingStrategy { override fun sort(tabs: Collection): List { - val tabMap: Map> = mapOf( - ContentKind.Classlikes to mutableListOf(), - ContentKind.Constructors to mutableListOf(), - ContentKind.Functions to mutableListOf(), - ContentKind.Properties to mutableListOf(), - ContentKind.Extensions to mutableListOf(), - ContentKind.Parameters to mutableListOf(), - ContentKind.Inheritors to mutableListOf(), - ContentKind.Source to mutableListOf(), - ContentKind.Sample to mutableListOf(), - ContentKind.Comment to mutableListOf() - ) + val tabMap: Map> = kindsOrder.asSequence().map { it to mutableListOf() }.toMap() val unrecognized: MutableList = mutableListOf() tabs.forEach { tabMap[it.dci.kind]?.add(it) ?: unrecognized.add(it) @@ -26,4 +28,4 @@ class DefaultTabSortingStrategy : TabSortingStrategy { return tabMap.values.flatten() + unrecognized } -} \ No newline at end of file +} -- cgit