From 4a1b8a981389a0459284ba62aa5d00cc0d44e454 Mon Sep 17 00:00:00 2001 From: vmishenev Date: Fri, 12 Nov 2021 04:43:25 +0300 Subject: Unite platforms bookmarks rows (#2219) --- .../documentables/DefaultPageCreator.kt | 71 +++-- .../kotlin/content/params/ContentForParamsTest.kt | 285 ++++++++++----------- .../content/seealso/ContentForSeeAlsoTest.kt | 103 ++++---- .../kotlin/linkableContent/LinkableContentTest.kt | 2 - 4 files changed, 225 insertions(+), 236 deletions(-) (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 332a0663..b33351ac 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -369,22 +369,37 @@ open class DefaultPageCreator( sourceSets.firstOrNull { it in this.keys }.let { this[it] } protected open fun contentForComments( - d: Documentable + d: Documentable, + isPlatformHintedContent: Boolean = true ): List { val tags = d.groupedTags - val platforms = d.sourceSets + + fun DocumentableContentBuilder.buildContent( + platforms: Set, + contentBuilder: DocumentableContentBuilder.() -> Unit + ) = if (isPlatformHintedContent) + sourceSetDependentHint( + sourceSets = platforms, + kind = ContentKind.SourceSetDependentHint, + block = contentBuilder + ) + else + contentBuilder() fun DocumentableContentBuilder.contentForParams() { - if (tags.isNotEmptyForTag() && d !is DProperty) { - header(2, "Parameters", kind = ContentKind.Parameters) + if (tags.isNotEmptyForTag()) { + val params = tags.withTypeNamed() + val availablePlatforms = params.values.flatMap { it.keys }.toSet() + + header(2, "Parameters", kind = ContentKind.Parameters, sourceSets = availablePlatforms) group( extra = mainExtra + SimpleAttr.header("Parameters"), - styles = setOf(ContentStyle.WithExtraAttributes) + styles = setOf(ContentStyle.WithExtraAttributes), + sourceSets = availablePlatforms ) { - sourceSetDependentHint(sourceSets = platforms.toSet(), kind = ContentKind.SourceSetDependentHint) { - val params = tags.withTypeNamed() - table(kind = ContentKind.Parameters) { - platforms.forEach { platform -> + buildContent(availablePlatforms) { + table(kind = ContentKind.Parameters, sourceSets = availablePlatforms) { + availablePlatforms.forEach { platform -> val possibleFallbacks = d.getPossibleFallbackSourcesets(platform) params.mapNotNull { (_, param) -> (param[platform] ?: param.fallback(possibleFallbacks))?.let { @@ -407,22 +422,25 @@ open class DefaultPageCreator( fun DocumentableContentBuilder.contentForSeeAlso() { if (tags.isNotEmptyForTag()) { - header(2, "See also", kind = ContentKind.Comment) + val seeAlsoTags = tags.withTypeNamed() + val availablePlatforms = seeAlsoTags.values.flatMap { it.keys }.toSet() + + header(2, "See also", kind = ContentKind.Comment, sourceSets = availablePlatforms) group( extra = mainExtra + SimpleAttr.header("See also"), - styles = setOf(ContentStyle.WithExtraAttributes) + styles = setOf(ContentStyle.WithExtraAttributes), + sourceSets = availablePlatforms ) { - sourceSetDependentHint(sourceSets = platforms.toSet(), kind = ContentKind.SourceSetDependentHint) { - val seeAlsoTags = tags.withTypeNamed() + buildContent(availablePlatforms) { table(kind = ContentKind.Sample) { - platforms.forEach { platform -> + availablePlatforms.forEach { platform -> val possibleFallbacks = d.getPossibleFallbackSourcesets(platform) seeAlsoTags.forEach { (_, see) -> (see[platform] ?: see.fallback(possibleFallbacks))?.let { row( sourceSets = setOf(platform), kind = ContentKind.Comment, - styles = this@sourceSetDependentHint.mainStyles, + styles = this@group.mainStyles, ) { if (it.address != null) link( it.name, @@ -444,9 +462,11 @@ open class DefaultPageCreator( fun DocumentableContentBuilder.contentForThrows() { val throws = tags.withTypeNamed() if (throws.isNotEmpty()) { - header(2, "Throws") - sourceSetDependentHint(sourceSets = platforms.toSet(), kind = ContentKind.SourceSetDependentHint) { - platforms.forEach { sourceset -> + val availablePlatforms = throws.values.flatMap { it.keys }.toSet() + + header(2, "Throws", sourceSets = availablePlatforms) + buildContent(availablePlatforms) { + availablePlatforms.forEach { sourceset -> table(kind = ContentKind.Main, sourceSets = setOf(sourceset)) { throws.entries.forEach { entry -> entry.value[sourceset]?.let { throws -> @@ -469,13 +489,15 @@ open class DefaultPageCreator( fun DocumentableContentBuilder.contentForSamples() { val samples = tags.withTypeNamed() if (samples.isNotEmpty()) { - header(2, "Samples", kind = ContentKind.Sample) + val availablePlatforms = samples.values.flatMap { it.keys }.toSet() + header(2, "Samples", kind = ContentKind.Sample, sourceSets = availablePlatforms) group( extra = mainExtra + SimpleAttr.header("Samples"), - styles = emptySet() + styles = emptySet(), + sourceSets = availablePlatforms ) { - sourceSetDependentHint(sourceSets = platforms.toSet(), kind = ContentKind.SourceSetDependentHint) { - platforms.map { platformData -> + buildContent(availablePlatforms) { + availablePlatforms.map { platformData -> val content = samples.filter { it.value.isEmpty() || platformData in it.value } group( sourceSets = setOf(platformData), @@ -496,7 +518,8 @@ open class DefaultPageCreator( if (tags.isNotEmpty()) { contentForSamples() contentForSeeAlso() - contentForParams() + if (d !is DProperty) + contentForParams() contentForThrows() } }.children @@ -561,7 +584,7 @@ open class DefaultPageCreator( } after { +contentForDescription(d) - +contentForComments(d) + +contentForComments(d, isPlatformHintedContent = false) } } } diff --git a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt index 75731665..664b8282 100644 --- a/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt +++ b/plugins/base/src/test/kotlin/content/params/ContentForParamsTest.kt @@ -451,23 +451,21 @@ class ContentForParamsTest : BaseAbstractTest() { after { group { pWrapped("a normal comment") } header(2) { +"Throws" } - platformHinted { - table { + table { + group { group { - group { - link { +"java.lang.IllegalStateException" } - } - comment { +"if the Dialog has not yet been created (before onCreateDialog) or has been destroyed (after onDestroyView)." } + link { +"java.lang.IllegalStateException" } } + comment { +"if the Dialog has not yet been created (before onCreateDialog) or has been destroyed (after onDestroyView)." } + } + group { group { - group { - link { +"java.lang.RuntimeException" } - } - comment { - +"when " - link { +"Hash Map" } - +" doesn't contain value." - } + link { +"java.lang.RuntimeException" } + } + comment { + +"when " + link { +"Hash Map" } + +" doesn't contain value." } } } @@ -510,39 +508,37 @@ class ContentForParamsTest : BaseAbstractTest() { after { group { pWrapped("a normal comment") } header(2) { +"Throws" } - platformHinted { - table { + table { + group { group { - group { - link { - check { - assertEquals( - "java.lang/IllegalStateException///PointingToDeclaration/", - (this as ContentDRILink).address.toString() - ) - } - +"java.lang.IllegalStateException" + link { + check { + assertEquals( + "java.lang/IllegalStateException///PointingToDeclaration/", + (this as ContentDRILink).address.toString() + ) } + +"java.lang.IllegalStateException" } - comment { +"if the Dialog has not yet been created (before onCreateDialog) or has been destroyed (after onDestroyView)." } } + comment { +"if the Dialog has not yet been created (before onCreateDialog) or has been destroyed (after onDestroyView)." } + } + group { group { - group { - link { - check { - assertEquals( - "java.lang/RuntimeException///PointingToDeclaration/", - (this as ContentDRILink).address.toString() - ) - } - +"java.lang.RuntimeException" + link { + check { + assertEquals( + "java.lang/RuntimeException///PointingToDeclaration/", + (this as ContentDRILink).address.toString() + ) } + +"java.lang.RuntimeException" } - comment { - +"when " - link { +"Hash Map" } - +" doesn't contain value." - } + } + comment { + +"when " + link { +"Hash Map" } + +" doesn't contain value." } } } @@ -590,44 +586,43 @@ class ContentForParamsTest : BaseAbstractTest() { after { group { pWrapped("a normal comment") } header(2) { +"Throws" } - platformHinted { - table { + table { + group { group { - group { - link { - check { - assertEquals( - "java.lang/IllegalStateException///PointingToDeclaration/", - (this as ContentDRILink).address.toString() - ) - } - +"java.lang.IllegalStateException" + link { + check { + assertEquals( + "java.lang/IllegalStateException///PointingToDeclaration/", + (this as ContentDRILink).address.toString() + ) } + +"java.lang.IllegalStateException" } - comment { +"if the Dialog has not yet been created (before onCreateDialog) or has been destroyed (after onDestroyView)." } } + comment { +"if the Dialog has not yet been created (before onCreateDialog) or has been destroyed (after onDestroyView)." } + } + group { group { - group { - link { - check { - assertEquals( - "java.lang/RuntimeException///PointingToDeclaration/", - (this as ContentDRILink).address.toString() - ) - } - +"java.lang.RuntimeException" + link { + check { + assertEquals( + "java.lang/RuntimeException///PointingToDeclaration/", + (this as ContentDRILink).address.toString() + ) } - } - comment { - +"when " - link { +"Hash Map" } - +" doesn't contain value." + +"java.lang.RuntimeException" } } + comment { + +"when " + link { +"Hash Map" } + +" doesn't contain value." + } } } } } + } } } @@ -726,14 +721,12 @@ class ContentForParamsTest : BaseAbstractTest() { } header(2) { +"Parameters" } group { - platformHinted { - table { - group { - +"testParam" - comment { - +"Sample description for test param that has a type of " - link { +"String" } - } + table { + group { + +"testParam" + comment { + +"Sample description for test param that has a type of " + link { +"String" } } } } @@ -1016,12 +1009,10 @@ class ContentForParamsTest : BaseAbstractTest() { group { pWrapped("comment to function") } header(2) { +"Parameters" } group { - platformHinted { - table { - group { - +"abc" - group { group { +"comment to param" } } - } + table { + group { + +"abc" + group { group { +"comment to param" } } } } } @@ -1071,20 +1062,18 @@ class ContentForParamsTest : BaseAbstractTest() { group { group { group { +"comment to function" } } } header(2) { +"Parameters" } group { - platformHinted { - table { - group { - +"first" - group { group { +"comment to first param" } } - } - group { - +"second" - group { group { +"comment to second param" } } - } - group { - +"third" - group { group { +"comment to third param" } } - } + table { + group { + +"first" + group { group { +"comment to first param" } } + } + group { + +"second" + group { group { +"comment to second param" } } + } + group { + +"third" + group { group { +"comment to third param" } } } } } @@ -1135,20 +1124,18 @@ class ContentForParamsTest : BaseAbstractTest() { group { group { group { +"comment to function" } } } header(2) { +"Parameters" } group { - platformHinted { - table { - group { - +"c" - group { group { +"comment to c param" } } - } - group { - +"b" - group { group { +"comment to b param" } } - } - group { - +"a" - group { group { +"comment to a param" } } - } + table { + group { + +"c" + group { group { +"comment to c param" } } + } + group { + +"b" + group { group { +"comment to b param" } } + } + group { + +"a" + group { group { +"comment to a param" } } } } } @@ -1196,20 +1183,18 @@ class ContentForParamsTest : BaseAbstractTest() { after { header(2) { +"Parameters" } group { - platformHinted { - table { - group { - +"first" - group { group { +"comment to first param" } } - } - group { - +"second" - group { group { +"comment to second param" } } - } - group { - +"third" - group { group { +"comment to third param" } } - } + table { + group { + +"first" + group { group { +"comment to first param" } } + } + group { + +"second" + group { group { +"comment to second param" } } + } + group { + +"third" + group { group { +"comment to third param" } } } } } @@ -1261,17 +1246,15 @@ class ContentForParamsTest : BaseAbstractTest() { after { group { pWrapped("comment to function") } group { - header(4){ +"Receiver" } + header(4) { +"Receiver" } pWrapped("comment to receiver") } header(2) { +"Parameters" } group { - platformHinted { - table { - group { - +"abc" - group { group { +"comment to param" } } - } + table { + group { + +"abc" + group { group { +"comment to param" } } } } } @@ -1320,16 +1303,14 @@ class ContentForParamsTest : BaseAbstractTest() { group { group { group { +"comment to function" } } } header(2) { +"Parameters" } group { - platformHinted { - table { - group { - +"first" - group { group { +"comment to first param" } } - } - group { - +"third" - group { group { +"comment to third param" } } - } + table { + group { + +"first" + group { group { +"comment to first param" } } + } + group { + +"third" + group { group { +"comment to third param" } } } } } @@ -1384,20 +1365,18 @@ class ContentForParamsTest : BaseAbstractTest() { header(2) { +"Parameters" } group { - platformHinted { - table { - group { - +"first" - group { group { +"comment to first param" } } - } - group { - +"second" - group { group { +"comment to second param" } } - } - group { - +"third" - group { group { +"comment to third param" } } - } + table { + group { + +"first" + group { group { +"comment to first param" } } + } + group { + +"second" + group { group { +"comment to second param" } } + } + group { + +"third" + group { group { +"comment to third param" } } } } } diff --git a/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt b/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt index e9a54e87..4096640a 100644 --- a/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt +++ b/plugins/base/src/test/kotlin/content/seealso/ContentForSeeAlsoTest.kt @@ -99,13 +99,11 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { after { header(2) { +"See also" } group { - platformHinted { - table { - group { - //DRI should be "test//abc/#/-1/" - link { +"abc" } - group { } - } + table { + group { + //DRI should be "test//abc/#/-1/" + link { +"abc" } + group { } } } } @@ -154,14 +152,12 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { after { header(2) { +"See also" } group { - platformHinted { - table { + table { + group { + //DRI should be "test//abc/#/-1/" + link { +"abc" } group { - //DRI should be "test//abc/#/-1/" - link { +"abc" } - group { - group { +"Comment to abc" } - } + group { +"Comment to abc" } } } } @@ -211,17 +207,18 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { after { header(2) { +"See also" } group { - platformHinted { - table { - group { - link { - check { - assertEquals("kotlin.collections/Collection///PointingToDeclaration/", (this as ContentDRILink).address.toString()) - } - +"kotlin.collections.Collection" + table { + group { + link { + check { + assertEquals( + "kotlin.collections/Collection///PointingToDeclaration/", + (this as ContentDRILink).address.toString() + ) } - group { } + +"kotlin.collections.Collection" } + group { } } } } @@ -270,14 +267,12 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { after { header(2) { +"See also" } group { - platformHinted { - table { + table { + group { + //DRI should be "test//abc/#/-1/" + link { +"kotlin.collections.Collection" } group { - //DRI should be "test//abc/#/-1/" - link { +"kotlin.collections.Collection" } - group { - group { +"Comment to stdliblink" } - } + group { +"Comment to stdliblink" } } } } @@ -328,20 +323,18 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { ) } after { - group { comment { +"random comment"} } + group { comment { +"random comment" } } unnamedTag("Author") { comment { +"pikinier20" } } unnamedTag("Since") { comment { +"0.11" } } header(2) { +"See also" } group { - platformHinted { - table { + table { + group { + //DRI should be "test//abc/#/-1/" + link { +"kotlin.collections.Collection" } group { - //DRI should be "test//abc/#/-1/" - link { +"kotlin.collections.Collection" } - group { - group { +"Comment to stdliblink" } - } + group { +"Comment to stdliblink" } } } } @@ -392,14 +385,12 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { after { header(2) { +"See also" } group { - platformHinted { - table { + table { + group { + //DRI should be "test//abc/#/-1/" + link { +"abc" } group { - //DRI should be "test//abc/#/-1/" - link { +"abc" } - group { - group { +"Comment to abc2" } - } + group { +"Comment to abc2" } } } } @@ -450,21 +441,19 @@ class ContentForSeeAlsoTest : BaseAbstractTest() { after { header(2) { +"See also" } group { - platformHinted { - table { + table { + group { + //DRI should be "test//abc/#/-1/" + link { +"abc" } group { - //DRI should be "test//abc/#/-1/" - link { +"abc" } - group { - group { +"Comment to abc1" } - } - } - group { - //DRI should be "test//abc/#/-1/" - link { +"kotlin.collections.Collection" } - group { group { +"Comment to collection" } } + group { +"Comment to abc1" } } } + group { + //DRI should be "test//abc/#/-1/" + link { +"kotlin.collections.Collection" } + group { group { +"Comment to collection" } } + } } } } diff --git a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt index b9107d53..3b0f6eef 100644 --- a/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt +++ b/plugins/base/src/test/kotlin/linkableContent/LinkableContentTest.kt @@ -202,8 +202,6 @@ class LinkableContentTest : BaseAbstractTest() { .cast().after .cast().children.last() .cast().children.last() - .cast().children.single() - .cast().children.single() .cast().children.single() .cast().children.single().cast().text Assertions.assertEquals( -- cgit