diff options
author | Szymon Świstun <sswistun@virtuslab.com> | 2020-02-05 12:07:21 +0100 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-02-12 13:33:10 +0100 |
commit | 8c534f14296a92fedc3410fb48de51836cb92859 (patch) | |
tree | 51750f4ea2cd57627e729090f11956c9319e4367 /core/src/main/kotlin | |
parent | af9697cbd2eb1a26c8a07d191ca6360d416a1666 (diff) | |
download | dokka-8c534f14296a92fedc3410fb48de51836cb92859.tar.gz dokka-8c534f14296a92fedc3410fb48de51836cb92859.tar.bz2 dokka-8c534f14296a92fedc3410fb48de51836cb92859.zip |
merger for functions
Diffstat (limited to 'core/src/main/kotlin')
-rw-r--r-- | core/src/main/kotlin/pages/PageNodes.kt | 10 | ||||
-rw-r--r-- | core/src/main/kotlin/plugability/DefaultExtensions.kt | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/transformers/pages/DefaultPageNodeMerger.kt | 45 |
3 files changed, 54 insertions, 3 deletions
diff --git a/core/src/main/kotlin/pages/PageNodes.kt b/core/src/main/kotlin/pages/PageNodes.kt index 6b67a734..244d951e 100644 --- a/core/src/main/kotlin/pages/PageNodes.kt +++ b/core/src/main/kotlin/pages/PageNodes.kt @@ -24,6 +24,7 @@ interface ContentPage: PageNode { fun modified( name: String = this.name, content: ContentNode = this.content, + dri: Set<DRI> = this.dri, embeddedResources: List<String> = this.embeddedResources, children: List<PageNode> = this.children ): ContentPage @@ -63,7 +64,6 @@ abstract class RootPageNode: PageNode { class ModulePageNode( override val name: String, override val content: ContentNode, - override val documentable: Documentable?, override val children: List<PageNode>, override val embeddedResources: List<String> = listOf() @@ -71,11 +71,12 @@ class ModulePageNode( override val dri: Set<DRI> = setOf(DRI.topLevel) override fun modified(name: String, children: List<PageNode>): ModulePageNode = - modified(name = name, content = this.content, children = children) + modified(name = name, content = this.content, dri = dri, children = children) override fun modified( name: String, content: ContentNode, + dri: Set<DRI>, embeddedResources: List<String>, children: List<PageNode> ): ModulePageNode = @@ -98,6 +99,7 @@ class PackagePageNode( override fun modified( name: String, content: ContentNode, + dri: Set<DRI>, embeddedResources: List<String>, children: List<PageNode> ): PackagePageNode = @@ -119,6 +121,7 @@ class ClasslikePageNode( override fun modified( name: String, content: ContentNode, + dri: Set<DRI>, embeddedResources: List<String>, children: List<PageNode> ): ClasslikePageNode = @@ -135,11 +138,12 @@ class MemberPageNode( override val embeddedResources: List<String> = listOf() ) : ContentPage { override fun modified(name: String, children: List<PageNode>): MemberPageNode = - modified(name = name, content = this.content, children = children) + modified(name = name, content = this.content, children = children) as MemberPageNode override fun modified( name: String, content: ContentNode, + dri: Set<DRI>, embeddedResources: List<String>, children: List<PageNode> ): MemberPageNode = diff --git a/core/src/main/kotlin/plugability/DefaultExtensions.kt b/core/src/main/kotlin/plugability/DefaultExtensions.kt index d6331b86..b7ab1af1 100644 --- a/core/src/main/kotlin/plugability/DefaultExtensions.kt +++ b/core/src/main/kotlin/plugability/DefaultExtensions.kt @@ -10,6 +10,7 @@ import org.jetbrains.dokka.transformers.descriptors.DefaultDescriptorToDocumenta import org.jetbrains.dokka.transformers.documentation.DefaultDocumentationNodeMerger import org.jetbrains.dokka.transformers.documentation.DefaultDocumentationToPageTranslator import org.jetbrains.dokka.transformers.psi.DefaultPsiToDocumentationTranslator +import org.jetbrains.dokka.transformers.pages.DefaultPageNodeMerger internal object DefaultExtensions { @@ -31,6 +32,7 @@ internal object DefaultExtensions { CoreExtensions.documentationMerger -> DefaultDocumentationNodeMerger CoreExtensions.commentsToContentConverter -> converter.get(fullContext) CoreExtensions.documentationToPageTranslator -> DefaultDocumentationToPageTranslator + CoreExtensions.pageTransformer -> DefaultPageNodeMerger CoreExtensions.renderer -> renderer.get(fullContext) CoreExtensions.locationProviderFactory -> providerFactory.get(fullContext) CoreExtensions.outputWriter -> outputWriter.get(fullContext) diff --git a/core/src/main/kotlin/transformers/pages/DefaultPageNodeMerger.kt b/core/src/main/kotlin/transformers/pages/DefaultPageNodeMerger.kt new file mode 100644 index 00000000..7cd4aba8 --- /dev/null +++ b/core/src/main/kotlin/transformers/pages/DefaultPageNodeMerger.kt @@ -0,0 +1,45 @@ +package org.jetbrains.dokka.transformers.pages + +import org.jetbrains.dokka.pages.* + +object DefaultPageNodeMerger : PageNodeTransformer { + override fun invoke(input: RootPageNode): RootPageNode = + input.modified(children = input.children.map { it.mergeChildren() }) + + fun asGroup(dci: DCI, nodes: List<ContentNode>): ContentGroup { + val n = nodes.first() + return ContentGroup(nodes, dci, n.platforms, n.style, n.extras) + } + + fun PageNode.mergeChildren(): PageNode = if (children.isNotEmpty()) { + children.groupBy { it.name } + .map { (k, v) -> + if (v.size > 1) { + v.mergePageNodes(k) + } else v.first() + } + .map { it.mergeChildren() } + .let { + modified(children = it) + } + } else this + + private fun List<PageNode>.mergePageNodes( + k: String + ): ContentPage { + val resChildren = this.flatMap { it.children }.distinct() + val contentChildren = this.filterIsInstance<ContentPage>() + val dri = contentChildren.flatMap { it.dri }.toSet() + val dci = DCI( + dri = dri, + kind = contentChildren.first().content.dci.kind + ) + return contentChildren.first() + .modified( + dri = dri, + name = k, + children = resChildren, + content = asGroup(dci, contentChildren.map { it.content }) + ) + } +}
\ No newline at end of file |