aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt
diff options
context:
space:
mode:
authorsebastian.sellmair <sebastian.sellmair@jetbrains.com>2020-08-28 11:52:21 +0200
committerSebastian Sellmair <34319766+sellmair@users.noreply.github.com>2020-08-31 15:10:04 +0200
commite1bc27df4b50cf09d45db41462944a01d428be56 (patch)
treefd4a7df6459b8307715d5128a8a63945505c7d83 /plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt
parent02ccae10e3f717c330dae5d87b49a0e72f798905 (diff)
downloaddokka-e1bc27df4b50cf09d45db41462944a01d428be56.tar.gz
dokka-e1bc27df4b50cf09d45db41462944a01d428be56.tar.bz2
dokka-e1bc27df4b50cf09d45db41462944a01d428be56.zip
Minor readability improvement in ModuleAndPackageDocumentationTransformer.kt
Diffstat (limited to 'plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt')
-rw-r--r--plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt34
1 files changed, 24 insertions, 10 deletions
diff --git a/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt b/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt
index dab06343..e8c6f02d 100644
--- a/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt
+++ b/plugins/base/src/main/kotlin/allModulePage/MultimodulePageCreator.kt
@@ -12,6 +12,7 @@ import org.jetbrains.dokka.base.resolvers.local.MultimoduleLocationProvider.Comp
import org.jetbrains.dokka.base.transformers.pages.comments.DocTagToContentConverter
import org.jetbrains.dokka.base.translators.documentables.PageContentBuilder
import org.jetbrains.dokka.links.DRI
+import org.jetbrains.dokka.model.doc.DocTag
import org.jetbrains.dokka.model.doc.DocumentationNode
import org.jetbrains.dokka.model.doc.P
import org.jetbrains.dokka.pages.*
@@ -20,7 +21,7 @@ import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.dokka.transformers.pages.PageCreator
import org.jetbrains.dokka.utilities.DokkaLogger
-class MultimodulePageCreator (
+class MultimodulePageCreator(
private val context: DokkaContext,
) : PageCreator {
private val logger: DokkaLogger = context.logger
@@ -71,16 +72,29 @@ class MultimodulePageCreator (
private fun getDisplayedModuleDocumentation(module: DokkaModuleDescription): P? {
val parsingContext = ModuleAndPackageDocumentationParsingContext(logger)
- return module.includes
+
+ val documentationFragment = module.includes
.flatMap { include -> parseModuleAndPackageDocumentationFragments(include) }
- .map { fragment -> parseModuleAndPackageDocumentation(parsingContext, fragment) }
- .firstOrNull { documentation -> documentation.classifier == Module && documentation.name == module.name }
- ?.documentation?.children.orEmpty()
- .flatMap { it.root.children }
- .filterIsInstance<P>()
- .firstOrNull()
+ .firstOrNull { fragment -> fragment.classifier == Module && fragment.name == module.name }
+ ?: return null
+
+ val moduleDocumentation = parseModuleAndPackageDocumentation(parsingContext, documentationFragment)
+ return moduleDocumentation.documentation.firstParagraph()
}
- private fun DocumentationNode.firstParagraph() =
- this.children.flatMap { it.root.children }.filterIsInstance<P>().firstOrNull()
+ private fun DocumentationNode.firstParagraph(): P? =
+ this.children
+ .map { it.root }
+ .mapNotNull { it.firstParagraph() }
+ .firstOrNull()
+
+ /**
+ * @return The very first, most inner paragraph. If any [P] is wrapped inside another [P], the inner one
+ * is preferred.
+ */
+ private fun DocTag.firstParagraph(): P? {
+ val firstChildParagraph = children.mapNotNull { it.firstParagraph() }.firstOrNull()
+ return if (firstChildParagraph == null && this is P) this
+ else firstChildParagraph
+ }
}