@@ -18,7 +18,6 @@ import org.jetbrains.dokka.transformers.pages.PageTransformer
1818import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
1919import org.jetbrains.kotlin.resolve.source.getPsi
2020import org.jetbrains.kotlin.utils.addToStdlib.cast
21- import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
2221import java.io.File
2322
2423class SourceLinksTransformer (val context : DokkaContext ) : PageTransformer {
@@ -39,7 +38,14 @@ class SourceLinksTransformer(val context: DokkaContext) : PageTransformer {
3938 is WithDocumentables -> {
4039 val sources = node.documentables
4140 .filterIsInstance<WithSources >()
42- .associate { (it as Documentable ).dri to resolveSources(sourceLinks, it) }
41+ .fold(mutableMapOf<DRI , List <Pair <DokkaSourceSet , String >>>()) { acc, documentable ->
42+ val dri = (documentable as Documentable ).dri
43+ acc.compute(dri) { _, v ->
44+ val sources = resolveSources(sourceLinks, documentable)
45+ v?.plus(sources) ? : sources
46+ }
47+ acc
48+ }
4349 if (sources.isNotEmpty())
4450 node.modified(content = transformContent(node.content, sources))
4551 else
@@ -102,15 +108,18 @@ class SourceLinksTransformer(val context: DokkaContext) : PageTransformer {
102108 ): ContentNode =
103109 contentNode.signatureGroupOrNull()?.let { sg ->
104110 sources[sg.dci.dri.singleOrNull()]?.let { sourceLinks ->
105- sourceLinks.filter { it.first.sourceSetID in sg.sourceSets.sourceSetIDs }.ifNotEmpty {
106- sg.copy(children = sg.children + sourceLinks.map {
107- buildContentLink(
108- sg.dci.dri.first(),
109- it.first,
110- it.second
111- )
112- })
113- }
111+ sourceLinks
112+ .filter { it.first.sourceSetID in sg.sourceSets.sourceSetIDs }
113+ .takeIf { it.isNotEmpty() }
114+ ?.let { filteredSourcesLinks ->
115+ sg.copy(children = sg.children + filteredSourcesLinks.map {
116+ buildContentLink(
117+ sg.dci.dri.first(),
118+ it.first,
119+ it.second
120+ )
121+ })
122+ }
114123 }
115124 } ? : when (contentNode) {
116125 is ContentComposite -> contentNode.transformChildren { transformContent(it, sources) }
0 commit comments