From ac2c1adf18289acbff8a79e8cbabe58e00f30f63 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Thu, 4 Mar 2021 17:23:30 +0100 Subject: Fix clashing properties and external links ordering (#1765) --- .../resolvers/local/DefaultLocationProvider.kt | 32 ++++++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'plugins/base/src/main/kotlin/resolvers') diff --git a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt index c956b308..87683414 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt @@ -1,7 +1,11 @@ package org.jetbrains.dokka.base.resolvers.local import org.jetbrains.dokka.base.DokkaBase +import org.jetbrains.dokka.base.resolvers.external.DefaultExternalLocationProvider +import org.jetbrains.dokka.base.resolvers.external.Dokka010ExternalLocationProvider import org.jetbrains.dokka.base.resolvers.external.ExternalLocationProvider +import org.jetbrains.dokka.base.resolvers.external.javadoc.AndroidExternalLocationProvider +import org.jetbrains.dokka.base.resolvers.external.javadoc.JavadocExternalLocationProvider import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation import org.jetbrains.dokka.base.resolvers.shared.PackageList import org.jetbrains.dokka.links.DRI @@ -36,12 +40,16 @@ abstract class DefaultLocationProvider( } .toMap() - protected val packagesIndex: Map = externalLocationProviders - .flatMap { (extDocInfo, externalLocationProvider) -> - extDocInfo.packageList.packages.map { packageName -> packageName to externalLocationProvider } - } - .toMap() - .filterKeys(String::isNotBlank) + protected val packagesIndex: Map = + externalLocationProviders + .flatMap { (extDocInfo, externalLocationProvider) -> + extDocInfo.packageList.packages.map { packageName -> packageName to externalLocationProvider } + }.groupBy { it.first }.mapValues { (_, lst) -> + lst.map { it.second } + .sortedWith(compareBy(nullsLast(ExternalLocationProviderOrdering)) { it }) + .firstOrNull() + } + .filterKeys(String::isNotBlank) protected val locationsIndex: Map = externalLocationProviders @@ -56,4 +64,16 @@ abstract class DefaultLocationProvider( ?: locationsIndex[dri.toString()]?.resolve(dri) ?: externalLocationProviders.values.mapNotNull { it?.resolve(dri) }.firstOrNull() + private object ExternalLocationProviderOrdering : Comparator { + private val desiredOrdering = listOf( + DefaultExternalLocationProvider::class, + Dokka010ExternalLocationProvider::class, + AndroidExternalLocationProvider::class, + JavadocExternalLocationProvider::class + ) + + override fun compare(o1: ExternalLocationProvider, o2: ExternalLocationProvider): Int = + desiredOrdering.indexOf(o1::class).compareTo(desiredOrdering.indexOf(o2::class)) + } + } -- cgit