diff options
Diffstat (limited to 'core/src')
4 files changed, 66 insertions, 56 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 |