diff options
author | Vadim Mishenev <vad-mishenev@yandex.ru> | 2022-02-21 23:06:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-21 23:06:59 +0300 |
commit | c44bf5487bd32f90a4576859548f1db0e9355a07 (patch) | |
tree | 2954c68d9247007ecc255d397fb207b1cb2d1be1 /plugins/base/src/main/kotlin/transformers | |
parent | f54597c754c9be6afb4ea374dc959dcc9fd551ce (diff) | |
download | dokka-c44bf5487bd32f90a4576859548f1db0e9355a07.tar.gz dokka-c44bf5487bd32f90a4576859548f1db0e9355a07.tar.bz2 dokka-c44bf5487bd32f90a4576859548f1db0e9355a07.zip |
Add option to merge implicit expect-actual declarations (#2316)
* Add option to merge implicit expect-actual declarations
* Merge entries, constructors
* Fix StdLib integration test
* Add doc
Diffstat (limited to 'plugins/base/src/main/kotlin/transformers')
3 files changed, 39 insertions, 31 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 2fb70fc8..6c12c719 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/merger/SameMethodNamePageMergerStrategy.kt @@ -23,7 +23,7 @@ class SameMethodNamePageMergerStrategy(val logger: DokkaLogger) : PageMergerStra children = members.flatMap { it.children }.distinct(), content = squashDivergentInstances(members).withSourceSets(members.allSourceSets()), embeddedResources = members.flatMap { it.embeddedResources }.distinct(), - documentable = null + documentables = members.flatMap { it.documentables } ) return (pages - members) + listOf(merged) @@ -37,9 +37,9 @@ class SameMethodNamePageMergerStrategy(val logger: DokkaLogger) : PageMergerStra .reduce { acc, node -> acc.mapTransform<ContentDivergentGroup, ContentNode> { g -> g.copy(children = (g.children + - (node.dfs { it is ContentDivergentGroup && it.groupID == g.groupID } as? ContentDivergentGroup) - ?.children?.single() - ).filterNotNull() + ((node.dfs { it is ContentDivergentGroup && it.groupID == g.groupID } as? ContentDivergentGroup) + ?.children ?: emptyList()) + ) ) } } diff --git a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt index 3ff7a77d..db133bb8 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/samples/SamplesTransformer.kt @@ -35,14 +35,18 @@ abstract class SamplesTransformer(val context: DokkaContext) : PageTransformer { "<script src=\"https://unpkg.com/kotlin-playground@1\"></script>" return input.transformContentPagesTree { page -> - page.documentable?.documentation?.entries?.fold(page) { acc, entry -> - entry.value.children.filterIsInstance<Sample>().fold(acc) { acc, sample -> + val samples = (page as? WithDocumentables)?.documentables?.flatMap { + it.documentation.entries.flatMap { entry -> + entry.value.children.filterIsInstance<Sample>().map { entry.key to it } + } + } + + samples?.fold(page as ContentPage) { acc, (sampleSourceSet, sample) -> acc.modified( - content = acc.content.addSample(page, entry.key, sample.name, analysis), + content = acc.content.addSample(page, sampleSourceSet, sample.name, analysis), embeddedResources = acc.embeddedResources + kotlinPlaygroundScript ) - } - } ?: page + } ?: page } } 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 f66ff222..93305055 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt @@ -1,15 +1,15 @@ package org.jetbrains.dokka.base.transformers.pages.sourcelinks -import com.intellij.psi.PsiElement import com.intellij.psi.PsiDocumentManager +import com.intellij.psi.PsiElement import org.jetbrains.dokka.DokkaConfiguration -import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder -import org.jetbrains.dokka.model.DocumentableSource import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet import org.jetbrains.dokka.analysis.DescriptorDocumentableSource import org.jetbrains.dokka.analysis.PsiDocumentableSource import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.resolvers.anchors.SymbolAnchorHint +import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder +import org.jetbrains.dokka.model.DocumentableSource import org.jetbrains.dokka.model.WithSources import org.jetbrains.dokka.model.toDisplaySourceSets import org.jetbrains.dokka.pages.* @@ -32,8 +32,9 @@ class SourceLinksTransformer(val context: DokkaContext) : PageTransformer { override fun invoke(input: RootPageNode) = input.transformContentPagesTree { node -> - when (val documentable = node.documentable) { - is WithSources -> resolveSources(documentable) + when (node) { + is WithDocumentables -> + node.documentables.filterIsInstance<WithSources>().flatMap { resolveSources(it) } .takeIf { it.isNotEmpty() } ?.let { node.addSourcesContent(it) } ?: node @@ -65,23 +66,26 @@ class SourceLinksTransformer(val context: DokkaContext) : PageTransformer { private fun PageContentBuilder.buildSourcesContent( node: ContentPage, sources: List<Pair<DokkaSourceSet, String>> - ) = contentFor( - node.dri.first(), - node.documentable!!.sourceSets.toSet() - ) { - header(2, "Sources", kind = ContentKind.Source) - +ContentTable( - header = emptyList(), - children = sources.map { - buildGroup(node.dri, setOf(it.first), kind = ContentKind.Source, extra = mainExtra + SymbolAnchorHint(it.second, ContentKind.Source)) { - link("${it.first.displayName} source", it.second) - } - }, - dci = DCI(node.dri, ContentKind.Source), - sourceSets = node.documentable!!.sourceSets.toDisplaySourceSets(), - style = emptySet(), - extra = mainExtra + SimpleAttr.header("Sources") - ) + ): ContentGroup { + val documentables = (node as? WithDocumentables)?.documentables.orEmpty() + return contentFor( + node.dri, + documentables.flatMap { it.sourceSets }.toSet() + ) { + header(2, "Sources", kind = ContentKind.Source) + +ContentTable( + header = emptyList(), + children = sources.map { + buildGroup(node.dri, setOf(it.first), kind = ContentKind.Source, extra = mainExtra + SymbolAnchorHint(it.second, ContentKind.Source)) { + link("${it.first.displayName} source", it.second) + } + }, + dci = DCI(node.dri, ContentKind.Source), + sourceSets = documentables.flatMap { it.sourceSets }.toDisplaySourceSets(), + style = emptySet(), + extra = mainExtra + SimpleAttr.header("Sources") + ) + } } private fun DocumentableSource.toLink(sourceLink: SourceLink): String { |