aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/transformers/pages/merger
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src/main/kotlin/transformers/pages/merger')
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt3
-rw-r--r--plugins/base/src/main/kotlin/transformers/pages/merger/SourceSetMergingPageTransformer.kt36
2 files changed, 38 insertions, 1 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt b/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt
index d81f131b..4eacf359 100644
--- a/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt
+++ b/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt
@@ -1,5 +1,6 @@
package org.jetbrains.dokka.base.transformers.pages.merger
+import org.jetbrains.dokka.model.dfs
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.utilities.DokkaLogger
@@ -37,4 +38,4 @@ class SameMethodNamePageMergerStrategy(val logger: DokkaLogger) : PageMergerStra
)
}
}
-} \ No newline at end of file
+}
diff --git a/plugins/base/src/main/kotlin/transformers/pages/merger/SourceSetMergingPageTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/merger/SourceSetMergingPageTransformer.kt
new file mode 100644
index 00000000..aaf4b5c3
--- /dev/null
+++ b/plugins/base/src/main/kotlin/transformers/pages/merger/SourceSetMergingPageTransformer.kt
@@ -0,0 +1,36 @@
+package org.jetbrains.dokka.base.transformers.pages.merger
+
+import org.jetbrains.dokka.Platform
+import org.jetbrains.dokka.pages.*
+import org.jetbrains.dokka.plugability.DokkaContext
+import org.jetbrains.dokka.transformers.pages.PageTransformer
+
+class SourceSetMergingPageTransformer(context: DokkaContext) : PageTransformer {
+
+ private val mergedSourceSets = context.configuration.sourceSets.toContentSourceSets()
+ .associateBy { sourceSet -> sourceSet.key }
+
+ override fun invoke(input: RootPageNode): RootPageNode {
+ return input.transformContentPagesTree { contentPage ->
+ val content: ContentNode = contentPage.content
+ val newContent = transformWithMergedSourceSets(content)
+ contentPage.modified(content = newContent)
+ }
+ }
+
+ private fun transformWithMergedSourceSets(
+ contentNode: ContentNode
+ ): ContentNode {
+ val mergedSourceSets = contentNode.sourceSets.map { mergedSourceSets.getValue(it.key) }.toSet()
+ return when (contentNode) {
+ is ContentComposite -> contentNode
+ .transformChildren(::transformWithMergedSourceSets)
+ .withSourceSets(mergedSourceSets)
+ else -> contentNode.withSourceSets(mergedSourceSets.toSet())
+ }
+ }
+}
+
+private val ContentSourceSet.key get() = SourceSetMergingKey(displayName, analysisPlatform)
+
+private data class SourceSetMergingKey(private val displayName: String, private val platform: Platform)