diff options
Diffstat (limited to 'core/src/main/kotlin/pages')
-rw-r--r-- | core/src/main/kotlin/pages/PageBuilder.kt | 64 | ||||
-rw-r--r-- | core/src/main/kotlin/pages/PageContentBuilder.kt | 17 | ||||
-rw-r--r-- | core/src/main/kotlin/pages/PageNodes.kt | 10 |
3 files changed, 69 insertions, 22 deletions
diff --git a/core/src/main/kotlin/pages/PageBuilder.kt b/core/src/main/kotlin/pages/PageBuilder.kt index e8930fae..003cc815 100644 --- a/core/src/main/kotlin/pages/PageBuilder.kt +++ b/core/src/main/kotlin/pages/PageBuilder.kt @@ -1,8 +1,9 @@ package org.jetbrains.dokka.pages -import org.jetbrains.dokka.model.doc.TagWrapper import org.jetbrains.dokka.model.* +import org.jetbrains.dokka.model.Enum import org.jetbrains.dokka.model.Function +import org.jetbrains.dokka.model.doc.TagWrapper class DefaultPageBuilder( override val rootContentGroup: RootContentBuilder @@ -13,14 +14,21 @@ class DefaultPageBuilder( override fun pageForPackage(p: Package) = PackagePageNode(p.name, contentForPackage(p), setOf(p.dri), p, - p.classes.map { pageForClass(it) } + + p.classlikes.map { pageForClasslike(it) } + p.functions.map { pageForMember(it) }) - override fun pageForClass(c: Class): ClassPageNode = - ClassPageNode(c.name, contentForClass(c), setOf(c.dri), c, - c.constructors.map { pageForMember(it) } + - c.classes.map { pageForClass(it) } + + override fun pageForClasslike(c: Classlike): ClasslikePageNode { + val constructors = when (c) { + is Class -> c.constructors + is Enum -> c.constructors + else -> emptyList() + } + + return ClasslikePageNode(c.name, contentForClasslike(c), setOf(c.dri), c, + constructors.map { pageForMember(it) } + + c.classlikes.map { pageForClasslike(it) } + c.functions.map { pageForMember(it) }) + } override fun pageForMember(m: CallableNode): MemberPageNode = when (m) { @@ -43,7 +51,7 @@ class DefaultPageBuilder( private fun contentForPackage(p: Package) = group(p) { header(1) { text("Package ${p.name}") } - block("Types", 2, ContentKind.Properties, p.classes, p.platformData) { + block("Types", 2, ContentKind.Properties, p.classlikes, p.platformData) { link(it.name, it.dri) text(it.briefDocTagString) } @@ -54,6 +62,12 @@ class DefaultPageBuilder( } } + private fun contentForClasslike(c: Classlike): ContentGroup = when (c) { + is Class -> contentForClass(c) + is Enum -> contentForEnum(c) + else -> throw IllegalStateException("$c should not be present here") + } + private fun contentForClass(c: Class) = group(c) { header(1) { text(c.name) } c.inherited.takeIf { it.isNotEmpty() }?.let { @@ -69,7 +83,32 @@ class DefaultPageBuilder( comment(it.root) text("\n") } + + block("Functions", 2, ContentKind.Functions, c.functions, c.platformData) { + link(it.name, it.dri) + signature(it) + text(it.briefDocTagString) + } + block("Properties", 2, ContentKind.Properties, c.properties, c.platformData) { + link(it.name, it.dri) + text(it.briefDocTagString) + } + } + } + + fun contentForEnum(c: Enum): ContentGroup = group(c) { + header(1) { text("enum ${c.name}") } + + block("Entries", 2, ContentKind.Properties, c.entries, c.platformData) { entry -> + link(entry.name, entry.dri) + contentForComments(entry) + } + + c.inherited.takeIf { it.isNotEmpty() }?.let { + header(2) { text("SuperInterfaces") } + linkTable(it) } + contentForComments(c) block("Constructors", 2, ContentKind.Functions, c.constructors, c.platformData) { link(it.name, it.dri) signature(it) @@ -86,6 +125,15 @@ class DefaultPageBuilder( } } + private fun PageContentBuilder.contentForComments(d: Documentable) = + d.commentsData.forEach { + it.children.forEach { + header(3) { text(it.toHeaderString()) } + comment(it.root) + text("\n") + } + } + private fun contentForFunction(f: Function) = group(f) { header(1) { text(f.name) } signature(f) @@ -115,5 +163,5 @@ interface PageBuilder { fun pageForModule(m: Module): ModulePageNode fun pageForPackage(p: Package): PackagePageNode fun pageForMember(m: CallableNode): MemberPageNode - fun pageForClass(c: Class): ClassPageNode + fun pageForClasslike(c: Classlike): ClasslikePageNode }
\ 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 efe23b5a..d5ffe27a 100644 --- a/core/src/main/kotlin/pages/PageContentBuilder.kt +++ b/core/src/main/kotlin/pages/PageContentBuilder.kt @@ -1,12 +1,12 @@ package org.jetbrains.dokka.pages -import org.jetbrains.dokka.model.doc.DocTag -import org.jetbrains.dokka.utilities.DokkaLogger +import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.Documentable import org.jetbrains.dokka.model.Function import org.jetbrains.dokka.model.Parameter import org.jetbrains.dokka.model.TypeWrapper -import org.jetbrains.dokka.links.DRI +import org.jetbrains.dokka.model.doc.DocTag +import org.jetbrains.dokka.utilities.DokkaLogger class DefaultPageContentBuilder( private val dri: Set<DRI>, @@ -169,10 +169,9 @@ private fun PageContentBuilder.type(t: TypeWrapper) { else if (t.constructorNamePathSegments.isNotEmpty() && t.dri == null) text(t.toString()) else (this as? DefaultPageContentBuilder)?.let { - logger.error("type $t cannot be resolved") - text("???") - } - + logger.error("type $t cannot be resolved") + text("???") + } list(t.arguments, prefix = "<", suffix = ">") { type(it) } @@ -199,8 +198,8 @@ interface PageContentBuilder { fun header(level: Int, block: PageContentBuilderFunction) fun <T> list( elements: List<T>, - prefix: String = "", - suffix: 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 73d63cd7..6b67a734 100644 --- a/core/src/main/kotlin/pages/PageNodes.kt +++ b/core/src/main/kotlin/pages/PageNodes.kt @@ -47,7 +47,7 @@ abstract class RootPageNode: PageNode { fun transformContentPagesTree(operation: (ContentPage) -> ContentPage) = transformPageNodeTree { if (it is ContentPage) operation(it) else it - } as RootPageNode + } private fun PageNode.transformNode(operation: (PageNode) -> PageNode): PageNode = operation(this).let { newNode -> @@ -105,7 +105,7 @@ class PackagePageNode( else PackagePageNode(name, content, dri, documentable, children, embeddedResources) } -class ClassPageNode( +class ClasslikePageNode( override val name: String, override val content: ContentNode, override val dri: Set<DRI>, @@ -113,7 +113,7 @@ class ClassPageNode( override val children: List<PageNode>, override val embeddedResources: List<String> = listOf() ) : ContentPage { - override fun modified(name: String, children: List<PageNode>): ClassPageNode = + override fun modified(name: String, children: List<PageNode>): ClasslikePageNode = modified(name = name, content = this.content, children = children) override fun modified( @@ -121,9 +121,9 @@ class ClassPageNode( content: ContentNode, embeddedResources: List<String>, children: List<PageNode> - ): ClassPageNode = + ): ClasslikePageNode = if (name == this.name && content === this.content && embeddedResources === this.embeddedResources && children shallowEq this.children) this - else ClassPageNode(name, content, dri, documentable, children, embeddedResources) + else ClasslikePageNode(name, content, dri, documentable, children, embeddedResources) } class MemberPageNode( |