From 2cd95b0828518dde751d039f4456dcf93e04dfc1 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Wed, 28 Jul 2021 09:14:38 +0200 Subject: Missing receiver docs (#2026) --- .../documentables/DefaultPageCreator.kt | 10 +--- .../kotlin/content/params/ContentForParamsTest.kt | 8 +-- .../content/receiver/ContentForReceiverTest.kt | 57 ++++++++++++++++++++++ 3 files changed, 62 insertions(+), 13 deletions(-) create mode 100644 plugins/base/src/test/kotlin/content/receiver/ContentForReceiverTest.kt (limited to 'plugins/base/src') diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index 61fbd7d2..eaa4b6cd 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -23,7 +23,7 @@ import org.jetbrains.dokka.base.transformers.documentables.ClashingDriIdentifier private typealias GroupedTags = Map, List>> private val specialTags: Set> = - setOf(Property::class, Description::class, Constructor::class, Receiver::class, Param::class, See::class) + setOf(Property::class, Description::class, Constructor::class, Param::class, See::class) open class DefaultPageCreator( configuration: DokkaBaseConfiguration?, @@ -382,18 +382,10 @@ open class DefaultPageCreator( styles = setOf(ContentStyle.WithExtraAttributes) ) { sourceSetDependentHint(sourceSets = platforms.toSet(), kind = ContentKind.SourceSetDependentHint) { - val receiver = tags.withTypeUnnamed() val params = tags.withTypeNamed() table(kind = ContentKind.Parameters) { platforms.forEach { platform -> val possibleFallbacks = d.getPossibleFallbackSourcesets(platform) - (receiver[platform] ?: receiver.fallback(possibleFallbacks))?.let { - row(sourceSets = setOf(platform), kind = ContentKind.Parameters) { - text("", styles = mainStyles + ContentStyle.RowTitle) - comment(it.root) - } - } - params.mapNotNull { (_, param) -> (param[platform] ?: param.fallback(possibleFallbacks))?.let { row(sourceSets = setOf(platform), kind = ContentKind.Parameters) { diff --git a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt index 26c072fd..f83ca55d 100644 --- a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt +++ b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt @@ -1256,14 +1256,14 @@ class ContentForParamsTest : BaseAbstractTest() { } after { group { pWrapped("comment to function") } + group { + header(4){ +"Receiver" } + pWrapped("comment to receiver") + } header(2) { +"Parameters" } group { platformHinted { table { - group { - +"" - group { group { +"comment to receiver" } } - } group { +"abc" group { group { +"comment to param" } } diff --git a/plugins/base/src/test/kotlin/content/receiver/ContentForReceiverTest.kt b/plugins/base/src/test/kotlin/content/receiver/ContentForReceiverTest.kt new file mode 100644 index 00000000..e566320c --- /dev/null +++ b/plugins/base/src/test/kotlin/content/receiver/ContentForReceiverTest.kt @@ -0,0 +1,57 @@ +package content.receiver + +import junit.framework.Assert.assertEquals +import junit.framework.Assert.assertNotNull +import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest +import org.jetbrains.dokka.model.dfs +import org.jetbrains.dokka.model.doc.Receiver +import org.jetbrains.dokka.model.doc.Text +import org.jetbrains.dokka.pages.ContentHeader +import org.jetbrains.dokka.pages.ContentText +import org.jetbrains.dokka.pages.MemberPageNode +import org.junit.jupiter.api.Test +import utils.docs + +class ContentForReceiverTest: BaseAbstractTest() { + private val testConfiguration = dokkaConfiguration { + sourceSets { + sourceSet { + sourceRoots = listOf("src/") + analysisPlatform = "jvm" + } + } + } + + @Test + fun `should have docs for receiver`(){ + testInline( + """ + |/src/main/kotlin/test/source.kt + |package test + |/** + | * docs + | * @receiver docs for string + | */ + |fun String.asd2(): String = this + """.trimIndent(), + testConfiguration + ){ + documentablesTransformationStage = { module -> + with(module.packages.flatMap { it.functions }.first()){ + val receiver = docs().firstOrNull { it is Receiver } + assertNotNull(receiver) + val content = receiver?.dfs { it is Text } as Text + assertEquals("docs for string", content.body) + } + } + pagesTransformationStage = { rootPageNode -> + val functionPage = rootPageNode.dfs { it is MemberPageNode } as MemberPageNode + val header = functionPage.content.dfs { it is ContentHeader && it.children.firstOrNull() is ContentText } + val text = functionPage.content.dfs { it is ContentText && it.text == "docs for string" } + + assertNotNull(header) + assertNotNull(text) + } + } + } +} \ No newline at end of file -- cgit