diff options
6 files changed, 175 insertions, 170 deletions
diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index e69de29b..00000000 --- a/.idea/compiler.xml +++ /dev/null diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index e69de29b..00000000 --- a/.idea/misc.xml +++ /dev/null diff --git a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt index 4764fbcb..9dc87d91 100644 --- a/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt +++ b/plugins/base/src/main/kotlin/translators/descriptors/DefaultDescriptorToDocumentableTranslator.kt @@ -554,19 +554,15 @@ private class DokkaDescriptorVisitor( getDocumentation()?.toSourceSetDependent() ?: emptyMap() private fun ClassDescriptor.resolveClassDescriptionData(): ClassInfo { - val superClasses = hashSetOf<ClassDescriptor>() - + val interfaces = hashSetOf<DRI>() fun processSuperClasses(supers: List<ClassDescriptor>) { supers.forEach { - superClasses.add(it) + if(it.kind == ClassKind.INTERFACE) interfaces.add(DRI.from(it)) processSuperClasses(it.getSuperInterfaces() + it.getAllSuperclassesWithoutAny()) } } processSuperClasses(getSuperInterfaces() + getAllSuperclassesWithoutAny()) - return ClassInfo( - superClasses.map { Supertype(DRI.from(it), it.kind == ClassKind.INTERFACE) }.toList(), - resolveDescriptorData() - ) + return ClassInfo(getAllSuperclassesWithoutAny().map { DRI.from(it) }, interfaces.toList(), resolveDescriptorData()) } private fun TypeParameterDescriptor.toTypeParameter() = @@ -739,12 +735,9 @@ private class DokkaDescriptorVisitor( private fun ValueArgument.childrenAsText() = this.safeAs<KtValueArgument>()?.children?.map {it.text }.orEmpty() - private data class ClassInfo(private val allSupertypes: List<Supertype>, val docs: SourceSetDependent<DocumentationNode>){ + private data class ClassInfo(val superclasses: List<DRI>, val interfaces: List<DRI>, val docs: SourceSetDependent<DocumentationNode>){ val supertypes: List<DRI> - get() = allSupertypes.map { it.dri } - - val interfaces: List<DRI> - get() = allSupertypes.filter { it.isInterface }.map { it.dri } + get() = (superclasses + interfaces).distinct() } private fun Visibility.toDokkaVisibility(): org.jetbrains.dokka.model.Visibility = when (this) { @@ -759,8 +752,6 @@ private class DokkaDescriptorVisitor( "${this.enumClassId.relativeClassName.asString()}.${this.enumEntryName.identifier}" private fun fallbackPackageName(): String = "[${sourceSet.displayName} root]"// TODO: error-prone, find a better way to do it - - private data class Supertype(val dri: DRI, val isInterface: Boolean) } private fun DRI.withPackageFallbackTo(fallbackPackage: String): DRI { diff --git a/plugins/base/src/test/kotlin/model/ClassesTest.kt b/plugins/base/src/test/kotlin/model/ClassesTest.kt index 6d17fdd1..979ea89b 100644 --- a/plugins/base/src/test/kotlin/model/ClassesTest.kt +++ b/plugins/base/src/test/kotlin/model/ClassesTest.kt @@ -258,7 +258,7 @@ class ClassesTest : AbstractModelTest("/src/main/kotlin/classes/Test.kt", "class modifier.values.forEach { it equals Final } } - D.supers.firstOrNull() equals C.dri + D.supers.single() equals C.dri E.supers.firstOrNull() equals D.dri } } diff --git a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt index 1f744fba..b4bc19ca 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/JavadocPageCreator.kt @@ -74,7 +74,7 @@ open class JavadocPageCreator( m.sourceSets.filter { it.platform == Platform.jvm }.toSet() ) { title(m.name, "0.0.1", dri = setOf(m.dri), kind = ContentKind.Main) - list("Packages", "Package", setOf(m.dri), ContentKind.Packages, m.packages.map { p -> + list("Packages", "Package", setOf(m.dri), ContentKind.Packages, m.packages.sortedBy { it.name }.map { p -> val description = p.documentation.entries.find { (k, _) -> k.platform == Platform.jvm }?.value?.let { it.children.firstIsInstanceOrNull<Description>()?.let { description -> DocTagToContentConverter.buildContent( @@ -98,7 +98,7 @@ open class JavadocPageCreator( p.sourceSets.filter { it.platform == Platform.jvm }.toSet() ) { title(p.name, "0.0.1", dri = setOf(p.dri), kind = ContentKind.Packages) - list("Packages", "Package", setOf(p.dri), ContentKind.Packages, p.classlikes.map { c -> + list("Packages", "Package", setOf(p.dri), ContentKind.Packages, p.classlikes.sortedBy { it.name }.map { c -> RowJavadocListEntry( LinkJavadocListEntry(c.name.orEmpty(), setOf(c.dri), JavadocContentKind.Class, sourceSets), listOf(signatureProvider.signature(c)) diff --git a/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt b/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt index 600cdd99..370ee68b 100644 --- a/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt +++ b/plugins/javadoc/src/main/kotlin/javadoc/KorteJavadocRenderer.kt @@ -12,6 +12,7 @@ import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.sureClassNames import org.jetbrains.dokka.model.ImplementedInterfaces import org.jetbrains.dokka.model.InheritedFunction +import org.jetbrains.dokka.model.SourceSetData import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.renderers.Renderer @@ -59,7 +60,7 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon "docName" to "docName", // todo docname "pathToRoot" to pathToRoot, "kind" to "main", - ) + renderJavadocContentNode(node.content) + ) + ContentNodesRenderer(pathToRoot).renderJavadocContentNode(node.content) writeFromTemplate(outputWriter, "$link/$name".toNormalized(), "tabPage.korte", contentMap.toList()) node.children.forEach { renderNode(it, link) } @@ -76,7 +77,7 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon "docName" to "docName", // todo docname "pathToRoot" to pathToRoot, "dir" to dir - ) + renderContentNodes(node) + ) + ContentNodesRenderer(dir).renderContentNodes(node) writeFromTemplate(outputWriter, link, templateForNode(node), contentMap.toList()) node.children.forEach { renderNode(it, link.toNormalized()) } } @@ -96,12 +97,6 @@ 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 LinkJavadocListEntry.toLinkTag(parent: String? = null) = - createLinkTag(locationProvider.resolve(dri.first(), sourceSets.toList()).let { - if (parent != null) it.relativizePath(parent) - else it - }, name) - fun DRI.toLink(context: PageNode? = null) = locationProvider.resolve(this, emptyList(), context) fun createLinkTag(address: String, name: String) = @@ -109,7 +104,6 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon """<a href="$it">$name</a>""" } - private fun String.parent() = Paths.get(this).parent.toNormalized() private fun Path.toNormalized() = this.normalize().toFile().toString() private fun String.toNormalized() = Paths.get(this).toNormalized() private fun String.relativizePath(parent: String) = Paths.get(parent).relativize(Paths.get(this)).toNormalized() @@ -125,9 +119,8 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon writer.writeHtml(path, tmp) } - - private fun htmlForContentNodes(content: List<ContentNode>): String = - content.joinToString("") { htmlForContentNode(it) } + private fun htmlForContentNodes(content: List<ContentNode>, render: (ContentNode) -> String): String = + content.joinToString("") { render(it) } fun getTemplateConfig() = TemplateConfig().also { config -> listOf( @@ -139,15 +132,15 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon TeFunction("createTabRow") { args -> val (link, doc) = args.first() as RowJavadocListEntry val dir = args[1] as String? + val renderer = ContentNodesRenderer(dir) (createLinkTag( locationProvider.resolve(link, dir.orEmpty()), link.name - ) to htmlForContentNodes(doc)).pairToTag().trim() + ) to htmlForContentNodes(doc, renderer::htmlForContentNode)).pairToTag().trim() }, TeFunction("createListRow") { args -> val link = args.first() as LinkJavadocListEntry val dir = args[1] as String? -// link.toLinkTag(dir) createLinkTag(locationProvider.resolve(link, dir.orEmpty()), link.name) }, TeFunction("createPackageHierarchy") { args -> @@ -205,171 +198,192 @@ class KorteJavadocRenderer(val outputWriter: OutputWriter, val context: DokkaCon ?.joinToString("\n") ?: throw IllegalStateException("Template not found: $basePath/$template") } - private fun renderContentNodes(node: JavadocPageNode): TemplateMap = - when (node) { - is JavadocClasslikePageNode -> renderClasslikeNode(node) - is JavadocFunctionNode -> renderFunctionNode(node) - is JavadocPackagePageNode -> renderPackagePageNode(node) - is TreeViewPage -> renderTreeViewPage(node) - is AllClassesPage -> renderAllClassesPage(node) - else -> emptyMap() - } + private inner class ContentNodesRenderer(private val currentLocation: String?) { + fun renderContentNodes(node: JavadocPageNode): TemplateMap = + when (node) { + is JavadocClasslikePageNode -> renderClasslikeNode(node) + is JavadocFunctionNode -> renderFunctionNode(node) + is JavadocPackagePageNode -> renderPackagePageNode(node) + is TreeViewPage -> renderTreeViewPage(node) + is AllClassesPage -> renderAllClassesPage(node) + else -> emptyMap() + } - private fun renderAllClassesPage(node: AllClassesPage): TemplateMap { - return mapOf( - "title" to "All Classes", - "list" to node.classEntries - ) - } + 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 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 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 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 htmlForContentNode(modifiers), - "signatureWithoutModifiers" to htmlForContentNode(signature), - "name" to node.name - ) - } + private fun renderFunctionNode(node: JavadocFunctionNode): TemplateMap { + val (modifiers, signature) = node.modifiersAndSignature + return mapOf( + "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 htmlForContentNode(modifiers), + "signatureWithoutModifiers" to htmlForContentNode(signature), + "name" to node.name + ) + } - private fun renderParameterNode(node: JavadocParameterNode): TemplateMap = - mapOf( - "description" to htmlForContentNode(node.description), - "name" to node.name, - "type" to node.type - ) - - private fun renderClasslikeNode(node: JavadocClasslikePageNode): TemplateMap = - mapOf( - "constructors" to node.constructors.map { renderContentNodes(it) }, - "signature" to htmlForContentNode(node.signature), - "methods" to renderClasslikeMethods(node.methods), - "entries" to node.entries.map { renderEntryNode(it) }, - "properties" to node.properties.map { renderPropertyNode(it) }, - "classlikes" to node.classlikes.map { renderNestedClasslikeNode(it) }, - "implementedInterfaces" to renderImplementedInterfaces(node), - "kind" to node.kind, - "packageName" to node.packageName - ) + renderJavadocContentNode(node.content) - - private fun renderImplementedInterfaces(node: JavadocClasslikePageNode) = - node.extras[ImplementedInterfaces]?.interfaces?.entries?.firstOrNull { it.key.platform == Platform.jvm }?.value?.map { it.displayable() } // TODO: REMOVE HARDCODED JVM DEPENDENCY + private fun renderParameterNode(node: JavadocParameterNode): TemplateMap = + mapOf( + "description" to htmlForContentNode(node.description), + "name" to node.name, + "type" to node.type + ) + + private fun renderClasslikeNode(node: JavadocClasslikePageNode): TemplateMap = + mapOf( + "constructors" to node.constructors.map { renderContentNodes(it) }, + "signature" to htmlForContentNode(node.signature), + "methods" to renderClasslikeMethods(node.methods), + "entries" to node.entries.map { renderEntryNode(it) }, + "properties" to node.properties.map { renderPropertyNode(it) }, + "classlikes" to node.classlikes.map { renderNestedClasslikeNode(it) }, + "implementedInterfaces" to renderImplementedInterfaces(node), + "kind" to node.kind, + "packageName" to node.packageName, + "name" to node.name + ) + renderJavadocContentNode(node.content) + + private fun renderImplementedInterfaces(node: JavadocClasslikePageNode) = + node.extras[ImplementedInterfaces]?.interfaces?.entries?.firstOrNull { it.key.platform == Platform.jvm }?.value?.map { it.displayable() } // TODO: REMOVE HARDCODED JVM DEPENDENCY .orEmpty() - private fun renderClasslikeMethods(nodes: List<JavadocFunctionNode>): TemplateMap { - val (inherited, own) = nodes.partition { it.extras[InheritedFunction]?.inheritedFrom?.any { - it.key.platform == Platform.jvm // TODO: REMOVE HARDCODED JVM DEPENDENCY - } ?: false } - return mapOf( - "own" to own.map { renderContentNodes(it) }, - "inherited" to inherited.map { renderInheritedMethod(it) } - .groupBy { it["inheritedFrom"] as String }.entries.map { + private fun renderClasslikeMethods(nodes: List<JavadocFunctionNode>): TemplateMap { + val (inherited, own) = nodes.partition { + val extra = it.extras[InheritedFunction] + extra?.inheritedFrom?.keys?.first { it.platform == Platform.jvm }?.let { jvm -> + extra.isInherited(jvm) + } ?: 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() ) } - ) - } + ) + } - private fun renderInheritedMethod(node: JavadocFunctionNode): TemplateMap { - val inheritedFrom = node.extras[InheritedFunction]?.inheritedFrom - return mapOf( - "inheritedFrom" to inheritedFrom?.entries?.firstOrNull { it.key.platform == Platform.jvm }?.value?.displayable() // TODO: REMOVE HARDCODED JVM DEPENDENCY + private fun renderInheritedMethod(node: JavadocFunctionNode): TemplateMap { + val inheritedFrom = node.extras[InheritedFunction]?.inheritedFrom + return mapOf( + "inheritedFrom" to inheritedFrom?.entries?.firstOrNull { it.key.platform == Platform.jvm }?.value?.displayable() // TODO: REMOVE HARDCODED JVM DEPENDENCY .orEmpty(), - "name" to node.name - ) - } + "name" to node.name + ) + } - private fun renderNestedClasslikeNode(node: JavadocClasslikePageNode): TemplateMap { - return mapOf( - "modifiers" to (node.modifiers + "static" + node.kind).joinToString(separator = " "), - "signature" to node.name, - "description" to node.description - ) - } + private fun renderNestedClasslikeNode(node: JavadocClasslikePageNode): TemplateMap { + return mapOf( + "modifiers" to (node.modifiers + "static" + node.kind).joinToString(separator = " "), + "signature" to node.name, + "description" to node.description + ) + } - private fun renderPropertyNode(node: JavadocPropertyNode): TemplateMap { - val (modifiers, signature) = node.modifiersAndSignature - return mapOf( - "modifiers" to htmlForContentNode(modifiers), - "signature" to htmlForContentNode(signature), - "description" to htmlForContentNode(node.brief) - ) - } + private fun renderPropertyNode(node: JavadocPropertyNode): TemplateMap { + val (modifiers, signature) = node.modifiersAndSignature + return mapOf( + "modifiers" to htmlForContentNode(modifiers), + "signature" to htmlForContentNode(signature), + "description" to htmlForContentNode(node.brief) + ) + } - private fun renderEntryNode(node: JavadocEntryNode): TemplateMap { - return mapOf( - "signature" to htmlForContentNode(node.signature), - "brief" to node.brief - ) - } + private fun renderEntryNode(node: JavadocEntryNode): TemplateMap { + return mapOf( + "signature" to htmlForContentNode(node.signature), + "brief" to node.brief + ) + } + fun htmlForContentNode(node: ContentNode): String = + when (node) { + is ContentGroup -> node.children.joinToString(separator = "") { htmlForContentNode(it) } + is ContentText -> node.text + is TextNode -> node.text + is ContentDRILink -> """<a href="${resolveLink( + node.address, + node.sourceSets + )}">${node.children.joinToString { htmlForContentNode(it) }} </a>""".trimMargin() + else -> "" + } - //TODO is it possible to use html renderer? - 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 { htmlForContentNode(it) }} </a>""" - else -> "" + 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 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 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 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 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 renderListNode(node: ListNode): TemplateMap { - return mapOf( - "tabTitle" to node.tabTitle, - "colTitle" to node.colTitle, - "list" to node.children - ) - } + private fun resolveLink(address: DRI, sourceSets: Set<SourceSetData>) = + locationProvider.resolve(address, sourceSets.toList()).let { + val afterFormattingToHtml = formatToEndWithHtml(it) + if (currentLocation != null) afterFormattingToHtml.relativizePath(currentLocation) + else afterFormattingToHtml + } - private fun DRI.displayable(): String = "${packageName}.${sureClassNames}" + private fun formatToEndWithHtml(address: String) = + if (address.endsWith(".html")) { + address + } else { + "$address.html" + } + + private fun DRI.displayable(): String = "${packageName}.${sureClassNames}" + } }
\ No newline at end of file |