From 493951f487910a1306a4129b7e8144e679c0213c Mon Sep 17 00:00:00 2001 From: Błażej Kardyś Date: Thu, 7 Nov 2019 08:21:43 +0100 Subject: Moving platform merging to documentationNodes --- core/src/main/kotlin/DokkaDescriptorVisitor.kt | 56 +++++++++++----- core/src/main/kotlin/DokkaGenerator.kt | 33 +++++---- core/src/main/kotlin/Model/DocumentationNode.kt | 51 ++++++++------ .../Model/transformers/ActualExpectedMerger.kt | 57 ---------------- .../transformers/DocumentationNodeTransformer.kt | 1 + .../Model/transformers/DocumentationNodesMerger.kt | 78 ++++++++++++++++++++++ .../kotlin/pages/MarkdownToContentConverter.kt | 38 +++-------- .../DefaultDocumentationToPageTransformer.kt | 27 ++++---- .../transformers/DocumentationToPageTransformer.kt | 2 +- .../kotlin/transformers/TopDownPageNodeMerger.kt | 50 -------------- 10 files changed, 189 insertions(+), 204 deletions(-) delete mode 100644 core/src/main/kotlin/Model/transformers/ActualExpectedMerger.kt create mode 100644 core/src/main/kotlin/Model/transformers/DocumentationNodesMerger.kt delete mode 100644 core/src/main/kotlin/transformers/TopDownPageNodeMerger.kt diff --git a/core/src/main/kotlin/DokkaDescriptorVisitor.kt b/core/src/main/kotlin/DokkaDescriptorVisitor.kt index c98c63dd..63d3ea20 100644 --- a/core/src/main/kotlin/DokkaDescriptorVisitor.kt +++ b/core/src/main/kotlin/DokkaDescriptorVisitor.kt @@ -6,14 +6,20 @@ import org.jetbrains.dokka.links.Callable import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.withClass import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.FAKE_OVERRIDE +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies +import org.jetbrains.kotlin.idea.kdoc.findKDoc +import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink +import org.jetbrains.kotlin.kdoc.psi.impl.KDocLink +import org.jetbrains.kotlin.kdoc.psi.impl.KDocName import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.MemberScope -import org.jetbrains.kotlin.idea.kdoc.findKDoc -import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.FAKE_OVERRIDE -import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED -object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies, DRI>() { +class DokkaDescriptorVisitor( + val platform: List, + private val resolutionFacade: DokkaResolutionFacade +) : DeclarationDescriptorVisitorEmptyBodies, DRI>() { override fun visitDeclarationDescriptor(descriptor: DeclarationDescriptor, parent: DRI): Nothing { throw IllegalStateException("${javaClass.simpleName} should never enter ${descriptor.javaClass.simpleName}") } @@ -35,6 +41,9 @@ object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies parameter(index, desc, dri) }, - listOfNotNull(descriptor.findKDoc()), - listOf(descriptor) + descriptor.takeIf { it.isExpect }?.resolveDescriptorData(), + listOfNotNull(descriptor.takeUnless { it.isExpect }?.resolveDescriptorData()) ) } @@ -77,8 +86,8 @@ object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies", null, descriptor.valueParameters.mapIndexed { index, desc -> parameter(index, desc, dri) }, - listOfNotNull(descriptor.findKDoc()), - listOf(descriptor) + descriptor.takeIf { it.isExpect }?.resolveDescriptorData(), + listOfNotNull(descriptor.takeUnless { it.isExpect }?.resolveDescriptorData()) ) } @@ -88,20 +97,18 @@ object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies = getContributedDescriptors(DescriptorKindFilter.FUNCTIONS) { true } @@ -118,4 +125,19 @@ object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies() .map { visitClassDescriptor(it, parent) } + + private fun T.resolveDescriptorData(): Descriptor { + val doc = findKDoc() + val links = doc?.children?.filter { it is KDocLink }?.flatMap { link -> + val destination = link.children.first { it is KDocName }.text + resolveKDocLink( + resolutionFacade.resolveSession.bindingContext, + resolutionFacade, + this, + null, + destination.split('.') + ).map { Pair(destination, DRI.from(it)) } + }?.toMap() ?: emptyMap() + return Descriptor(this, doc, links, platform) + } } diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt index 69c6fa41..f5e8b832 100644 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -1,18 +1,15 @@ package org.jetbrains.dokka import org.jetbrains.dokka.Model.Module +import org.jetbrains.dokka.Model.transformers.DocumentationNodesMerger import org.jetbrains.dokka.Utilities.genericPretty -import org.jetbrains.dokka.Model.transformers.ActualExpectedMerger import org.jetbrains.dokka.Utilities.pretty import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.pages.MarkdownToContentConverter -import org.jetbrains.dokka.pages.ModulePageNode -import org.jetbrains.dokka.pages.PageNode import org.jetbrains.dokka.renderers.FileWriter import org.jetbrains.dokka.renderers.HtmlRenderer import org.jetbrains.dokka.resolvers.DefaultLocationProvider import org.jetbrains.dokka.transformers.DefaultDocumentationToPageTransformer -import org.jetbrains.dokka.transformers.TopDownPageNodeMerger import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector @@ -41,23 +38,28 @@ class DokkaGenerator( val environment = createCoreEnvironment() val (facade, _) = createResolutionFacade(environment) - val markdownConverter = MarkdownToContentConverter(facade, logger) - - val module = environment.getSourceFiles().asSequence() + environment.getSourceFiles().asSequence() .map { it.packageFqName } .distinct() .mapNotNull { facade.resolveSession.getPackageFragment(it) } - .map { DokkaDescriptorVisitor.visitPackageFragmentDescriptor(it, DRI.topLevel) } + .map { + DokkaDescriptorVisitor(pass.targets, facade).visitPackageFragmentDescriptor( + it, + DRI.topLevel + ) + } .toList() .let { Module(it) } - .let { ActualExpectedMerger(it) } + .let { DocumentationNodesMerger(it) } .also { println("${pass.analysisPlatform}:\n${it.pretty()}\n\n") } - - DefaultDocumentationToPageTransformer(markdownConverter, logger).transform(pass, module) } + }.let { + val markdownConverter = MarkdownToContentConverter(logger) + it.forEach { it.genericPretty().also(::nierzigoj) } + DefaultDocumentationToPageTransformer(markdownConverter, logger).transform(DocumentationNodesMerger(it)) } - .merge() .also { + it.genericPretty().also(::nierzigoj) HtmlRenderer( FileWriter(configuration.outputDir, ""), DefaultLocationProvider(it, configuration, ".${configuration.format}") @@ -66,12 +68,7 @@ class DokkaGenerator( } } -private fun Iterable.merge(): PageNode { - this.forEach { it.genericPretty().also(::println) } - return TopDownPageNodeMerger().mergeModules(this).also { - it.genericPretty().also(::println) - } -} +private fun nierzigoj(niczym: String) {} private class DokkaMessageCollector(private val logger: DokkaLogger) : MessageCollector { override fun clear() { diff --git a/core/src/main/kotlin/Model/DocumentationNode.kt b/core/src/main/kotlin/Model/DocumentationNode.kt index 99764fac..7efe6818 100644 --- a/core/src/main/kotlin/Model/DocumentationNode.kt +++ b/core/src/main/kotlin/Model/DocumentationNode.kt @@ -5,10 +5,7 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag class Module(val packages: List) : DocumentationNode() { - override val docTags: List = emptyList() - override val dri: DRI = DRI.topLevel - override val children: List = packages } @@ -19,8 +16,6 @@ class Package( override val classes: List ) : ScopeNode() { val name = dri.packageName.orEmpty() - - override val docTags: List = emptyList() } class Class( @@ -30,8 +25,8 @@ class Class( override val functions: List, override val properties: List, override val classes: List, - override val docTags: List, - override val descriptors: List + override val expectDescriptor: Descriptor?, + override val actualDescriptors: List> ) : ScopeNode() class Function( @@ -39,8 +34,8 @@ class Function( val name: String, override val receiver: Parameter?, val parameters: List, - override val docTags: List, - override val descriptors: List + override val expectDescriptor: Descriptor?, + override val actualDescriptors: List> ) : CallableNode() { override val children: List get() = listOfNotNull(receiver) + parameters @@ -50,8 +45,8 @@ class Property( override val dri: DRI, val name: String, override val receiver: Parameter?, - override val docTags: List, - override val descriptors: List + override val expectDescriptor: Descriptor?, + override val actualDescriptors: List> ) : CallableNode() { override val children: List get() = listOfNotNull(receiver) @@ -61,35 +56,51 @@ class Property( class Parameter( override val dri: DRI, val name: String?, - override val docTags: List, - override val descriptors: List + override val actualDescriptors: List> ) : DocumentationNode() { override val children: List> get() = emptyList() } -abstract class DocumentationNode { - open val descriptors: List = emptyList() +class Descriptor( + val descriptor: T, + val docTag: KDocTag?, + val links: Map, + val passes: List +) : DeclarationDescriptor by descriptor { + + override fun equals(other: Any?): Boolean = + other is Descriptor<*> && ( + descriptor.toString() == other.descriptor.toString() && + docTag?.text == other.docTag?.text && + links == other.links) + + override fun hashCode(): Int = + listOf(descriptor.toString(), docTag?.text, links).hashCode() +} - abstract val docTags: List // TODO: replace in the future with more robust doc-comment model +abstract class DocumentationNode { + open val expectDescriptor: Descriptor? = null + open val actualDescriptors: List> = emptyList() + val descriptors by lazy { listOfNotNull(expectDescriptor) + actualDescriptors } abstract val dri: DRI abstract val children: List> override fun toString(): String { - return "${javaClass.simpleName}($dri)" + briefDocstring.takeIf { it.isNotBlank() }?.let { " [$it]"}.orEmpty() + return "${javaClass.simpleName}($dri)" + briefDocstring.takeIf { it.isNotBlank() }?.let { " [$it]" }.orEmpty() } override fun equals(other: Any?) = other is DocumentationNode<*> && this.dri == other.dri override fun hashCode() = dri.hashCode() - val rawDocstrings: List - get() = docTags.map(KDocTag::getContent) + val commentsData: List>> + get() = descriptors.mapNotNull { it.docTag?.let { tag -> Pair(tag.getContent(), it.links) } } val briefDocstring: String - get() = rawDocstrings.firstOrNull().orEmpty().shorten(40) + get() = descriptors.firstOrNull()?.docTag?.getContent().orEmpty().shorten(40) } abstract class ScopeNode : DocumentationNode() { diff --git a/core/src/main/kotlin/Model/transformers/ActualExpectedMerger.kt b/core/src/main/kotlin/Model/transformers/ActualExpectedMerger.kt deleted file mode 100644 index 171b41d0..00000000 --- a/core/src/main/kotlin/Model/transformers/ActualExpectedMerger.kt +++ /dev/null @@ -1,57 +0,0 @@ -package org.jetbrains.dokka.Model.transformers - -import org.jetbrains.dokka.Model.* -import org.jetbrains.dokka.Model.Function - -internal object ActualExpectedMerger : DocumentationNodeTransformer { - override fun invoke(original: Module) = Module( - original.packages.map { mergePackageContent(it) } - ) -} - -private fun mergePackageContent(original: Package) = Package( - original.dri, - merge(original.functions, Function::mergeWith), - merge(original.properties, Property::mergeWith), - merge(original.classes, Class::mergeWith) -) - -private fun > merge(elements: List, reducer: (T, T) -> T): List = - elements.groupingBy { it.dri } - .reduce { _, left, right -> reducer(left, right)} - .values.toList() - -fun Function.mergeWith(other: Function) = Function( - dri, - name, - if (receiver != null && other.receiver != null) receiver.mergeWith(other.receiver) else null, - merge(parameters + other.parameters, Parameter::mergeWith), - docTags + other.docTags, - descriptors + other.descriptors -) - -fun Property.mergeWith(other: Property) = Property( - dri, - name, - if (receiver != null && other.receiver != null) receiver.mergeWith(other.receiver) else null, - docTags + other.docTags, - descriptors + other.descriptors -) - -fun Class.mergeWith(other: Class) = Class( - dri, - name, - merge(constructors + other.constructors, Function::mergeWith), - merge(functions + other.functions, Function::mergeWith), - merge(properties + other.properties, Property::mergeWith), - merge(classes + other.classes, Class::mergeWith), - docTags + other.docTags, - descriptors + other.descriptors -) - -fun Parameter.mergeWith(other: Parameter) = Parameter( - dri, - name, - docTags + other.docTags, - descriptors + other.descriptors -) diff --git a/core/src/main/kotlin/Model/transformers/DocumentationNodeTransformer.kt b/core/src/main/kotlin/Model/transformers/DocumentationNodeTransformer.kt index f94147fb..318d20b3 100644 --- a/core/src/main/kotlin/Model/transformers/DocumentationNodeTransformer.kt +++ b/core/src/main/kotlin/Model/transformers/DocumentationNodeTransformer.kt @@ -4,4 +4,5 @@ import org.jetbrains.dokka.Model.Module interface DocumentationNodeTransformer { operator fun invoke(original: Module): Module + operator fun invoke(modules: Collection): Module } \ No newline at end of file diff --git a/core/src/main/kotlin/Model/transformers/DocumentationNodesMerger.kt b/core/src/main/kotlin/Model/transformers/DocumentationNodesMerger.kt new file mode 100644 index 00000000..c5a67513 --- /dev/null +++ b/core/src/main/kotlin/Model/transformers/DocumentationNodesMerger.kt @@ -0,0 +1,78 @@ +package org.jetbrains.dokka.Model.transformers + +import org.jetbrains.dokka.Model.* +import org.jetbrains.dokka.Model.Function +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor + +internal object DocumentationNodesMerger : DocumentationNodeTransformer { + override fun invoke(original: Module) = Module( + original.packages.map { mergePackageContent(it) } + ) + override fun invoke(modules: Collection): Module = + Module(merge(modules.flatMap { it.packages }, Package::mergeWith)) +} + +private fun mergePackageContent(original: Package) = Package( + original.dri, + merge(original.functions, Function::mergeWith), + merge(original.properties, Property::mergeWith), + merge(original.classes, Class::mergeWith) +) + +private fun > merge(elements: List, reducer: (T, T) -> T): List = + elements.groupingBy { it.dri } + .reduce { _, left, right -> reducer(left, right)} + .values.toList() + +fun Descriptor.mergeWith(other: Descriptor?) = Descriptor( + descriptor, + docTag, + links, + (passes + (other?.passes ?: emptyList())).distinct() +) + +fun List>.merge() : List> = + groupingBy { it.descriptor }.reduce { + _, left, right -> left.mergeWith(right) + }.values.toList() + +fun Function.mergeWith(other: Function) = Function( + dri, + name, + if (receiver != null && other.receiver != null) receiver.mergeWith(other.receiver) else null, + merge(parameters + other.parameters, Parameter::mergeWith), + expectDescriptor?.mergeWith(other.expectDescriptor), + (actualDescriptors + other.actualDescriptors).merge() +) + +fun Property.mergeWith(other: Property) = Property( + dri, + name, + if (receiver != null && other.receiver != null) receiver.mergeWith(other.receiver) else null, + expectDescriptor?.mergeWith(other.expectDescriptor), + (actualDescriptors + other.actualDescriptors).merge() +) + +fun Class.mergeWith(other: Class) = Class( + dri, + name, + merge(constructors + other.constructors, Function::mergeWith), + merge(functions + other.functions, Function::mergeWith), + merge(properties + other.properties, Property::mergeWith), + merge(classes + other.classes, Class::mergeWith), + expectDescriptor?.mergeWith(other.expectDescriptor), + (actualDescriptors + other.actualDescriptors).merge() +) + +fun Parameter.mergeWith(other: Parameter) = Parameter( + dri, + name, + (actualDescriptors + other.actualDescriptors).merge() +) + +fun Package.mergeWith(other: Package) = Package( + dri, + merge(functions + other.functions, Function::mergeWith), + merge(properties + other.properties, Property::mergeWith), + merge(classes + other.classes, Class::mergeWith) +) \ No newline at end of file diff --git a/core/src/main/kotlin/pages/MarkdownToContentConverter.kt b/core/src/main/kotlin/pages/MarkdownToContentConverter.kt index 24bfc6f4..b29614d7 100644 --- a/core/src/main/kotlin/pages/MarkdownToContentConverter.kt +++ b/core/src/main/kotlin/pages/MarkdownToContentConverter.kt @@ -3,25 +3,21 @@ package org.jetbrains.dokka.pages import org.intellij.markdown.MarkdownElementTypes import org.intellij.markdown.MarkdownTokenTypes import org.jetbrains.dokka.DokkaLogger -import org.jetbrains.dokka.DokkaResolutionFacade import org.jetbrains.dokka.MarkdownNode -import org.jetbrains.dokka.Model.DocumentationNode import org.jetbrains.dokka.links.DRI -import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink class MarkdownToContentConverter( - private val resolutionFacade: DokkaResolutionFacade, private val logger: DokkaLogger ) { fun buildContent( node: MarkdownNode, dci: DCI, - documentationNode: DocumentationNode<*> + links: Map = emptyMap() ): List { // println(tree.toTestString()) fun buildChildren(node: MarkdownNode) = node.children.flatMap { - buildContent(it, dci, documentationNode) + buildContent(it, dci, links) }.coalesceText() return when (node.type) { @@ -89,27 +85,15 @@ class MarkdownToContentConverter( } MarkdownElementTypes.SHORT_REFERENCE_LINK, MarkdownElementTypes.FULL_REFERENCE_LINK -> { - if (documentationNode.descriptors.isNotEmpty()) { - val destinationNode = node.children.find { it.type == MarkdownElementTypes.LINK_DESTINATION } - ?: node.children.first { it.type == MarkdownElementTypes.LINK_LABEL } - val destination = destinationNode.children.find { it.type == MarkdownTokenTypes.TEXT }?.text - ?: destinationNode.text - - documentationNode.descriptors.flatMap { - resolveKDocLink( - resolutionFacade.resolveSession.bindingContext, - resolutionFacade, - it, - null, - destination.split('.') - ) - } - .firstOrNull() - ?.let { ContentLink(destination, DRI.from(it), dci) } - .let(::listOfNotNull) - } else { - logger.error("Apparently descriptor for $documentationNode was needed in model") - emptyList() + val destinationNode = node.children.find { it.type == MarkdownElementTypes.LINK_DESTINATION } + ?: node.children.first { it.type == MarkdownElementTypes.LINK_LABEL } + val destination = destinationNode.children.find { it.type == MarkdownTokenTypes.TEXT }?.text + ?: destinationNode.text + links[destination]?.let { dri -> + listOf(ContentLink(destination, dri, dci)) + } ?: let { + logger.error("Apparently there is no link resolved for $destination") + emptyList() } } MarkdownTokenTypes.WHITE_SPACE -> { diff --git a/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt b/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt index d7837ca2..771226d5 100644 --- a/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt +++ b/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt @@ -1,6 +1,5 @@ package org.jetbrains.dokka.transformers -import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.DokkaLogger import org.jetbrains.dokka.Model.* import org.jetbrains.dokka.Model.Function @@ -16,8 +15,8 @@ class DefaultDocumentationToPageTransformer( private val markdownConverter: MarkdownToContentConverter, private val logger: DokkaLogger ) : DocumentationToPageTransformer { - override fun transform(passConfiguration: DokkaConfiguration.PassConfiguration, module: Module): ModulePageNode { - val platformData = passConfiguration.targets.map { PlatformData(it, passConfiguration.analysisPlatform) } + override fun transform(module: Module): ModulePageNode { + val platformData = emptyList() return PageBuilder(platformData).pageForModule(module) } @@ -72,7 +71,7 @@ class DefaultDocumentationToPageTransformer( private fun contentForClass(c: Class) = content(DCI(c.dri, platformData)) { header(1) { text(c.name) } - c.rawDocstrings.forEach { comment(it, c) } + c.commentsData.forEach { (doc, links) -> comment(doc, links) } block("Constructors", c.constructors) { link(it.name, it.dri) signature(it) @@ -88,11 +87,11 @@ class DefaultDocumentationToPageTransformer( private fun contentForFunction(f: Function) = content(DCI(f.dri, platformData)) { header(1) { text(f.name) } signature(f) - f.rawDocstrings.forEach { markdown(it, f) } + f.commentsData.forEach { (doc, links) -> markdown(doc, links) } block("Parameters", f.children) { param -> group { text(param.name ?: "") - param.rawDocstrings.forEach { markdown(it, param) } + param.commentsData.forEach { (doc, links) -> markdown(doc, links) } } } } @@ -145,12 +144,12 @@ class DefaultDocumentationToPageTransformer( fun link(text: String, address: DRI) { contents += ContentLink(text, address, dci) } - fun comment(raw: String, node: DocumentationNode<*>) { - contents += ContentComment(markdownConverter.buildContent(parseMarkdown(raw), dci, node), dci) + fun comment(raw: String, links: Map) { + contents += ContentComment(markdownConverter.buildContent(parseMarkdown(raw), dci, links), dci) } - fun markdown(raw: String, node: DocumentationNode<*>) { - contents += markdownConverter.buildContent(parseMarkdown(raw), dci, node) + fun markdown(raw: String, links: Map) { + contents += markdownConverter.buildContent(parseMarkdown(raw), dci, links) } private inline fun content(block: ContentBuilder.() -> Unit): List = content(dci, block) @@ -163,7 +162,7 @@ class DefaultDocumentationToPageTransformer( private fun ContentBuilder.signature(f: Function) = symbol { text("fun ") if (f.receiver is Parameter) { - type(f.receiver.descriptors.first().type) + type(f.receiver.descriptors.first().descriptor.type) text(".") } link(f.name, f.dri) @@ -171,11 +170,11 @@ class DefaultDocumentationToPageTransformer( list(f.parameters) { link(it.name!!, it.dri) text(": ") - type(it.descriptors.first().type) + type(it.descriptors.first().descriptor.type) } text(")") - val returnType = f.descriptors.first().returnType - if (f.descriptors.first() !is ConstructorDescriptor && returnType != null && + val returnType = f.descriptors.first().descriptor.returnType + if (f.descriptors.first().descriptor !is ConstructorDescriptor && returnType != null && returnType.constructor.declarationDescriptor?.fqNameSafe?.asString() != Unit::class.qualifiedName) { text(": ") type(returnType) diff --git a/core/src/main/kotlin/transformers/DocumentationToPageTransformer.kt b/core/src/main/kotlin/transformers/DocumentationToPageTransformer.kt index b37b5439..19703025 100644 --- a/core/src/main/kotlin/transformers/DocumentationToPageTransformer.kt +++ b/core/src/main/kotlin/transformers/DocumentationToPageTransformer.kt @@ -7,5 +7,5 @@ import org.jetbrains.dokka.pages.ModulePageNode import org.jetbrains.dokka.pages.PageNode interface DocumentationToPageTransformer { - fun transform(passConfiguration: DokkaConfiguration.PassConfiguration, module: Module): ModulePageNode // TODO refactor this... some more? + fun transform(module: Module): ModulePageNode // TODO refactor this... some more? } \ No newline at end of file diff --git a/core/src/main/kotlin/transformers/TopDownPageNodeMerger.kt b/core/src/main/kotlin/transformers/TopDownPageNodeMerger.kt deleted file mode 100644 index 7d6d33b7..00000000 --- a/core/src/main/kotlin/transformers/TopDownPageNodeMerger.kt +++ /dev/null @@ -1,50 +0,0 @@ -package org.jetbrains.dokka.transformers - -import org.jetbrains.dokka.pages.* -import kotlin.reflect.KClass - -class TopDownPageNodeMerger { - fun mergeModules(nodes: Iterable): PageNode { - assert(nodes.all { it::class == nodes.first()::class }) // TODO check - - val merged = ModulePageNode(nodes.first().name, mergeContent(nodes), null, nodes.first().documentationNode) // TODO: merge documentationNodes - merged.appendChildren(mergeChildren(nodes.flatMap { it.children })) - - return merged - } - - private fun mergeChildren(nodes: Iterable): List = - nodes.groupBy { it.dri }.map { (_, list) -> - val merged = when (list.first()) { - is PackagePageNode -> PackagePageNode(list.first().name, mergeContent(list), list.first().parent!!, list.first().dri!!, list.first().documentationNode) // TODO: merge documentationlist - is ClassPageNode -> ClassPageNode(list.first().name, mergeContent(list), list.first().parent!!, list.first().dri!!, list.first().documentationNode) // TODO: merge documentationlist - is MemberPageNode -> MemberPageNode(list.first().name, mergeContent(list), list.first().parent!!, list.first().dri!!, list.first().documentationNode) // TODO: merge documentationNodes - else -> throw IllegalStateException("${list.first()} should not be present here") - } - merged.appendChildren(mergeChildren(list.flatMap { it.children })) - merged - } - - private fun mergeContent(nodes: Iterable): List = nodes.flatMap { it.content }.groupBy { it.dci.dri }.flatMap { (_, list) -> list.mergeList() } - - - - private fun List.mergeContent(): ContentBlock = - ContentBlock(this.first().name, this.flatMap { it.children }.groupBy { it.dci.dri }.flatMap { (_, list) -> list.mergeList() }, DCI(this.first().dci.dri, this.flatMap { it.dci.platformDataList }.distinct()), this.flatMap { it.annotations }) - - private fun List.mergeList(): List = - this.groupBy { it::class }.flatMap { (_, list) -> - val thisClass = list.first() - val newDCI = DCI(thisClass.dci.dri, list.flatMap { it.dci.platformDataList }.distinct()) - when(thisClass) { - is ContentBlock -> list.groupBy{ (it as ContentBlock).name }.map { (it.value as List).mergeContent() } //(ContentBlock(thisClass.name, (list as List).mergeContent(), newDCI, list.flatMap { it.annotations }.distinct())) - is ContentHeader -> list.distinctBy { it.toString().replace("dci=.*,".toRegex(), "") }.map { (it as ContentHeader).copy(dci = newDCI)} - is ContentStyle -> list.distinctBy { it.toString().replace("dci=.*,".toRegex(), "") }.map { (it as ContentStyle).copy(dci = newDCI)} - is ContentSymbol -> list.distinctBy { it.toString().replace("dci=.*,".toRegex(), "") }.map { (it as ContentSymbol).copy(dci = newDCI)} - is ContentComment -> list.distinctBy { it.toString().replace("dci=.*,".toRegex(), "") }.map { (it as ContentComment).copy(dci = newDCI)} - is ContentGroup -> list.distinctBy { it.toString().replace("dci=.*,".toRegex(), "") }.map { (it as ContentGroup).copy(dci = newDCI)} - is ContentList -> list.distinctBy { it.toString().replace("dci=.*,".toRegex(), "") }.map { (it as ContentList).copy(dci = newDCI)} - else -> list.distinctBy { it.toString().replace("dci=.*,".toRegex(), "") } - } - } -} \ No newline at end of file -- cgit