aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBłażej Kardyś <bkardys@virtuslab.com>2019-11-26 14:39:06 +0100
committerBłażej Kardyś <bkardys@virtuslab.com>2019-11-26 14:39:06 +0100
commit4b1a3a2cbe62f98c9f1b472e70d754645d7f8641 (patch)
treeb66dc9a69905f972c84cdca75bc2f21a02f244a4
parent193b8c0bcebdcdfd749090a408149cac06203614 (diff)
downloaddokka-4b1a3a2cbe62f98c9f1b472e70d754645d7f8641.tar.gz
dokka-4b1a3a2cbe62f98c9f1b472e70d754645d7f8641.tar.bz2
dokka-4b1a3a2cbe62f98c9f1b472e70d754645d7f8641.zip
Merging PageNode changes with plugins
-rw-r--r--core/src/main/kotlin/Model/DocumentationNode.kt26
-rw-r--r--core/src/main/kotlin/pages/PageContentBuilder.kt86
-rw-r--r--core/src/main/kotlin/pages/PageNodes.kt8
-rw-r--r--core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt2
-rw-r--r--plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt2
-rw-r--r--plugins/xml/src/main/kotlin/XmlPlugin.kt62
-rw-r--r--plugins/xml/src/main/kotlin/utils.kt136
7 files changed, 102 insertions, 220 deletions
diff --git a/core/src/main/kotlin/Model/DocumentationNode.kt b/core/src/main/kotlin/Model/DocumentationNode.kt
index 623f2ea3..0adb37b5 100644
--- a/core/src/main/kotlin/Model/DocumentationNode.kt
+++ b/core/src/main/kotlin/Model/DocumentationNode.kt
@@ -18,12 +18,12 @@ class Package(
override val classes: List<Class>,
override val extra: MutableSet<Extra> = mutableSetOf()
) : ScopeNode() {
- val name = dri.packageName.orEmpty()
+ override val name = dri.packageName.orEmpty()
}
class Class(
override val dri: DRI,
- val name: String,
+ override val name: String,
val kind: ClassKind,
val constructors: List<Function>,
override val functions: List<Function>,
@@ -38,7 +38,7 @@ class Class(
class Function(
override val dri: DRI,
- val name: String,
+ override val name: String,
val returnType: TypeWrapper?,
val isConstructor: Boolean,
override val receiver: Parameter?,
@@ -53,7 +53,7 @@ class Function(
class Property(
override val dri: DRI,
- val name: String,
+ override val name: String,
override val receiver: Parameter?,
override val expected: PlatformInfo?,
override val actual: List<PlatformInfo>,
@@ -66,7 +66,7 @@ class Property(
// TODO: treat named Parameters and receivers differently
class Parameter(
override val dri: DRI,
- val name: String?,
+ override val name: String?,
val type: TypeWrapper,
override val actual: List<PlatformInfo>,
override val extra: MutableSet<Extra> = mutableSetOf()
@@ -102,6 +102,7 @@ class ClassPlatformInfo(
abstract class DocumentationNode {
open val expected: PlatformInfo? = null
open val actual: List<PlatformInfo> = emptyList()
+ open val name: String? = null
val platformInfo by lazy { listOfNotNull(expected) + actual }
val platformData by lazy { platformInfo.flatMap { it.platformData }.toSet() }
@@ -151,11 +152,6 @@ interface TypeWrapper {
}
interface ClassKind
-fun DocumentationNode.walk(process: DocumentationNode.() -> Unit) {
- this.process()
- this.children.forEach { it.process() }
-}
-
fun DocumentationNode.dfs(predicate: (DocumentationNode) -> Boolean): DocumentationNode? =
if (predicate(this)) {
this
@@ -163,14 +159,4 @@ fun DocumentationNode.dfs(predicate: (DocumentationNode) -> Boolean): Documentat
this.children.asSequence().mapNotNull { it.dfs(predicate) }.firstOrNull()
}
-fun DocumentationNode.findAll(predicate: (DocumentationNode) -> Boolean): Set<DocumentationNode> {
- val found = mutableSetOf<DocumentationNode>()
- if (predicate(this)) {
- found.add(this)
- } else {
- this.children.asSequence().mapNotNull { it.findAll(predicate) }.forEach { found.addAll(it) }
- }
- return found
-}
-
interface Extra \ No newline at end of file
diff --git a/core/src/main/kotlin/pages/PageContentBuilder.kt b/core/src/main/kotlin/pages/PageContentBuilder.kt
index 9d07a098..2341a59d 100644
--- a/core/src/main/kotlin/pages/PageContentBuilder.kt
+++ b/core/src/main/kotlin/pages/PageContentBuilder.kt
@@ -9,7 +9,8 @@ import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.parseMarkdown
class DefaultPageContentBuilder(
- private val node: DocumentationNode,
+ private val dri: DRI,
+ private val platformData: Set<PlatformData>,
private val kind: Kind,
private val markdownConverter: MarkdownToContentConverter,
val logger: DokkaLogger,
@@ -18,13 +19,13 @@ class DefaultPageContentBuilder(
) : PageContentBuilder {
private val contents = mutableListOf<ContentNode>()
- private fun createText(text: String) =
- ContentText(text, DCI(node.dri, ContentKind.Symbol), node.platformData, styles, extras)
+ private fun createText(text: String, kind: Kind = ContentKind.Symbol) =
+ ContentText(text, DCI(dri, kind), platformData, styles, extras)
private fun build() = ContentGroup(
contents.toList(),
- DCI(node.dri, kind),
- node.platformData,
+ DCI(dri, kind),
+ platformData,
styles,
extras
)
@@ -33,12 +34,12 @@ class DefaultPageContentBuilder(
contents += ContentHeader(level, group(ContentKind.Symbol, block))
}
- override fun text(text: String) {
- contents += createText(text)
+ override fun text(text: String, kind: Kind) {
+ contents += createText(text, kind)
}
private fun signature(f: Function, block: PageContentBuilderFunction) {
- contents += group(f, ContentKind.Symbol, block)
+ contents += group(f.dri, f.platformData, ContentKind.Symbol, block)
}
override fun signature(f: Function) = signature(f) {
@@ -49,7 +50,7 @@ class DefaultPageContentBuilder(
}
link(f.name, f.dri)
text("(")
- list(f.parameters, "", "", ", ") {
+ list(f.parameters) {
link(it.name!!, it.dri)
text(": ")
type(it.type)
@@ -66,9 +67,9 @@ class DefaultPageContentBuilder(
override fun linkTable(elements: List<DRI>) {
contents += ContentTable(
emptyList(),
- elements.map { group(node, ContentKind.Classes) { link(it.classNames ?: "", it) } },
- DCI(node.dri, kind),
- node.platformData, styles, extras
+ elements.map { group(dri, platformData, ContentKind.Classes) { link(it.classNames ?: "", it) } },
+ DCI(dri, kind),
+ platformData, styles, extras
)
}
@@ -84,8 +85,8 @@ class DefaultPageContentBuilder(
contents += ContentTable(
emptyList(),
- elements.map { group(it, kind) { operation(it) } },
- DCI(node.dri, kind),
+ elements.map { group(it.dri, it.platformData, kind) { operation(it) } },
+ DCI(dri, kind),
platformData, styles, extras
)
}
@@ -108,12 +109,21 @@ class DefaultPageContentBuilder(
}
}
- override fun link(text: String, address: DRI) {
+ override fun link(text: String, address: DRI, kind: Kind) {
contents += ContentDRILink(
listOf(createText(text)),
address,
- DCI(node.dri, ContentKind.Symbol),
- node.platformData
+ DCI(dri, kind),
+ platformData
+ )
+ }
+
+ override fun link(address: DRI, kind: Kind, block: PageContentBuilderFunction) {
+ contents += ContentDRILink(
+ group(ContentKind.Main, block).children,
+ address,
+ DCI(dri, kind),
+ platformData
)
}
@@ -122,8 +132,8 @@ class DefaultPageContentBuilder(
with(this as DefaultPageContentBuilder) {
contents += markdownConverter.buildContent(
parseMarkdown(raw),
- DCI(node.dri, ContentKind.Comment),
- node.platformData,
+ DCI(dri, ContentKind.Comment),
+ platformData,
links
)
}
@@ -132,30 +142,32 @@ class DefaultPageContentBuilder(
override fun markdown(raw: String, links: Map<String, DRI>) {
contents += markdownConverter.buildContent(
- parseMarkdown(raw), DCI(node.dri, ContentKind.Sample),
- node.platformData,
+ parseMarkdown(raw), DCI(dri, ContentKind.Sample),
+ platformData,
links
)
}
- private fun group(kind: Kind, block: PageContentBuilderFunction): ContentGroup =
- group(node, kind, block)
+ fun group(kind: Kind, block: PageContentBuilderFunction): ContentGroup =
+ group(dri, platformData, kind, block)
override fun group(
- node: DocumentationNode,
+ dri: DRI,
+ platformData: Set<PlatformData>,
kind: Kind,
block: PageContentBuilderFunction
- ): ContentGroup = group(node, kind, markdownConverter, logger, block)
+ ): ContentGroup = group(dri, platformData, kind, markdownConverter, logger, block)
companion object {
fun group(
- node: DocumentationNode,
+ dri: DRI,
+ platformData: Set<PlatformData>,
kind: Kind,
markdownConverter: MarkdownToContentConverter,
logger: DokkaLogger,
block: PageContentBuilderFunction
): ContentGroup =
- DefaultPageContentBuilder(node, kind, markdownConverter, logger).apply(block).build()
+ DefaultPageContentBuilder(dri, platformData, kind, markdownConverter, logger).apply(block).build()
}
}
@@ -167,7 +179,7 @@ private fun PageContentBuilder.type(t: TypeWrapper) {
logger.error("type $t cannot be resolved")
text("???")
}
- list(t.arguments, prefix = "<", suffix = ">", separator = ", ") {
+ list(t.arguments, prefix = "<", suffix = ">") {
type(it)
}
}
@@ -179,19 +191,23 @@ annotation class ContentMarker
@ContentMarker
interface PageContentBuilder {
- fun group(node: DocumentationNode, kind: Kind, block: PageContentBuilderFunction): ContentGroup
- fun text(text: String)
+ fun group(
+ dri: DRI,
+ platformData: Set<PlatformData>,
+ kind: Kind, block: PageContentBuilderFunction): ContentGroup
+ fun text(text: String, kind: Kind = ContentKind.Symbol)
fun signature(f: Function)
- fun link(text: String, address: DRI)
+ fun link(text: String, address: DRI, kind: Kind = ContentKind.Symbol)
+ fun link(address: DRI, kind: Kind = ContentKind.Symbol, block: PageContentBuilderFunction)
fun linkTable(elements: List<DRI>)
fun comment(raw: String, links: Map<String, DRI>)
fun markdown(raw: String, links: Map<String, DRI>)
- fun header(level: Int, block: PageContentBuilder.() -> Unit)
+ fun header(level: Int, block: PageContentBuilderFunction)
fun <T> list(
elements: List<T>,
- prefix: String,
- suffix: String,
- separator: String,
+ prefix: String = "",
+ suffix: String = "",
+ separator: String = ",",
operation: PageContentBuilder.(T) -> Unit
)
diff --git a/core/src/main/kotlin/pages/PageNodes.kt b/core/src/main/kotlin/pages/PageNodes.kt
index a07aa8c1..cf5bf453 100644
--- a/core/src/main/kotlin/pages/PageNodes.kt
+++ b/core/src/main/kotlin/pages/PageNodes.kt
@@ -58,6 +58,14 @@ class ModulePageNode(
): ModulePageNode =
if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this
else ModulePageNode(name, content, documentationNode, children, embeddedResources)
+
+ private fun PageNode.transformNode(operation: (PageNode) -> PageNode): PageNode =
+ operation(this).let { newNode ->
+ newNode.modified(children = newNode.children.map { it.transformNode(operation) })
+ }
+
+ fun transformPageNodeTree(operation: (PageNode) -> PageNode) =
+ this.transformNode(operation) as ModulePageNode
}
class PackagePageNode(
diff --git a/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt b/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt
index 4c44ecdf..b0877527 100644
--- a/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt
+++ b/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt
@@ -14,7 +14,7 @@ class DefaultDocumentationToPageTransformer(
) : DocumentationToPageTransformer {
override fun transform(module: Module): ModulePageNode =
DefaultPageBuilder { node, kind, operation ->
- DefaultPageContentBuilder.group(node, kind, markdownConverter, logger, operation)
+ DefaultPageContentBuilder.group(node.dri, node.platformData, kind, markdownConverter, logger, operation)
}.pageForModule(module)
} \ No newline at end of file
diff --git a/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt b/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt
index 63512966..0decfb1c 100644
--- a/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt
+++ b/plugins/mathjax/src/main/kotlin/MathjaxPlugin.kt
@@ -28,7 +28,7 @@ object MathjaxTransformer : PageNodeTransformer {
private val PageNode.isNeedingMathjax
- get() = documentationNode?.descriptors
+ get() = documentationNode?.platformInfo
?.flatMap { it.docTag?.children?.toList().orEmpty() }
.orEmpty()
.any { it.text == ANNOTATION }
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<DefaultExtra>()?.filter { it.key == "@attr ref"}.orEmpty()
- val elementsToAdd = mutableListOf<DocumentationNode<*>>()
-
- 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<DefaultExtra>()?.filter { it.key == "@attr ref" }
+ .orEmpty()
+ val elementsToAdd = mutableListOf<DocumentationNode>()
+
+ 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 ?: "<unnamed>", 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<PageNode> {
- val found = mutableSetOf<PageNode>()
- 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()
diff --git a/plugins/xml/src/main/kotlin/utils.kt b/plugins/xml/src/main/kotlin/utils.kt
index 510f3328..2f5f1893 100644
--- a/plugins/xml/src/main/kotlin/utils.kt
+++ b/plugins/xml/src/main/kotlin/utils.kt
@@ -1,135 +1 @@
-package org.jetbrains.dokka.xml
-
-import org.jetbrains.dokka.Model.DocumentationNode
-import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.pages.*
-
-internal class ContentBuilder(
- val platforms: Set<PlatformData>,
- val dri: DRI,
- val kind: Kind,
- val styles: Set<Style> = emptySet(),
- val extras: Set<Extra> = emptySet()
-) {
- private val contents = mutableListOf<ContentNode>()
-
- fun build() = ContentGroup(
- contents.toList(),
- DCI(dri, kind),
- platforms,
- styles,
- extras
- )
-
- fun header(level: Int, block: ContentBuilder.() -> Unit) {
- contents += ContentHeader(level, group(ContentKind.Symbol, block))
- }
-
- private fun createText(text: String) =
- ContentText(text, DCI(dri, ContentKind.Symbol), platforms, styles, extras)
-
- fun text(text: String) {
- contents += createText(text)
- }
-
- inline fun <T : Any> block(
- name: String,
- level: Int,
- kind: Kind,
- elements: Iterable<T>,
- platformData: Set<PlatformData>,
- operation: ContentBuilder.(T) -> Unit
- ) {
- header(level) { text(name) }
-
- contents += ContentTable(
- emptyList(),
- elements.map { group(platforms, dri, kind) { operation(it) } },
- DCI(dri, kind),
- platformData, styles, extras
- )
- }
-
- inline fun <T> list(
- elements: List<T>,
- prefix: String = "",
- suffix: String = "",
- separator: String = ", ",
- block: ContentBuilder.(T) -> Unit
- ) {
- if (elements.isNotEmpty()) {
- if (prefix.isNotEmpty()) text(prefix)
- elements.dropLast(1).forEach {
- block(it)
- text(separator)
- }
- block(elements.last())
- if (suffix.isNotEmpty()) text(suffix)
- }
- }
-
- fun link(text: String, address: DRI) {
- contents += ContentDRILink(
- listOf(createText(text)),
- address,
- DCI(dri, ContentKind.Symbol),
- platforms
- )
- }
-
- fun <T: DocumentationNode<*>> table(
- name: String,
- level: Int,
- kind: Kind,
- elements: Iterable<T>,
- operation: ContentBuilder.(T) -> Unit
- ) {
- header(level) { text(name) }
-
- contents += ContentTable(
- emptyList(),
- elements.map { row(it) }.toList(),
- DCI(dri, kind),
- platforms, emptySet(), emptySet()
- )
- }
-
-
- fun row(element: DocumentationNode<*>) =
- ContentGroup(
- listOf(
- ContentDRILink(
- listOf(
- ContentText(
- element.descriptors.first().name.toString(),
- DCI(dri, XmlTransformer.XMLKind.Main),
- platforms, emptySet(), emptySet()
- )
- ),
- element.dri,
- DCI(element.dri, XmlTransformer.XMLKind.XmlList),
- element.platformData.toSet(), emptySet(), emptySet()
- ),
- ContentText(
- element.briefDocstring,
- DCI(element.dri, XmlTransformer.XMLKind.XmlList),
- element.platformData.toSet(), emptySet(), emptySet()
- )
- ),
- DCI(dri, XmlTransformer.XMLKind.XmlList),
- platforms, emptySet(), emptySet()
- )
-
-
- private inline fun group(kind: Kind, block: ContentBuilder.() -> Unit): ContentGroup =
- group(platforms, dri, kind, block)
-}
-
-internal inline fun group(
- platforms: Set<PlatformData>,
- dri: DRI,
- kind: Kind = ContentKind.Main,
- block: ContentBuilder.() -> Unit
-) = ContentBuilder(platforms, dri, kind).apply(block).build()
-
-
+package org.jetbrains.dokka.xml \ No newline at end of file