aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/transformers/pages/sourcelinks
diff options
context:
space:
mode:
authorVadim Mishenev <vad-mishenev@yandex.ru>2022-09-26 17:41:04 +0300
committerGitHub <noreply@github.com>2022-09-26 17:41:04 +0300
commit9207f8f032fac8036c9aa5aa65633341a14efa62 (patch)
tree68f7c6d7d9e5a7bed4e2e28e6ff2b28c802cbb51 /plugins/base/src/main/kotlin/transformers/pages/sourcelinks
parentee8e73012c1a7f86783920181590489d740af839 (diff)
downloaddokka-9207f8f032fac8036c9aa5aa65633341a14efa62.tar.gz
dokka-9207f8f032fac8036c9aa5aa65633341a14efa62.tar.bz2
dokka-9207f8f032fac8036c9aa5aa65633341a14efa62.zip
Fix source links in case of dri clashing (#2676)
Diffstat (limited to 'plugins/base/src/main/kotlin/transformers/pages/sourcelinks')
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt31
1 files changed, 20 insertions, 11 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
index 385cd335..0bb4a732 100644
--- a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
+++ b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt
@@ -18,7 +18,6 @@ import org.jetbrains.dokka.transformers.pages.PageTransformer
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
import org.jetbrains.kotlin.resolve.source.getPsi
import org.jetbrains.kotlin.utils.addToStdlib.cast
-import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
import java.io.File
class SourceLinksTransformer(val context: DokkaContext) : PageTransformer {
@@ -39,7 +38,14 @@ class SourceLinksTransformer(val context: DokkaContext) : PageTransformer {
is WithDocumentables -> {
val sources = node.documentables
.filterIsInstance<WithSources>()
- .associate { (it as Documentable).dri to resolveSources(sourceLinks, it) }
+ .fold(mutableMapOf<DRI, List<Pair<DokkaSourceSet, String>>>()) { acc, documentable ->
+ val dri = (documentable as Documentable).dri
+ acc.compute(dri) { _, v ->
+ val sources = resolveSources(sourceLinks, documentable)
+ v?.plus(sources) ?: sources
+ }
+ acc
+ }
if (sources.isNotEmpty())
node.modified(content = transformContent(node.content, sources))
else
@@ -102,15 +108,18 @@ class SourceLinksTransformer(val context: DokkaContext) : PageTransformer {
): ContentNode =
contentNode.signatureGroupOrNull()?.let { sg ->
sources[sg.dci.dri.singleOrNull()]?.let { sourceLinks ->
- sourceLinks.filter { it.first.sourceSetID in sg.sourceSets.sourceSetIDs }.ifNotEmpty {
- sg.copy(children = sg.children + sourceLinks.map {
- buildContentLink(
- sg.dci.dri.first(),
- it.first,
- it.second
- )
- })
- }
+ sourceLinks
+ .filter { it.first.sourceSetID in sg.sourceSets.sourceSetIDs }
+ .takeIf { it.isNotEmpty() }
+ ?.let { filteredSourcesLinks ->
+ sg.copy(children = sg.children + filteredSourcesLinks.map {
+ buildContentLink(
+ sg.dci.dri.first(),
+ it.first,
+ it.second
+ )
+ })
+ }
}
} ?: when (contentNode) {
is ContentComposite -> contentNode.transformChildren { transformContent(it, sources) }