diff options
| author | Błażej Kardyś <bkardys@virtuslab.com> | 2019-11-07 08:21:43 +0100 |
|---|---|---|
| committer | Błażej Kardyś <bkardys@virtuslab.com> | 2019-11-08 18:47:43 +0100 |
| commit | 493951f487910a1306a4129b7e8144e679c0213c (patch) | |
| tree | 15ac0502e76c0a327bb835e31d0e65f499928ec1 /core/src/main/kotlin/transformers | |
| parent | 0627b9dd15171db221bee2e5a6b0082aec813c98 (diff) | |
| download | dokka-493951f487910a1306a4129b7e8144e679c0213c.tar.gz dokka-493951f487910a1306a4129b7e8144e679c0213c.tar.bz2 dokka-493951f487910a1306a4129b7e8144e679c0213c.zip | |
Moving platform merging to documentationNodes
Diffstat (limited to 'core/src/main/kotlin/transformers')
3 files changed, 14 insertions, 65 deletions
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<PlatformData>() 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 ?: "<receiver>") - 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<String, DRI>) { + 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<String, DRI>) { + contents += markdownConverter.buildContent(parseMarkdown(raw), dci, links) } private inline fun content(block: ContentBuilder.() -> Unit): List<ContentNode> = 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<ModulePageNode>): 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<PageNode>): List<PageNode> = - 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<PageNode>): List<ContentNode> = nodes.flatMap { it.content }.groupBy { it.dci.dri }.flatMap { (_, list) -> list.mergeList() } - - - - private fun List<ContentBlock>.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<ContentNode>.mergeList(): List<ContentNode> = - 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<ContentBlock>).mergeContent() } //(ContentBlock(thisClass.name, (list as List<ContentBlock>).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 |
