From 9be7ac19b3ad38c80c78f39443eb2f55b3b699c6 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Sat, 21 Aug 2021 14:50:55 +0200 Subject: Make briefs contain first paragraph as in spec, resolve issues with i.e. (#2048) * Make briefs contain first paragraph as in spec, resolve issues with i.e. * Html and the end --- .../documentables/DefaultPageCreator.kt | 28 +++++++++++++--- .../documentables/PageContentBuilder.kt | 28 ++++++++++++++-- .../documentables/briefFromContentNodes.kt | 39 +++++++++++++++++----- .../documentables/documentableLanguage.kt | 15 +++++++++ .../translators/psi/parsers/JavadocParser.kt | 5 ++- 5 files changed, 97 insertions(+), 18 deletions(-) create mode 100644 plugins/base/src/main/kotlin/translators/documentables/documentableLanguage.kt (limited to 'plugins/base/src/main') diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index 081608d6..4b5fc1c0 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -141,7 +141,7 @@ open class DefaultPageCreator( link(it.name, it.dri) if (it.sourceSets.size == 1 || (documentations.isNotEmpty() && haveSameContent)) { - documentations.first()?.let { firstSentenceComment(kind = ContentKind.Comment, content = it.root) } + documentations.first()?.let { firstParagraphComment(kind = ContentKind.Comment, content = it.root) } } } } @@ -375,7 +375,7 @@ open class DefaultPageCreator( val platforms = d.sourceSets fun DocumentableContentBuilder.contentForParams() { - if (tags.isNotEmptyForTag()) { + if (tags.isNotEmptyForTag() && d !is DProperty) { header(2, "Parameters", kind = ContentKind.Parameters) group( extra = mainExtra + SimpleAttr.header("Parameters"), @@ -504,15 +504,33 @@ open class DefaultPageCreator( protected open fun DocumentableContentBuilder.contentForBrief(documentable: Documentable) { documentable.sourceSets.forEach { sourceSet -> - documentable.documentation[sourceSet]?.children?.firstOrNull()?.root?.let { + documentable.documentation[sourceSet]?.let { + /* + Get description or a tag that holds documentation. + This tag can be either property or constructor but constructor tags are handled already in analysis so we + only need to keep an eye on property + + We purposefully ignore all other tags as they should not be visible in brief + */ + it.firstMemberOfTypeOrNull() ?: it.firstMemberOfTypeOrNull().takeIf { documentable is DProperty } + }?.let { group(sourceSets = setOf(sourceSet), kind = ContentKind.BriefComment) { - if (documentable.hasSeparatePage) firstSentenceComment(it) - else comment(it) + if (documentable.hasSeparatePage) createBriefComment(documentable, sourceSet, it) + else comment(it.root) } } } } + private fun DocumentableContentBuilder.createBriefComment(documentable: Documentable, sourceSet: DokkaSourceSet, tag: TagWrapper){ + (documentable as? WithSources)?.documentableLanguage(sourceSet)?.let { + when(it){ + DocumentableLanguage.KOTLIN -> firstParagraphComment(tag.root) + DocumentableLanguage.JAVA -> firstSentenceComment(tag.root) + } + } ?: firstParagraphComment(tag.root) + } + protected open fun DocumentableContentBuilder.contentForSinceKotlin(documentable: Documentable) { documentable.documentation.mapValues { it.value.children.find { it is CustomTagWrapper && it.name == "Since Kotlin" } as CustomTagWrapper? diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt index f98e284f..2db55d45 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt @@ -283,13 +283,37 @@ open class PageContentBuilder( contents += ContentGroup(content, DCI(mainDRI, kind), sourceSets.toDisplaySourceSets(), styles, extra) } - fun firstSentenceComment( + fun firstParagraphComment( content: DocTag, kind: Kind = ContentKind.Comment, sourceSets: Set = mainSourcesetData, styles: Set