diff options
author | Błażej Kardyś <bkardys@virtuslab.com> | 2019-11-07 08:21:43 +0100 |
---|---|---|
committer | Błażej Kardyś <bkardys@virtuslab.com> | 2019-11-08 18:47:43 +0100 |
commit | 493951f487910a1306a4129b7e8144e679c0213c (patch) | |
tree | 15ac0502e76c0a327bb835e31d0e65f499928ec1 /core/src/main | |
parent | 0627b9dd15171db221bee2e5a6b0082aec813c98 (diff) | |
download | dokka-493951f487910a1306a4129b7e8144e679c0213c.tar.gz dokka-493951f487910a1306a4129b7e8144e679c0213c.tar.bz2 dokka-493951f487910a1306a4129b7e8144e679c0213c.zip |
Moving platform merging to documentationNodes
Diffstat (limited to 'core/src/main')
-rw-r--r-- | core/src/main/kotlin/DokkaDescriptorVisitor.kt | 56 | ||||
-rw-r--r-- | core/src/main/kotlin/DokkaGenerator.kt | 33 | ||||
-rw-r--r-- | core/src/main/kotlin/Model/DocumentationNode.kt | 51 | ||||
-rw-r--r-- | core/src/main/kotlin/Model/transformers/DocumentationNodeTransformer.kt | 1 | ||||
-rw-r--r-- | core/src/main/kotlin/Model/transformers/DocumentationNodesMerger.kt (renamed from core/src/main/kotlin/Model/transformers/ActualExpectedMerger.kt) | 39 | ||||
-rw-r--r-- | core/src/main/kotlin/pages/MarkdownToContentConverter.kt | 38 | ||||
-rw-r--r-- | core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt | 27 | ||||
-rw-r--r-- | core/src/main/kotlin/transformers/DocumentationToPageTransformer.kt | 2 | ||||
-rw-r--r-- | core/src/main/kotlin/transformers/TopDownPageNodeMerger.kt | 50 |
9 files changed, 141 insertions, 156 deletions
diff --git a/core/src/main/kotlin/DokkaDescriptorVisitor.kt b/core/src/main/kotlin/DokkaDescriptorVisitor.kt index c98c63dd..63d3ea20 100644 --- a/core/src/main/kotlin/DokkaDescriptorVisitor.kt +++ b/core/src/main/kotlin/DokkaDescriptorVisitor.kt @@ -6,14 +6,20 @@ import org.jetbrains.dokka.links.Callable import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.links.withClass import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.FAKE_OVERRIDE +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED import org.jetbrains.kotlin.descriptors.impl.DeclarationDescriptorVisitorEmptyBodies +import org.jetbrains.kotlin.idea.kdoc.findKDoc +import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink +import org.jetbrains.kotlin.kdoc.psi.impl.KDocLink +import org.jetbrains.kotlin.kdoc.psi.impl.KDocName import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter import org.jetbrains.kotlin.resolve.scopes.MemberScope -import org.jetbrains.kotlin.idea.kdoc.findKDoc -import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.FAKE_OVERRIDE -import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor.Kind.SYNTHESIZED -object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies<DocumentationNode<*>, DRI>() { +class DokkaDescriptorVisitor( + val platform: List<String>, + private val resolutionFacade: DokkaResolutionFacade +) : DeclarationDescriptorVisitorEmptyBodies<DocumentationNode<*>, DRI>() { override fun visitDeclarationDescriptor(descriptor: DeclarationDescriptor, parent: DRI): Nothing { throw IllegalStateException("${javaClass.simpleName} should never enter ${descriptor.javaClass.simpleName}") } @@ -35,6 +41,9 @@ object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies<Document override fun visitClassDescriptor(descriptor: ClassDescriptor, parent: DRI): Class { val dri = parent.withClass(descriptor.name.asString()) val scope = descriptor.getMemberScope(emptyList()) + val kdoc = descriptor.findKDoc()?.let { + parseMarkdown(it.text) + } return Class( dri, descriptor.name.asString(), @@ -42,8 +51,8 @@ object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies<Document scope.functions(dri), scope.properties(dri), scope.classes(dri), - listOfNotNull(descriptor.findKDoc()), - listOf(descriptor) + descriptor.takeIf { it.isExpect }?.resolveDescriptorData(), + listOfNotNull(descriptor.takeUnless { it.isExpect }?.resolveDescriptorData()) ) } @@ -53,8 +62,8 @@ object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies<Document dri, descriptor.name.asString(), descriptor.extensionReceiverParameter?.let { visitReceiverParameterDescriptor(it, dri) }, - listOfNotNull(descriptor.findKDoc()), - listOf(descriptor) + descriptor.takeIf { it.isExpect }?.resolveDescriptorData(), + listOfNotNull(descriptor.takeUnless { it.isExpect }?.resolveDescriptorData()) ) } @@ -65,8 +74,8 @@ object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies<Document descriptor.name.asString(), descriptor.extensionReceiverParameter?.let { visitReceiverParameterDescriptor(it, dri) }, descriptor.valueParameters.mapIndexed { index, desc -> parameter(index, desc, dri) }, - listOfNotNull(descriptor.findKDoc()), - listOf(descriptor) + descriptor.takeIf { it.isExpect }?.resolveDescriptorData(), + listOfNotNull(descriptor.takeUnless { it.isExpect }?.resolveDescriptorData()) ) } @@ -77,8 +86,8 @@ object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies<Document "<init>", null, descriptor.valueParameters.mapIndexed { index, desc -> parameter(index, desc, dri) }, - listOfNotNull(descriptor.findKDoc()), - listOf(descriptor) + descriptor.takeIf { it.isExpect }?.resolveDescriptorData(), + listOfNotNull(descriptor.takeUnless { it.isExpect }?.resolveDescriptorData()) ) } @@ -88,20 +97,18 @@ object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies<Document ) = Parameter( parent.copy(target = 0), null, - listOfNotNull(descriptor.findKDoc()), - listOf(descriptor) + listOf(descriptor.resolveDescriptorData()) ) private fun parameter(index: Int, descriptor: ValueParameterDescriptor, parent: DRI) = Parameter( parent.copy(target = index + 1), descriptor.name.asString(), - listOfNotNull(descriptor.findKDoc()), - listOf(descriptor) + listOf(descriptor.resolveDescriptorData()) ) private val FunctionDescriptor.isSynthetic: Boolean - get() = (kind == FAKE_OVERRIDE || kind == SYNTHESIZED) && findKDoc() == null + get() = (kind == FAKE_OVERRIDE || kind == SYNTHESIZED) && findKDoc() == null private fun MemberScope.functions(parent: DRI): List<Function> = getContributedDescriptors(DescriptorKindFilter.FUNCTIONS) { true } @@ -118,4 +125,19 @@ object DokkaDescriptorVisitor : DeclarationDescriptorVisitorEmptyBodies<Document getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS) { true } .filterIsInstance<ClassDescriptor>() .map { visitClassDescriptor(it, parent) } + + private fun <T : DeclarationDescriptor> T.resolveDescriptorData(): Descriptor<T> { + val doc = findKDoc() + val links = doc?.children?.filter { it is KDocLink }?.flatMap { link -> + val destination = link.children.first { it is KDocName }.text + resolveKDocLink( + resolutionFacade.resolveSession.bindingContext, + resolutionFacade, + this, + null, + destination.split('.') + ).map { Pair(destination, DRI.from(it)) } + }?.toMap() ?: emptyMap() + return Descriptor(this, doc, links, platform) + } } diff --git a/core/src/main/kotlin/DokkaGenerator.kt b/core/src/main/kotlin/DokkaGenerator.kt index 69c6fa41..f5e8b832 100644 --- a/core/src/main/kotlin/DokkaGenerator.kt +++ b/core/src/main/kotlin/DokkaGenerator.kt @@ -1,18 +1,15 @@ package org.jetbrains.dokka import org.jetbrains.dokka.Model.Module +import org.jetbrains.dokka.Model.transformers.DocumentationNodesMerger import org.jetbrains.dokka.Utilities.genericPretty -import org.jetbrains.dokka.Model.transformers.ActualExpectedMerger import org.jetbrains.dokka.Utilities.pretty import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.pages.MarkdownToContentConverter -import org.jetbrains.dokka.pages.ModulePageNode -import org.jetbrains.dokka.pages.PageNode import org.jetbrains.dokka.renderers.FileWriter import org.jetbrains.dokka.renderers.HtmlRenderer import org.jetbrains.dokka.resolvers.DefaultLocationProvider import org.jetbrains.dokka.transformers.DefaultDocumentationToPageTransformer -import org.jetbrains.dokka.transformers.TopDownPageNodeMerger import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity import org.jetbrains.kotlin.cli.common.messages.MessageCollector @@ -41,23 +38,28 @@ class DokkaGenerator( val environment = createCoreEnvironment() val (facade, _) = createResolutionFacade(environment) - val markdownConverter = MarkdownToContentConverter(facade, logger) - - val module = environment.getSourceFiles().asSequence() + environment.getSourceFiles().asSequence() .map { it.packageFqName } .distinct() .mapNotNull { facade.resolveSession.getPackageFragment(it) } - .map { DokkaDescriptorVisitor.visitPackageFragmentDescriptor(it, DRI.topLevel) } + .map { + DokkaDescriptorVisitor(pass.targets, facade).visitPackageFragmentDescriptor( + it, + DRI.topLevel + ) + } .toList() .let { Module(it) } - .let { ActualExpectedMerger(it) } + .let { DocumentationNodesMerger(it) } .also { println("${pass.analysisPlatform}:\n${it.pretty()}\n\n") } - - DefaultDocumentationToPageTransformer(markdownConverter, logger).transform(pass, module) } + }.let { + val markdownConverter = MarkdownToContentConverter(logger) + it.forEach { it.genericPretty().also(::nierzigoj) } + DefaultDocumentationToPageTransformer(markdownConverter, logger).transform(DocumentationNodesMerger(it)) } - .merge() .also { + it.genericPretty().also(::nierzigoj) HtmlRenderer( FileWriter(configuration.outputDir, ""), DefaultLocationProvider(it, configuration, ".${configuration.format}") @@ -66,12 +68,7 @@ class DokkaGenerator( } } -private fun Iterable<ModulePageNode>.merge(): PageNode { - this.forEach { it.genericPretty().also(::println) } - return TopDownPageNodeMerger().mergeModules(this).also { - it.genericPretty().also(::println) - } -} +private fun nierzigoj(niczym: String) {} private class DokkaMessageCollector(private val logger: DokkaLogger) : MessageCollector { override fun clear() { diff --git a/core/src/main/kotlin/Model/DocumentationNode.kt b/core/src/main/kotlin/Model/DocumentationNode.kt index 99764fac..7efe6818 100644 --- a/core/src/main/kotlin/Model/DocumentationNode.kt +++ b/core/src/main/kotlin/Model/DocumentationNode.kt @@ -5,10 +5,7 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag class Module(val packages: List<Package>) : DocumentationNode<Nothing>() { - override val docTags: List<KDocTag> = emptyList() - override val dri: DRI = DRI.topLevel - override val children: List<Package> = packages } @@ -19,8 +16,6 @@ class Package( override val classes: List<Class> ) : ScopeNode<Nothing>() { val name = dri.packageName.orEmpty() - - override val docTags: List<KDocTag> = emptyList() } class Class( @@ -30,8 +25,8 @@ class Class( override val functions: List<Function>, override val properties: List<Property>, override val classes: List<Class>, - override val docTags: List<KDocTag>, - override val descriptors: List<ClassDescriptor> + override val expectDescriptor: Descriptor<ClassDescriptor>?, + override val actualDescriptors: List<Descriptor<ClassDescriptor>> ) : ScopeNode<ClassDescriptor>() class Function( @@ -39,8 +34,8 @@ class Function( val name: String, override val receiver: Parameter?, val parameters: List<Parameter>, - override val docTags: List<KDocTag>, - override val descriptors: List<FunctionDescriptor> + override val expectDescriptor: Descriptor<FunctionDescriptor>?, + override val actualDescriptors: List<Descriptor<FunctionDescriptor>> ) : CallableNode<FunctionDescriptor>() { override val children: List<Parameter> get() = listOfNotNull(receiver) + parameters @@ -50,8 +45,8 @@ class Property( override val dri: DRI, val name: String, override val receiver: Parameter?, - override val docTags: List<KDocTag>, - override val descriptors: List<PropertyDescriptor> + override val expectDescriptor: Descriptor<PropertyDescriptor>?, + override val actualDescriptors: List<Descriptor<PropertyDescriptor>> ) : CallableNode<PropertyDescriptor>() { override val children: List<Parameter> get() = listOfNotNull(receiver) @@ -61,35 +56,51 @@ class Property( class Parameter( override val dri: DRI, val name: String?, - override val docTags: List<KDocTag>, - override val descriptors: List<ParameterDescriptor> + override val actualDescriptors: List<Descriptor<ParameterDescriptor>> ) : DocumentationNode<ParameterDescriptor>() { override val children: List<DocumentationNode<*>> get() = emptyList() } -abstract class DocumentationNode<out T : DeclarationDescriptor> { - open val descriptors: List<T> = emptyList() +class Descriptor<out T : DeclarationDescriptor>( + val descriptor: T, + val docTag: KDocTag?, + val links: Map<String, DRI>, + val passes: List<String> +) : DeclarationDescriptor by descriptor { + + override fun equals(other: Any?): Boolean = + other is Descriptor<*> && ( + descriptor.toString() == other.descriptor.toString() && + docTag?.text == other.docTag?.text && + links == other.links) + + override fun hashCode(): Int = + listOf(descriptor.toString(), docTag?.text, links).hashCode() +} - abstract val docTags: List<KDocTag> // TODO: replace in the future with more robust doc-comment model +abstract class DocumentationNode<out T : DeclarationDescriptor> { + open val expectDescriptor: Descriptor<T>? = null + open val actualDescriptors: List<Descriptor<T>> = emptyList() + val descriptors by lazy { listOfNotNull(expectDescriptor) + actualDescriptors } abstract val dri: DRI abstract val children: List<DocumentationNode<*>> override fun toString(): String { - return "${javaClass.simpleName}($dri)" + briefDocstring.takeIf { it.isNotBlank() }?.let { " [$it]"}.orEmpty() + return "${javaClass.simpleName}($dri)" + briefDocstring.takeIf { it.isNotBlank() }?.let { " [$it]" }.orEmpty() } override fun equals(other: Any?) = other is DocumentationNode<*> && this.dri == other.dri override fun hashCode() = dri.hashCode() - val rawDocstrings: List<String> - get() = docTags.map(KDocTag::getContent) + val commentsData: List<Pair<String, Map<String, DRI>>> + get() = descriptors.mapNotNull { it.docTag?.let { tag -> Pair(tag.getContent(), it.links) } } val briefDocstring: String - get() = rawDocstrings.firstOrNull().orEmpty().shorten(40) + get() = descriptors.firstOrNull()?.docTag?.getContent().orEmpty().shorten(40) } abstract class ScopeNode<out T : ClassOrPackageFragmentDescriptor> : DocumentationNode<T>() { diff --git a/core/src/main/kotlin/Model/transformers/DocumentationNodeTransformer.kt b/core/src/main/kotlin/Model/transformers/DocumentationNodeTransformer.kt index f94147fb..318d20b3 100644 --- a/core/src/main/kotlin/Model/transformers/DocumentationNodeTransformer.kt +++ b/core/src/main/kotlin/Model/transformers/DocumentationNodeTransformer.kt @@ -4,4 +4,5 @@ import org.jetbrains.dokka.Model.Module interface DocumentationNodeTransformer { operator fun invoke(original: Module): Module + operator fun invoke(modules: Collection<Module>): Module }
\ No newline at end of file diff --git a/core/src/main/kotlin/Model/transformers/ActualExpectedMerger.kt b/core/src/main/kotlin/Model/transformers/DocumentationNodesMerger.kt index 171b41d0..c5a67513 100644 --- a/core/src/main/kotlin/Model/transformers/ActualExpectedMerger.kt +++ b/core/src/main/kotlin/Model/transformers/DocumentationNodesMerger.kt @@ -2,11 +2,14 @@ package org.jetbrains.dokka.Model.transformers import org.jetbrains.dokka.Model.* import org.jetbrains.dokka.Model.Function +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -internal object ActualExpectedMerger : DocumentationNodeTransformer { +internal object DocumentationNodesMerger : DocumentationNodeTransformer { override fun invoke(original: Module) = Module( original.packages.map { mergePackageContent(it) } ) + override fun invoke(modules: Collection<Module>): Module = + Module(merge(modules.flatMap { it.packages }, Package::mergeWith)) } private fun mergePackageContent(original: Package) = Package( @@ -21,21 +24,33 @@ private fun <T: DocumentationNode<*>> merge(elements: List<T>, reducer: (T, T) - .reduce { _, left, right -> reducer(left, right)} .values.toList() +fun <T:DeclarationDescriptor> Descriptor<T>.mergeWith(other: Descriptor<T>?) = Descriptor( + descriptor, + docTag, + links, + (passes + (other?.passes ?: emptyList())).distinct() +) + +fun <T:DeclarationDescriptor> List<Descriptor<T>>.merge() : List<Descriptor<T>> = + groupingBy { it.descriptor }.reduce { + _, left, right -> left.mergeWith(right) + }.values.toList() + fun Function.mergeWith(other: Function) = Function( dri, name, if (receiver != null && other.receiver != null) receiver.mergeWith(other.receiver) else null, merge(parameters + other.parameters, Parameter::mergeWith), - docTags + other.docTags, - descriptors + other.descriptors + expectDescriptor?.mergeWith(other.expectDescriptor), + (actualDescriptors + other.actualDescriptors).merge() ) fun Property.mergeWith(other: Property) = Property( dri, name, if (receiver != null && other.receiver != null) receiver.mergeWith(other.receiver) else null, - docTags + other.docTags, - descriptors + other.descriptors + expectDescriptor?.mergeWith(other.expectDescriptor), + (actualDescriptors + other.actualDescriptors).merge() ) fun Class.mergeWith(other: Class) = Class( @@ -45,13 +60,19 @@ fun Class.mergeWith(other: Class) = Class( merge(functions + other.functions, Function::mergeWith), merge(properties + other.properties, Property::mergeWith), merge(classes + other.classes, Class::mergeWith), - docTags + other.docTags, - descriptors + other.descriptors + expectDescriptor?.mergeWith(other.expectDescriptor), + (actualDescriptors + other.actualDescriptors).merge() ) fun Parameter.mergeWith(other: Parameter) = Parameter( dri, name, - docTags + other.docTags, - descriptors + other.descriptors + (actualDescriptors + other.actualDescriptors).merge() ) + +fun Package.mergeWith(other: Package) = Package( + dri, + merge(functions + other.functions, Function::mergeWith), + merge(properties + other.properties, Property::mergeWith), + merge(classes + other.classes, Class::mergeWith) +)
\ No newline at end of file diff --git a/core/src/main/kotlin/pages/MarkdownToContentConverter.kt b/core/src/main/kotlin/pages/MarkdownToContentConverter.kt index 24bfc6f4..b29614d7 100644 --- a/core/src/main/kotlin/pages/MarkdownToContentConverter.kt +++ b/core/src/main/kotlin/pages/MarkdownToContentConverter.kt @@ -3,25 +3,21 @@ package org.jetbrains.dokka.pages import org.intellij.markdown.MarkdownElementTypes import org.intellij.markdown.MarkdownTokenTypes import org.jetbrains.dokka.DokkaLogger -import org.jetbrains.dokka.DokkaResolutionFacade import org.jetbrains.dokka.MarkdownNode -import org.jetbrains.dokka.Model.DocumentationNode import org.jetbrains.dokka.links.DRI -import org.jetbrains.kotlin.idea.kdoc.resolveKDocLink class MarkdownToContentConverter( - private val resolutionFacade: DokkaResolutionFacade, private val logger: DokkaLogger ) { fun buildContent( node: MarkdownNode, dci: DCI, - documentationNode: DocumentationNode<*> + links: Map<String, DRI> = emptyMap() ): List<ContentNode> { // println(tree.toTestString()) fun buildChildren(node: MarkdownNode) = node.children.flatMap { - buildContent(it, dci, documentationNode) + buildContent(it, dci, links) }.coalesceText() return when (node.type) { @@ -89,27 +85,15 @@ class MarkdownToContentConverter( } MarkdownElementTypes.SHORT_REFERENCE_LINK, MarkdownElementTypes.FULL_REFERENCE_LINK -> { - if (documentationNode.descriptors.isNotEmpty()) { - val destinationNode = node.children.find { it.type == MarkdownElementTypes.LINK_DESTINATION } - ?: node.children.first { it.type == MarkdownElementTypes.LINK_LABEL } - val destination = destinationNode.children.find { it.type == MarkdownTokenTypes.TEXT }?.text - ?: destinationNode.text - - documentationNode.descriptors.flatMap { - resolveKDocLink( - resolutionFacade.resolveSession.bindingContext, - resolutionFacade, - it, - null, - destination.split('.') - ) - } - .firstOrNull() - ?.let { ContentLink(destination, DRI.from(it), dci) } - .let(::listOfNotNull) - } else { - logger.error("Apparently descriptor for $documentationNode was needed in model") - emptyList() + val destinationNode = node.children.find { it.type == MarkdownElementTypes.LINK_DESTINATION } + ?: node.children.first { it.type == MarkdownElementTypes.LINK_LABEL } + val destination = destinationNode.children.find { it.type == MarkdownTokenTypes.TEXT }?.text + ?: destinationNode.text + links[destination]?.let { dri -> + listOf(ContentLink(destination, dri, dci)) + } ?: let { + logger.error("Apparently there is no link resolved for $destination") + emptyList<ContentNode>() } } MarkdownTokenTypes.WHITE_SPACE -> { diff --git a/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt b/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt index d7837ca2..771226d5 100644 --- a/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt +++ b/core/src/main/kotlin/transformers/DefaultDocumentationToPageTransformer.kt @@ -1,6 +1,5 @@ package org.jetbrains.dokka.transformers -import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.DokkaLogger import org.jetbrains.dokka.Model.* import org.jetbrains.dokka.Model.Function @@ -16,8 +15,8 @@ class DefaultDocumentationToPageTransformer( private val markdownConverter: MarkdownToContentConverter, private val logger: DokkaLogger ) : DocumentationToPageTransformer { - override fun transform(passConfiguration: DokkaConfiguration.PassConfiguration, module: Module): ModulePageNode { - val platformData = passConfiguration.targets.map { PlatformData(it, passConfiguration.analysisPlatform) } + override fun transform(module: Module): ModulePageNode { + val platformData = emptyList<PlatformData>() return PageBuilder(platformData).pageForModule(module) } @@ -72,7 +71,7 @@ class DefaultDocumentationToPageTransformer( private fun contentForClass(c: Class) = content(DCI(c.dri, platformData)) { header(1) { text(c.name) } - c.rawDocstrings.forEach { comment(it, c) } + c.commentsData.forEach { (doc, links) -> comment(doc, links) } block("Constructors", c.constructors) { link(it.name, it.dri) signature(it) @@ -88,11 +87,11 @@ class DefaultDocumentationToPageTransformer( private fun contentForFunction(f: Function) = content(DCI(f.dri, platformData)) { header(1) { text(f.name) } signature(f) - f.rawDocstrings.forEach { markdown(it, f) } + f.commentsData.forEach { (doc, links) -> markdown(doc, links) } block("Parameters", f.children) { param -> group { text(param.name ?: "<receiver>") - param.rawDocstrings.forEach { markdown(it, param) } + param.commentsData.forEach { (doc, links) -> markdown(doc, links) } } } } @@ -145,12 +144,12 @@ class DefaultDocumentationToPageTransformer( fun link(text: String, address: DRI) { contents += ContentLink(text, address, dci) } - fun comment(raw: String, node: DocumentationNode<*>) { - contents += ContentComment(markdownConverter.buildContent(parseMarkdown(raw), dci, node), dci) + fun comment(raw: String, links: Map<String, DRI>) { + contents += ContentComment(markdownConverter.buildContent(parseMarkdown(raw), dci, links), dci) } - fun markdown(raw: String, node: DocumentationNode<*>) { - contents += markdownConverter.buildContent(parseMarkdown(raw), dci, node) + fun markdown(raw: String, links: Map<String, DRI>) { + contents += markdownConverter.buildContent(parseMarkdown(raw), dci, links) } private inline fun content(block: ContentBuilder.() -> Unit): List<ContentNode> = content(dci, block) @@ -163,7 +162,7 @@ class DefaultDocumentationToPageTransformer( private fun ContentBuilder.signature(f: Function) = symbol { text("fun ") if (f.receiver is Parameter) { - type(f.receiver.descriptors.first().type) + type(f.receiver.descriptors.first().descriptor.type) text(".") } link(f.name, f.dri) @@ -171,11 +170,11 @@ class DefaultDocumentationToPageTransformer( list(f.parameters) { link(it.name!!, it.dri) text(": ") - type(it.descriptors.first().type) + type(it.descriptors.first().descriptor.type) } text(")") - val returnType = f.descriptors.first().returnType - if (f.descriptors.first() !is ConstructorDescriptor && returnType != null && + val returnType = f.descriptors.first().descriptor.returnType + if (f.descriptors.first().descriptor !is ConstructorDescriptor && returnType != null && returnType.constructor.declarationDescriptor?.fqNameSafe?.asString() != Unit::class.qualifiedName) { text(": ") type(returnType) diff --git a/core/src/main/kotlin/transformers/DocumentationToPageTransformer.kt b/core/src/main/kotlin/transformers/DocumentationToPageTransformer.kt index b37b5439..19703025 100644 --- a/core/src/main/kotlin/transformers/DocumentationToPageTransformer.kt +++ b/core/src/main/kotlin/transformers/DocumentationToPageTransformer.kt @@ -7,5 +7,5 @@ import org.jetbrains.dokka.pages.ModulePageNode import org.jetbrains.dokka.pages.PageNode interface DocumentationToPageTransformer { - fun transform(passConfiguration: DokkaConfiguration.PassConfiguration, module: Module): ModulePageNode // TODO refactor this... some more? + fun transform(module: Module): ModulePageNode // TODO refactor this... some more? }
\ No newline at end of file diff --git a/core/src/main/kotlin/transformers/TopDownPageNodeMerger.kt b/core/src/main/kotlin/transformers/TopDownPageNodeMerger.kt deleted file mode 100644 index 7d6d33b7..00000000 --- a/core/src/main/kotlin/transformers/TopDownPageNodeMerger.kt +++ /dev/null @@ -1,50 +0,0 @@ -package org.jetbrains.dokka.transformers - -import org.jetbrains.dokka.pages.* -import kotlin.reflect.KClass - -class TopDownPageNodeMerger { - fun mergeModules(nodes: Iterable<ModulePageNode>): PageNode { - assert(nodes.all { it::class == nodes.first()::class }) // TODO check - - val merged = ModulePageNode(nodes.first().name, mergeContent(nodes), null, nodes.first().documentationNode) // TODO: merge documentationNodes - merged.appendChildren(mergeChildren(nodes.flatMap { it.children })) - - return merged - } - - private fun mergeChildren(nodes: Iterable<PageNode>): List<PageNode> = - nodes.groupBy { it.dri }.map { (_, list) -> - val merged = when (list.first()) { - is PackagePageNode -> PackagePageNode(list.first().name, mergeContent(list), list.first().parent!!, list.first().dri!!, list.first().documentationNode) // TODO: merge documentationlist - is ClassPageNode -> ClassPageNode(list.first().name, mergeContent(list), list.first().parent!!, list.first().dri!!, list.first().documentationNode) // TODO: merge documentationlist - is MemberPageNode -> MemberPageNode(list.first().name, mergeContent(list), list.first().parent!!, list.first().dri!!, list.first().documentationNode) // TODO: merge documentationNodes - else -> throw IllegalStateException("${list.first()} should not be present here") - } - merged.appendChildren(mergeChildren(list.flatMap { it.children })) - merged - } - - private fun mergeContent(nodes: Iterable<PageNode>): List<ContentNode> = nodes.flatMap { it.content }.groupBy { it.dci.dri }.flatMap { (_, list) -> list.mergeList() } - - - - private fun List<ContentBlock>.mergeContent(): ContentBlock = - ContentBlock(this.first().name, this.flatMap { it.children }.groupBy { it.dci.dri }.flatMap { (_, list) -> list.mergeList() }, DCI(this.first().dci.dri, this.flatMap { it.dci.platformDataList }.distinct()), this.flatMap { it.annotations }) - - private fun List<ContentNode>.mergeList(): List<ContentNode> = - this.groupBy { it::class }.flatMap { (_, list) -> - val thisClass = list.first() - val newDCI = DCI(thisClass.dci.dri, list.flatMap { it.dci.platformDataList }.distinct()) - when(thisClass) { - is ContentBlock -> list.groupBy{ (it as ContentBlock).name }.map { (it.value as List<ContentBlock>).mergeContent() } //(ContentBlock(thisClass.name, (list as List<ContentBlock>).mergeContent(), newDCI, list.flatMap { it.annotations }.distinct())) - is ContentHeader -> list.distinctBy { it.toString().replace("dci=.*,".toRegex(), "") }.map { (it as ContentHeader).copy(dci = newDCI)} - is ContentStyle -> list.distinctBy { it.toString().replace("dci=.*,".toRegex(), "") }.map { (it as ContentStyle).copy(dci = newDCI)} - is ContentSymbol -> list.distinctBy { it.toString().replace("dci=.*,".toRegex(), "") }.map { (it as ContentSymbol).copy(dci = newDCI)} - is ContentComment -> list.distinctBy { it.toString().replace("dci=.*,".toRegex(), "") }.map { (it as ContentComment).copy(dci = newDCI)} - is ContentGroup -> list.distinctBy { it.toString().replace("dci=.*,".toRegex(), "") }.map { (it as ContentGroup).copy(dci = newDCI)} - is ContentList -> list.distinctBy { it.toString().replace("dci=.*,".toRegex(), "") }.map { (it as ContentList).copy(dci = newDCI)} - else -> list.distinctBy { it.toString().replace("dci=.*,".toRegex(), "") } - } - } -}
\ No newline at end of file |