From 4b1a3a2cbe62f98c9f1b472e70d754645d7f8641 Mon Sep 17 00:00:00 2001 From: Błażej Kardyś Date: Tue, 26 Nov 2019 14:39:06 +0100 Subject: Merging PageNode changes with plugins --- plugins/xml/src/main/kotlin/XmlPlugin.kt | 62 +++++++++++++++++--------------- 1 file changed, 34 insertions(+), 28 deletions(-) (limited to 'plugins/xml/src/main/kotlin/XmlPlugin.kt') diff --git a/plugins/xml/src/main/kotlin/XmlPlugin.kt b/plugins/xml/src/main/kotlin/XmlPlugin.kt index 4023e1cc..5be0eca4 100644 --- a/plugins/xml/src/main/kotlin/XmlPlugin.kt +++ b/plugins/xml/src/main/kotlin/XmlPlugin.kt @@ -2,6 +2,7 @@ package org.jetbrains.dokka.xml import org.jetbrains.dokka.CoreExtensions import org.jetbrains.dokka.DefaultExtra +import org.jetbrains.dokka.DokkaConsoleLogger import org.jetbrains.dokka.Model.DocumentationNode import org.jetbrains.dokka.Model.dfs import org.jetbrains.dokka.links.DRI @@ -9,6 +10,7 @@ import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.plugability.DokkaPlugin import org.jetbrains.dokka.transformers.PageNodeTransformer +import javax.xml.bind.annotation.XmlList class XmlPlugin : DokkaPlugin() { val transformer by extending { @@ -21,36 +23,40 @@ object XmlTransformer : PageNodeTransformer { Main, XmlList } - override fun invoke(input: ModulePageNode, dokkaContext: DokkaContext): ModulePageNode { - input.findAll { it is ClassPageNode }.forEach { node -> - val refs = node.documentationNode?.extra?.filterIsInstance()?.filter { it.key == "@attr ref"}.orEmpty() - val elementsToAdd = mutableListOf>() - - refs.forEach { ref -> - val toFind = DRI.from(ref.value) - input.documentationNode?.dfs { it.dri == toFind }?.let { elementsToAdd.add(it) } - } - val refTable = group(node.platforms().toSet(), node.dri, XMLKind.XmlList) { - table("XML Attributes", 2, XMLKind.XmlList, elementsToAdd) { - elementsToAdd.map { row(it) } + override fun invoke(input: ModulePageNode, dokkaContext: DokkaContext): ModulePageNode = + input.transformPageNodeTree { node -> + if (node !is ClassPageNode) node + else { + val refs = + node.documentationNode?.extra?.filterIsInstance()?.filter { it.key == "@attr ref" } + .orEmpty() + val elementsToAdd = mutableListOf() + + refs.forEach { ref -> + val toFind = DRI.from(ref.value) + input.documentationNode?.dfs { it.dri == toFind }?.let { elementsToAdd.add(it) } + } + val platformData = node.platforms().toSet() + val refTable = DefaultPageContentBuilder.group( + node.dri, + platformData, + XMLKind.XmlList, + //Following parameters will soon be drawn from context, so we can leave them like this for the time being + MarkdownToContentConverter(DokkaConsoleLogger), + DokkaConsoleLogger + ) { + block("XML Attributes", 2, XMLKind.XmlList, elementsToAdd, platformData) { element -> + link(element.dri, XMLKind.XmlList) { + text(element.name ?: "", XMLKind.Main) + } + text(element.briefDocstring, XMLKind.XmlList) + } } - } - - val content = node.content as ContentGroup - val children = (node.content as ContentGroup).children - node.content = content.copy(children = children + refTable) - } - return input - } - private fun PageNode.findAll(predicate: (PageNode) -> Boolean): Set { - val found = mutableSetOf() - if (predicate(this)) { - found.add(this) - } else { - this.children.asSequence().mapNotNull { it.findAll(predicate) }.forEach { found.addAll(it) } - } - return found + val content = node.content as ContentGroup + val children = (node.content as ContentGroup).children + node.modified(content = content.copy(children = children + refTable)) + } } private fun PageNode.platforms() = this.content.platforms.toList() -- cgit