From 2372302f4bc3b4bf49beb0d477eebdd9ac99a78f Mon Sep 17 00:00:00 2001 From: Goooler Date: Tue, 15 Feb 2022 17:38:10 +0800 Subject: Convert interfaces to functional (#2360) --- .../DefaultExternalLocationProviderFactory.kt | 22 ++++++------- .../resolvers/external/ExternalLocationProvider.kt | 2 +- .../external/ExternalLocationProviderFactory.kt | 2 +- .../JavadocExternalLocationProviderFactory.kt | 37 ++++++++++------------ 4 files changed, 29 insertions(+), 34 deletions(-) (limited to 'plugins/base/src/main/kotlin/resolvers/external') diff --git a/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProviderFactory.kt b/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProviderFactory.kt index 63db27be..8455320f 100644 --- a/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProviderFactory.kt +++ b/plugins/base/src/main/kotlin/resolvers/external/DefaultExternalLocationProviderFactory.kt @@ -1,21 +1,19 @@ package org.jetbrains.dokka.base.resolvers.external -import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat import org.jetbrains.dokka.plugability.DokkaContext class DefaultExternalLocationProviderFactory(val context: DokkaContext) : ExternalLocationProviderFactory by ExternalLocationProviderFactoryWithCache( - object : ExternalLocationProviderFactory { - override fun getExternalLocationProvider(doc: ExternalDocumentation): ExternalLocationProvider? = - when (doc.packageList.linkFormat) { - RecognizedLinkFormat.KotlinWebsite, - RecognizedLinkFormat.KotlinWebsiteHtml, - RecognizedLinkFormat.DokkaOldHtml -> Dokka010ExternalLocationProvider(doc, ".html", context) - RecognizedLinkFormat.DokkaHtml -> DefaultExternalLocationProvider(doc, ".html", context) - RecognizedLinkFormat.DokkaGFM, - RecognizedLinkFormat.DokkaJekyll -> DefaultExternalLocationProvider(doc, ".md", context) - else -> null - } + { doc -> + when (doc.packageList.linkFormat) { + RecognizedLinkFormat.KotlinWebsite, + RecognizedLinkFormat.KotlinWebsiteHtml, + RecognizedLinkFormat.DokkaOldHtml -> Dokka010ExternalLocationProvider(doc, ".html", context) + RecognizedLinkFormat.DokkaHtml -> DefaultExternalLocationProvider(doc, ".html", context) + RecognizedLinkFormat.DokkaGFM, + RecognizedLinkFormat.DokkaJekyll -> DefaultExternalLocationProvider(doc, ".md", context) + else -> null + } } ) diff --git a/plugins/base/src/main/kotlin/resolvers/external/ExternalLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/external/ExternalLocationProvider.kt index 11940abc..8465d41f 100644 --- a/plugins/base/src/main/kotlin/resolvers/external/ExternalLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/external/ExternalLocationProvider.kt @@ -5,7 +5,7 @@ import org.jetbrains.dokka.links.DRI /** * Provides the path to the page documenting a [DRI] in an external documentation source */ -interface ExternalLocationProvider { +fun interface ExternalLocationProvider { /** * @return Path to the page containing the [dri] or null if the path cannot be created * (eg. when the package-list does not contain [dri]'s package) diff --git a/plugins/base/src/main/kotlin/resolvers/external/ExternalLocationProviderFactory.kt b/plugins/base/src/main/kotlin/resolvers/external/ExternalLocationProviderFactory.kt index c7328765..c11a79ba 100644 --- a/plugins/base/src/main/kotlin/resolvers/external/ExternalLocationProviderFactory.kt +++ b/plugins/base/src/main/kotlin/resolvers/external/ExternalLocationProviderFactory.kt @@ -2,6 +2,6 @@ package org.jetbrains.dokka.base.resolvers.external import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation -interface ExternalLocationProviderFactory { +fun interface ExternalLocationProviderFactory { fun getExternalLocationProvider(doc: ExternalDocumentation): ExternalLocationProvider? } diff --git a/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProviderFactory.kt b/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProviderFactory.kt index 102d118a..c9ebad81 100644 --- a/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProviderFactory.kt +++ b/plugins/base/src/main/kotlin/resolvers/external/javadoc/JavadocExternalLocationProviderFactory.kt @@ -3,32 +3,29 @@ package org.jetbrains.dokka.base.resolvers.external.javadoc import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.androidSdk import org.jetbrains.dokka.androidX -import org.jetbrains.dokka.base.resolvers.external.ExternalLocationProvider import org.jetbrains.dokka.base.resolvers.external.ExternalLocationProviderFactory import org.jetbrains.dokka.base.resolvers.external.ExternalLocationProviderFactoryWithCache -import org.jetbrains.dokka.base.resolvers.shared.ExternalDocumentation import org.jetbrains.dokka.base.resolvers.shared.RecognizedLinkFormat import org.jetbrains.dokka.plugability.DokkaContext class JavadocExternalLocationProviderFactory(val context: DokkaContext) : ExternalLocationProviderFactory by ExternalLocationProviderFactoryWithCache( - object : ExternalLocationProviderFactory { - override fun getExternalLocationProvider(doc: ExternalDocumentation): ExternalLocationProvider? = - when (doc.packageList.url) { - DokkaConfiguration.ExternalDocumentationLink.androidX().packageListUrl, - DokkaConfiguration.ExternalDocumentationLink.androidSdk().packageListUrl -> - AndroidExternalLocationProvider(doc, context) - else -> - when (doc.packageList.linkFormat) { - RecognizedLinkFormat.Javadoc1 -> - JavadocExternalLocationProvider(doc, "()", ", ", context) // Covers JDK 1 - 7 - RecognizedLinkFormat.Javadoc8 -> - JavadocExternalLocationProvider(doc, "--", "-", context) // Covers JDK 8 - 9 - RecognizedLinkFormat.Javadoc10, - RecognizedLinkFormat.DokkaJavadoc -> - JavadocExternalLocationProvider(doc, "()", ",", context) // Covers JDK 10 - else -> null - } - } + { doc -> + when (doc.packageList.url) { + DokkaConfiguration.ExternalDocumentationLink.androidX().packageListUrl, + DokkaConfiguration.ExternalDocumentationLink.androidSdk().packageListUrl -> + AndroidExternalLocationProvider(doc, context) + else -> + when (doc.packageList.linkFormat) { + RecognizedLinkFormat.Javadoc1 -> + JavadocExternalLocationProvider(doc, "()", ", ", context) // Covers JDK 1 - 7 + RecognizedLinkFormat.Javadoc8 -> + JavadocExternalLocationProvider(doc, "--", "-", context) // Covers JDK 8 - 9 + RecognizedLinkFormat.Javadoc10, + RecognizedLinkFormat.DokkaJavadoc -> + JavadocExternalLocationProvider(doc, "()", ",", context) // Covers JDK 10 + else -> null + } + } } ) -- cgit