diff options
Diffstat (limited to 'plugins')
5 files changed, 241 insertions, 201 deletions
diff --git a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt index a3bef099..1f744fba 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt @@ -27,10 +27,10 @@ open class JavadocPageCreator( fun pageForModule(m: DModule): JavadocModulePageNode = JavadocModulePageNode( - m.name.ifEmpty { "root" }, - contentForModule(m), - m.packages.map { pageForPackage(it) }, - setOf(m.dri) + name = m.name.ifEmpty { "root" }, + content = contentForModule(m), + children = m.packages.map { pageForPackage(it) }, + dri = setOf(m.dri) ) fun pageForPackage(p: DPackage) = @@ -39,7 +39,7 @@ open class JavadocPageCreator( ) fun pageForClasslike(c: DClasslike): JavadocClasslikePageNode? = - c.sourceSets.firstOrNull { it.platform == Platform.jvm }?.let {jvm -> + c.sourceSets.firstOrNull { it.platform == Platform.jvm }?.let { jvm -> JavadocClasslikePageNode( name = c.name.orEmpty(), content = contentForClasslike(c), @@ -49,9 +49,19 @@ open class JavadocPageCreator( description = c.description(jvm), constructors = c.safeAs<WithConstructors>()?.constructors?.map { it.toJavadocFunction(jvm) }.orEmpty(), methods = c.functions.map { it.toJavadocFunction(jvm) }, - entries = c.safeAs<DEnum>()?.entries?.map { JavadocEntryNode(signatureProvider.signature(it), it.description(jvm)) }.orEmpty(), + entries = c.safeAs<DEnum>()?.entries?.map { + JavadocEntryNode( + signatureProvider.signature(it), + it.description(jvm) + ) + }.orEmpty(), classlikes = c.classlikes.mapNotNull { pageForClasslike(it) }, - properties = c.properties.map { JavadocPropertyNode(signatureProvider.signature(it), TextNode(it.description(jvm), setOf(jvm))) }, + properties = c.properties.map { + JavadocPropertyNode( + signatureProvider.signature(it), + TextNode(it.description(jvm), setOf(jvm)) + ) + }, documentable = c, extras = c.safeAs<WithExtraProperties<Documentable>>()?.extra ?: PropertyContainer.empty() ) @@ -117,7 +127,7 @@ open class JavadocPageCreator( is TypeConstructor -> if (p.function) "TODO" else { - val other = if(p.projections.isNotEmpty()){ + val other = if (p.projections.isNotEmpty()) { p.projections.joinToString(prefix = "<", postfix = ">") { signatureForProjection(it) } } else { "" @@ -149,9 +159,10 @@ open class JavadocPageCreator( extras = extra ) - private fun Documentable.description(sourceSetData: SourceSetData): String = findNodeInDocumentation<Description>(sourceSetData) + private fun Documentable.description(sourceSetData: SourceSetData): String = + findNodeInDocumentation<Description>(sourceSetData) - private inline fun <reified T: TagWrapper> Documentable.findNodeInDocumentation(sourceSetData: SourceSetData): String = + private inline fun <reified T : TagWrapper> Documentable.findNodeInDocumentation(sourceSetData: SourceSetData): String = documentation[sourceSetData]?.children?.firstIsInstanceOrNull<T>()?.root?.children?.firstIsInstanceOrNull<Text>()?.body.orEmpty() } diff --git a/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt b/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt index 1026ea5c..f0835270 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt @@ -19,7 +19,7 @@ import java.nio.file.Path import java.nio.file.Paths import java.time.LocalDate -typealias PageContent = Map<String, Any?> +typealias TemplateMap = Map<String, Any?> class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaContext, val resourceDir: String) : Renderer { @@ -54,10 +54,12 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon val name = "index" val pathToRoot = "" - val contentMap = mapOf( + val contentMap = mapOf<String, Any?>( "docName" to "docName", // todo docname - "pathToRoot" to pathToRoot - ) + node.contentMap + "pathToRoot" to pathToRoot, + "kind" to "main", + ) + renderJavadocContentNode(node.content) + writeFromTemplate(outputWriter, "$link/$name".toNormalized(), "tabPage.korte", contentMap.toList()) node.children.forEach { renderNode(it, link) } } @@ -65,7 +67,7 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon private fun CoroutineScope.renderJavadocNode(node: JavadocPageNode) { val link = locationProvider.resolve(node, skipExtension = true) val dir = Paths.get(link).parent?.let { it.toNormalized() }.orEmpty() - val pathToRoot = dir.split("/").filter { it.isNotEmpty()} .joinToString("/") { ".." }.let { + val pathToRoot = dir.split("/").filter { it.isNotEmpty() }.joinToString("/") { ".." }.let { if (it.isNotEmpty()) "$it/" else it } @@ -90,7 +92,8 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon } } - fun Pair<String, String>.pairToTag() = "\n<th class=\"colFirst\" scope=\"row\">${first}</th>\n<td class=\"colLast\">${second}</td>" + fun Pair<String, String>.pairToTag() = + "\n<th class=\"colFirst\" scope=\"row\">${first}</th>\n<td class=\"colLast\">${second}</td>" fun LinkJavadocListEntry.toLinkTag(parent: String? = null) = createLinkTag(locationProvider.resolve(dri.first(), sourceSets.toList()).let { @@ -116,23 +119,14 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon path: String, template: String, args: List<Pair<String, *>> - ) = - launch { - val tmp = templateRenderer.render(template, *(args.toTypedArray())) - writer.writeHtml( - path, - tmp - ) - } + ) = launch { + val tmp = templateRenderer.render(template, *(args.toTypedArray())) + writer.writeHtml(path, tmp) + } -// private fun renderContentNode(content: ContentNode) = when(content) { -// is ContentText -> content.text -// is ContentComposite -> renderContent(content.children) -// else -> "" -// } - private fun renderContent(content: List<ContentNode>): String = - content.joinToString("") { renderContentNode(it) } + private fun htmlForContentNodes(content: List<ContentNode>): String = + content.joinToString("") { htmlForContentNode(it) } fun getTemplateConfig() = TemplateConfig().also { config -> listOf( @@ -144,7 +138,10 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon TeFunction("createTabRow") { args -> val (link, doc) = args.first() as RowJavadocListEntry val dir = args[1] as String? - (createLinkTag(locationProvider.resolve(link, dir.orEmpty()), link.name) to renderContent(doc)).pairToTag().trim() + (createLinkTag( + locationProvider.resolve(link, dir.orEmpty()), + link.name + ) to htmlForContentNodes(doc)).pairToTag().trim() }, TeFunction("createListRow") { args -> val link = args.first() as LinkJavadocListEntry @@ -163,7 +160,7 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon TeFunction("renderInheritanceGraph") { args -> val rootNodes = args.first() as List<TreeViewPage.InheritanceNode> - fun drawRec(node: TreeViewPage.InheritanceNode) : String { + fun drawRec(node: TreeViewPage.InheritanceNode): String { val returnValue = "<li class=\"circle\">" + node.dri.let { dri -> listOfNotNull( dri.packageName, @@ -182,11 +179,12 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon }.orEmpty() + "</li>" return returnValue } - rootNodes.joinToString{ drawRec(it) } + rootNodes.joinToString { drawRec(it) } }, Filter("length") { subject.dynamicLength() }, - TeFunction("hasAnyDescription"){ args -> - args.first().safeAs<List<HashMap<String, String>>>()?.any { it["description"]?.trim()?.isNotEmpty() ?: false } + TeFunction("hasAnyDescription") { args -> + args.first().safeAs<List<HashMap<String, String>>>() + ?.any { it["description"]?.trim()?.isNotEmpty() ?: false } } ).forEach { when (it) { @@ -206,54 +204,92 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon ?.joinToString("\n") ?: throw IllegalStateException("Template not found: $basePath/$template") } - private fun renderContentNodes(node: JavadocPageNode): PageContent = - when(node){ + private fun renderContentNodes(node: JavadocPageNode): TemplateMap = + when (node) { is JavadocClasslikePageNode -> renderClasslikeNode(node) is JavadocFunctionNode -> renderFunctionNode(node) - else -> node.contentMap + is JavadocPackagePageNode -> renderPackagePageNode(node) + is TreeViewPage -> renderTreeViewPage(node) + is AllClassesPage -> renderAllClassesPage(node) + else -> emptyMap() } - private fun renderFunctionNode(node: JavadocFunctionNode): PageContent { + + private fun renderAllClassesPage(node: AllClassesPage): TemplateMap { + return mapOf( + "title" to "All Classes", + "list" to node.classEntries + ) + } + + private fun renderTreeViewPage(node: TreeViewPage): TemplateMap { + return mapOf( + "title" to node.title, + "name" to node.name, + "kind" to node.kind, + "list" to node.packages.orEmpty() + node.classes.orEmpty(), + "classGraph" to node.classGraph, + "interfaceGraph" to node.interfaceGraph + ) + } + + private fun renderPackagePageNode(node: JavadocPackagePageNode): TemplateMap { + return mapOf( + "kind" to "package" + ) + renderJavadocContentNode(node.content) + } + + private fun renderFunctionNode(node: JavadocFunctionNode): TemplateMap { val (modifiers, signature) = node.modifiersAndSignature return mapOf( - "signature" to renderContentNode(node.signature), - "brief" to renderContentNode(node.brief), + "signature" to htmlForContentNode(node.signature), + "brief" to htmlForContentNode(node.brief), "parameters" to node.parameters.map { renderParameterNode(it) }, "inlineParameters" to node.parameters.joinToString { "${it.type} ${it.name}" }, - "modifiers" to renderContentNode(modifiers), - "signatureWithoutModifiers" to renderContentNode(signature)) + node.contentMap + "modifiers" to htmlForContentNode(modifiers), + "signatureWithoutModifiers" to htmlForContentNode(signature), + "name" to node.name + ) } - private fun renderParameterNode(node: JavadocParameterNode): PageContent = + private fun renderParameterNode(node: JavadocParameterNode): TemplateMap = mapOf( - "description" to renderContentNode(node.description), - ) + node.contentMap + "description" to htmlForContentNode(node.description), + "name" to node.name, + "type" to node.type + ) - private fun renderClasslikeNode(node: JavadocClasslikePageNode): PageContent = + private fun renderClasslikeNode(node: JavadocClasslikePageNode): TemplateMap = mapOf( "constructors" to node.constructors.map { renderContentNodes(it) }, - "signature" to renderContentNode(node.signature), + "signature" to htmlForContentNode(node.signature), "methods" to renderClasslikeMethods(node.methods), "entries" to node.entries.map { renderEntryNode(it) }, - "properties" to node.properties.map { renderPropertyNode(it)}, + "properties" to node.properties.map { renderPropertyNode(it) }, "classlikes" to node.classlikes.map { renderNestedClasslikeNode(it) }, - "implementedInterfaces" to renderImplementedInterfaces(node) - ) + node.contentMap + "implementedInterfaces" to renderImplementedInterfaces(node), + "kind" to node.kind, + "packageName" to node.packageName + ) + renderJavadocContentNode(node.content) private fun renderImplementedInterfaces(node: JavadocClasslikePageNode) = node.extras[ImplementedInterfaces]?.interfaces?.map { it.displayable() }.orEmpty() - private fun renderClasslikeMethods(nodes: List<JavadocFunctionNode>): PageContent { + private fun renderClasslikeMethods(nodes: List<JavadocFunctionNode>): TemplateMap { val (inherited, own) = nodes.partition { it.extras[InheritedFunction]?.isInherited ?: false } return mapOf( "own" to own.map { renderContentNodes(it) }, - "inherited" to inherited.map { renderInheritedMethod(it) }.groupBy { it["inheritedFrom"] as String }.entries.map { - mapOf("inheritedFrom" to it.key, "names" to it.value.map{ it["name"] as String }.sorted().joinToString() ) - } + "inherited" to inherited.map { renderInheritedMethod(it) } + .groupBy { it["inheritedFrom"] as String }.entries.map { + mapOf( + "inheritedFrom" to it.key, + "names" to it.value.map { it["name"] as String }.sorted().joinToString() + ) + } ) } - private fun renderInheritedMethod(node: JavadocFunctionNode): PageContent { + private fun renderInheritedMethod(node: JavadocFunctionNode): TemplateMap { val inheritedFrom = node.extras[InheritedFunction]?.inheritedFrom return mapOf( "inheritedFrom" to inheritedFrom?.displayable().orEmpty(), @@ -261,38 +297,74 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon ) } - private fun renderNestedClasslikeNode(node: JavadocClasslikePageNode): PageContent { + private fun renderNestedClasslikeNode(node: JavadocClasslikePageNode): TemplateMap { return mapOf( - "modifiers" to (node.modifiers + "static" + node.contentMap["kind"]).joinToString(separator = " "), + "modifiers" to (node.modifiers + "static" + node.kind).joinToString(separator = " "), "signature" to node.name, "description" to node.description ) } - private fun renderPropertyNode(node: JavadocPropertyNode): PageContent { + private fun renderPropertyNode(node: JavadocPropertyNode): TemplateMap { val (modifiers, signature) = node.modifiersAndSignature return mapOf( - "modifiers" to renderContentNode(modifiers), - "signature" to renderContentNode(signature), - "description" to renderContentNode(node.brief) + "modifiers" to htmlForContentNode(modifiers), + "signature" to htmlForContentNode(signature), + "description" to htmlForContentNode(node.brief) ) } - private fun renderEntryNode(node: JavadocEntryNode): PageContent = - mapOf( - "signature" to renderContentNode(node.signature), - ) + node.contentMap + private fun renderEntryNode(node: JavadocEntryNode): TemplateMap { + return mapOf( + "signature" to htmlForContentNode(node.signature), + "brief" to node.brief + ) + } //TODO is it possible to use html renderer? - private fun renderContentNode(node: ContentNode): String = - when(node){ - is ContentGroup -> node.children.joinToString(separator = "") { renderContentNode(it) } + private fun htmlForContentNode(node: ContentNode): String = + when (node) { + is ContentGroup -> node.children.joinToString(separator = "") { htmlForContentNode(it) } is ContentText -> node.text is TextNode -> node.text - is ContentLink -> """<a href="TODO">${node.children.joinToString { renderContentNode(it) }} </a>""" + is ContentLink -> """<a href="TODO">${node.children.joinToString { htmlForContentNode(it) }} </a>""" else -> "" } + private fun renderJavadocContentNode(node: JavadocContentNode): TemplateMap = when (node) { + is TitleNode -> renderTitleNode(node) + is JavadocContentGroup -> renderJavadocContentGroup(node) + is TextNode -> renderTextNode(node) + is ListNode -> renderListNode(node) + else -> emptyMap() + } + + private fun renderTitleNode(node: TitleNode): TemplateMap { + return mapOf( + "title" to node.title, + "version" to node.version, + "packageName" to node.parent + ) + } + + private fun renderJavadocContentGroup(note: JavadocContentGroup): TemplateMap { + return note.children.fold(emptyMap<String, Any?>()) { map, child -> + map + renderJavadocContentNode(child) + } + } + + private fun renderTextNode(node: TextNode): TemplateMap { + return mapOf("text" to node.text) + } + + private fun renderListNode(node: ListNode): TemplateMap { + return mapOf( + "tabTitle" to node.tabTitle, + "colTitle" to node.colTitle, + "list" to node.children + ) + } + private fun DRI.displayable(): String = "${packageName}.${sureClassNames}" }
\ No newline at end of file diff --git a/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt index 1c42adb3..6587e290 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocContentNodes.kt @@ -14,11 +14,9 @@ abstract class JavadocContentNode( kind: Kind, override val sourceSets: Set<SourceSetData> ) : ContentNode { - abstract val contentMap: Map<String, Any?> override val dci: DCI = DCI(dri, kind) override val style: Set<Style> = emptySet() override val extra: PropertyContainer<ContentNode> = PropertyContainer.empty() - override fun withNewExtras(newExtras: PropertyContainer<ContentNode>): ContentNode = this } @@ -47,7 +45,6 @@ class JavadocContentGroup( sourceSets: Set<SourceSetData>, val children: List<JavadocContentNode> ) : JavadocContentNode(dri, kind, sourceSets) { - override val contentMap: Map<String, Any?> by lazy { children.fold(emptyMap<String, Any?>()) { m, cv -> m + cv.contentMap } } companion object { operator fun invoke( @@ -74,16 +71,7 @@ class TitleNode( val kind: Kind, sourceSets: Set<SourceSetData> ) : JavadocContentNode(dri, kind, sourceSets) { - override fun hasAnyContent(): Boolean = !title.isBlank() || !version.isBlank() - - override val contentMap: Map<String, Any?> by lazy { - mapOf( - "title" to title, - "version" to version, - "packageName" to parent - ) - } } fun JavaContentGroupBuilder.title( @@ -100,12 +88,7 @@ data class TextNode( val text: String, override val sourceSets: Set<SourceSetData> ) : JavadocContentNode(emptySet(), ContentKind.Main, sourceSets) { - override fun hasAnyContent(): Boolean = !text.isBlank() - - override val contentMap: Map<String, Any?> = mapOf( - "text" to text, - ) } class ListNode( @@ -116,16 +99,7 @@ class ListNode( val kind: Kind, sourceSets: Set<SourceSetData> ) : JavadocContentNode(dri, kind, sourceSets) { - override fun hasAnyContent(): Boolean = children.isNotEmpty() - - override val contentMap: Map<String, Any?> by lazy { - mapOf( - "tabTitle" to tabTitle, - "colTitle" to colTitle, - "list" to children - ) - } } fun JavaContentGroupBuilder.list( @@ -138,9 +112,6 @@ fun JavaContentGroupBuilder.list( list.add(ListNode(tabTitle, colTitle, children, dri, kind, sourceSets)) } -data class SimpleJavadocListEntry(val content: String) : JavadocListEntry { - override val stringTag: String = content -} class LinkJavadocListEntry( val name: String, @@ -164,19 +135,3 @@ class LinkJavadocListEntry( data class RowJavadocListEntry(val link: LinkJavadocListEntry, val doc: List<ContentNode>) : JavadocListEntry { override val stringTag: String = "" } - -data class CompoundJavadocListEntry( - val name: String, - val content: List<JavadocListEntry> -) : JavadocListEntry { - override val stringTag: String - get() = if (builtString == null) - throw IllegalStateException("stringTag for CompoundJavadocListEntry accessed before build() call") - else builtString!! - - private var builtString: String? = null - - fun build(body: (List<JavadocListEntry>) -> String) { - builtString = body(content) - } -}
\ No newline at end of file diff --git a/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocPageNodes.kt b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocPageNodes.kt index 7f6abb15..c148a440 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocPageNodes.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/pages/JavadocPageNodes.kt @@ -1,7 +1,6 @@ package javadoc.pages import com.intellij.psi.PsiClass -import com.intellij.psi.PsiType import org.jetbrains.dokka.Platform import org.jetbrains.dokka.base.renderers.platforms import org.jetbrains.dokka.links.DRI @@ -13,33 +12,31 @@ import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.resolve.DescriptorUtils.getClassDescriptorForType import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance -interface JavadocPageNode : ContentPage { - val contentMap: Map<String, Any?> -} +interface JavadocPageNode : ContentPage class JavadocModulePageNode( - override val name: String, override val content: JavadocContentNode, override val children: List<PageNode>, + override val name: String, + override val content: JavadocContentNode, + override val children: List<PageNode>, override val dri: Set<DRI> ) : RootPageNode(), JavadocPageNode { - override val contentMap: Map<String, Any?> by lazy { mapOf("kind" to "main") + content.contentMap } val version: String = "0.0.1" - val pathToRoot: String = "" override val documentable: Documentable? = null override val embeddedResources: List<String> = emptyList() - override fun modified(name: String, ch: List<PageNode>): RootPageNode = - JavadocModulePageNode(name, content, ch, dri) + override fun modified(name: String, children: List<PageNode>): RootPageNode = + JavadocModulePageNode(name, content, children, dri) override fun modified( name: String, content: ContentNode, dri: Set<DRI>, embeddedResources: List<String>, - ch: List<PageNode> - ): ContentPage = JavadocModulePageNode(name, content as JavadocContentNode, ch, dri) + children: List<PageNode> + ): ContentPage = JavadocModulePageNode(name, content as JavadocContentNode, children, dri) } class JavadocPackagePageNode( @@ -51,16 +48,16 @@ class JavadocPackagePageNode( override val children: List<PageNode> = emptyList(), override val embeddedResources: List<String> = listOf() ) : JavadocPageNode { - override val contentMap: Map<String, Any?> by lazy { mapOf("kind" to "package") + content.contentMap } + override fun modified( name: String, - ch: List<PageNode> + children: List<PageNode> ): PageNode = JavadocPackagePageNode( name, content, dri, documentable, - ch, + children, embeddedResources ) @@ -69,14 +66,14 @@ class JavadocPackagePageNode( content: ContentNode, dri: Set<DRI>, embeddedResources: List<String>, - ch: List<PageNode> + children: List<PageNode> ): ContentPage = JavadocPackagePageNode( name, content as JavadocContentNode, dri, documentable, - ch, + children, embeddedResources ) } @@ -84,27 +81,18 @@ class JavadocPackagePageNode( data class JavadocEntryNode( val signature: ContentNode, val brief: String -) { - val contentMap: Map<String, Any?> = mapOf( - "brief" to brief - ) -} +) data class JavadocParameterNode( val name: String, val type: String, val description: ContentNode -) { - val contentMap: Map<String, Any?> = mapOf( - "name" to name, - "type" to type - ) -} +) data class JavadocPropertyNode( val signature: ContentNode, val brief: ContentNode -){ +) { val modifiersAndSignature: Pair<ContentNode, ContentNode> get() = (signature as ContentGroup).splitSignatureIntoModifiersAndName() } @@ -115,15 +103,13 @@ data class JavadocFunctionNode( val parameters: List<JavadocParameterNode>, override val name: String, override val dri: Set<DRI> = emptySet(), - override val content: ContentNode = EmptyNode(DRI.topLevel, ContentKind.Classlikes, emptySet()), override val children: List<PageNode> = emptyList(), override val documentable: Documentable? = null, override val embeddedResources: List<String> = emptyList(), val extras: PropertyContainer<DFunction> = PropertyContainer.empty() -): JavadocPageNode { - override val contentMap: Map<String, Any?> = mapOf( - "name" to name - ) +) : JavadocPageNode { + + override val content: ContentNode = EmptyNode(DRI.topLevel, ContentKind.Classlikes, emptySet()) override fun modified( name: String, @@ -160,19 +146,30 @@ class JavadocClasslikePageNode( override val embeddedResources: List<String> = listOf(), val extras: PropertyContainer<Documentable>, ) : JavadocPageNode { - override val contentMap: Map<String, Any?> by lazy { - mapOf( - "kind" to documentable?.kind(), - "name" to name, - "package" to dri.first().packageName, - "classlikeDocumentation" to description - ) + content.contentMap - } + + val kind: String? = documentable?.kind() + val packageName = dri.first().packageName override fun modified( name: String, children: List<PageNode> - ): PageNode = JavadocClasslikePageNode(name, content, dri, modifiers, signature, description, constructors, methods, entries, classlikes, properties, documentable, children, embeddedResources, extras) + ): PageNode = JavadocClasslikePageNode( + name, + content, + dri, + modifiers, + signature, + description, + constructors, + methods, + entries, + classlikes, + properties, + documentable, + children, + embeddedResources, + extras + ) override fun modified( name: String, @@ -181,16 +178,28 @@ class JavadocClasslikePageNode( embeddedResources: List<String>, children: List<PageNode> ): ContentPage = - JavadocClasslikePageNode(name, content as JavadocContentNode, dri, modifiers, signature, description, constructors, methods, entries, classlikes, properties, documentable, children, embeddedResources, extras) + JavadocClasslikePageNode( + name, + content as JavadocContentNode, + dri, + modifiers, + signature, + description, + constructors, + methods, + entries, + classlikes, + properties, + documentable, + children, + embeddedResources, + extras + ) } class AllClassesPage(val classes: List<JavadocClasslikePageNode>) : JavadocPageNode { - val classEntries = classes.map { LinkJavadocListEntry(it.name, it.dri, ContentKind.Classlikes, it.platforms().toSet()) } - - override val contentMap: Map<String, Any?> = mapOf( - "title" to "All Classes", - "list" to classEntries - ) + val classEntries = + classes.map { LinkJavadocListEntry(it.name, it.dri, ContentKind.Classlikes, it.platforms().toSet()) } override val name: String = "All Classes" override val dri: Set<DRI> = setOf(DRI.topLevel) @@ -239,25 +248,20 @@ class TreeViewPage( private val descriptorMap = getDescriptorMap() private val inheritanceTuple = generateInheritanceTree() - private val classGraph = inheritanceTuple.first - private val interfaceGraph = inheritanceTuple.second + internal val classGraph = inheritanceTuple.first + internal val interfaceGraph = inheritanceTuple.second override val children: List<PageNode> = emptyList() - override val contentMap: Map<String, Any?> = mapOf( - "title" to (when (documentable) { - is DPackage -> "$name Class Hierarchy" - else -> "All packages" - }), - "name" to name, - "kind" to (when (documentable) { - is DPackage -> "package" - else -> "main" - }), - "list" to packages.orEmpty() + classes.orEmpty(), - "classGraph" to classGraph, - "interfaceGraph" to interfaceGraph - ) + val title = when (documentable) { + is DPackage -> "$name Class Hierarchy" + else -> "All packages" + } + + val kind = when (documentable) { + is DPackage -> "package" + else -> "main" + } override fun modified( name: String, @@ -314,17 +318,16 @@ class TreeViewPage( ) fun classTreeRec(node: InheritanceNode): List<InheritanceNode> = if (node.isInterface) { - node.children.flatMap (::classTreeRec) - } - else { - listOf(node.copy(children = node.children.flatMap (::classTreeRec))) + node.children.flatMap(::classTreeRec) + } else { + listOf(node.copy(children = node.children.flatMap(::classTreeRec))) } + fun classTree(node: InheritanceNode) = classTreeRec(node).singleOrNull() fun interfaceTreeRec(node: InheritanceNode): List<InheritanceNode> = if (node.isInterface) { listOf(node.copy(children = node.children.filter { it.isInterface })) - } - else { + } else { node.children.flatMap(::interfaceTreeRec) } @@ -341,9 +344,9 @@ class TreeViewPage( .let { it + it.map { it.second to null } } - .groupBy({it.first}) {it.second} + .groupBy({ it.first }) { it.second } .map { it.key to it.value.filterNotNull().distinct() } - .map { (k,v) -> + .map { (k, v) -> InheritanceNode( DRI.from(k), v.map { InheritanceNode(DRI.from(it)) }, @@ -353,14 +356,14 @@ class TreeViewPage( } - val descriptorInheritanceTree = descriptorMap.flatMap { - (_,v) -> v.typeConstructor.supertypes - .map { getClassDescriptorForType(it) to v } + val descriptorInheritanceTree = descriptorMap.flatMap { (_, v) -> + v.typeConstructor.supertypes + .map { getClassDescriptorForType(it) to v } } .let { it + it.map { it.second to null } } - .groupBy ({ it.first }) { it.second } + .groupBy({ it.first }) { it.second } .map { it.key to it.value.filterNotNull().distinct() } .map { (k, v) -> InheritanceNode( @@ -426,18 +429,17 @@ class TreeViewPage( } } -interface ContentValue -data class StringValue(val text: String) : ContentValue -data class ListValue(val list: List<String>) : ContentValue - private fun ContentGroup.splitSignatureIntoModifiersAndName(): Pair<ContentNode, ContentNode> { val signature = children.firstIsInstance<ContentGroup>() val modifiers = signature.children.takeWhile { it !is ContentLink } - return Pair(signature.copy(children = modifiers), signature.copy(children = signature.children.drop(modifiers.size))) + return Pair( + signature.copy(children = modifiers), + signature.copy(children = signature.children.drop(modifiers.size)) + ) } private fun Documentable.kind(): String? = - when(this){ + when (this) { is DClass -> "class" is DEnum -> "enum" is DAnnotation -> "annotation" diff --git a/plugins/javadoc/src/main/kotlin/javadoc/pages/htmlPreprocessors.kt b/plugins/javadoc/src/main/kotlin/javadoc/pages/htmlPreprocessors.kt index 8795f359..3ccd1d71 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/pages/htmlPreprocessors.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/pages/htmlPreprocessors.kt @@ -35,7 +35,7 @@ object TreeViewInstaller : PageTransformer { root = root ) - return node.modified(ch = node.children.map { node -> install(node, root) } + overviewTree) as JavadocModulePageNode + return node.modified(children = node.children.map { node -> install(node, root) } + overviewTree) as JavadocModulePageNode } private fun installPackageTreeNode(node: JavadocPackagePageNode, root: RootPageNode): JavadocPackagePageNode { @@ -48,7 +48,7 @@ object TreeViewInstaller : PageTransformer { root = root ) - return node.modified(ch = node.children + packageTree) as JavadocPackagePageNode + return node.modified(children = node.children + packageTree) as JavadocPackagePageNode } } |