diff options
5 files changed, 227 insertions, 237 deletions
diff --git a/plugins/base/api/base.api b/plugins/base/api/base.api index c87d6f5e..5a7573ee 100644 --- a/plugins/base/api/base.api +++ b/plugins/base/api/base.api @@ -1307,7 +1307,8 @@ public class org/jetbrains/dokka/base/translators/documentables/DefaultPageCreat public fun <init> (Lorg/jetbrains/dokka/base/DokkaBaseConfiguration;Lorg/jetbrains/dokka/base/transformers/pages/comments/CommentsToContentConverter;Lorg/jetbrains/dokka/base/signatures/SignatureProvider;Lorg/jetbrains/dokka/utilities/DokkaLogger;)V protected fun contentForBrief (Lorg/jetbrains/dokka/base/translators/documentables/PageContentBuilder$DocumentableContentBuilder;Lorg/jetbrains/dokka/model/Documentable;)V protected fun contentForClasslike (Lorg/jetbrains/dokka/model/DClasslike;)Lorg/jetbrains/dokka/pages/ContentGroup; - protected fun contentForComments (Lorg/jetbrains/dokka/model/Documentable;)Ljava/util/List; + protected fun contentForComments (Lorg/jetbrains/dokka/model/Documentable;Z)Ljava/util/List; + public static synthetic fun contentForComments$default (Lorg/jetbrains/dokka/base/translators/documentables/DefaultPageCreator;Lorg/jetbrains/dokka/model/Documentable;ZILjava/lang/Object;)Ljava/util/List; protected fun contentForDescription (Lorg/jetbrains/dokka/model/Documentable;)Ljava/util/List; protected fun contentForEnumEntry (Lorg/jetbrains/dokka/model/DEnumEntry;)Lorg/jetbrains/dokka/pages/ContentGroup; protected fun contentForFunction (Lorg/jetbrains/dokka/model/DFunction;)Lorg/jetbrains/dokka/pages/ContentGroup; 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<ContentNode> { val tags = d.groupedTags - val platforms = d.sourceSets + + fun DocumentableContentBuilder.buildContent( + platforms: Set<DokkaSourceSet>, + contentBuilder: DocumentableContentBuilder.() -> Unit + ) = if (isPlatformHintedContent) + sourceSetDependentHint( + sourceSets = platforms, + kind = ContentKind.SourceSetDependentHint, + block = contentBuilder + ) + else + contentBuilder() fun DocumentableContentBuilder.contentForParams() { - if (tags.isNotEmptyForTag<Param>() && d !is DProperty) { - header(2, "Parameters", kind = ContentKind.Parameters) + if (tags.isNotEmptyForTag<Param>()) { + val params = tags.withTypeNamed<Param>() + 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<Param>() - 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<See>()) { - header(2, "See also", kind = ContentKind.Comment) + val seeAlsoTags = tags.withTypeNamed<See>() + 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<See>() + 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<Throws>() 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<Sample>() 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<ContentDivergentInstance>().after .cast<ContentGroup>().children.last() .cast<ContentGroup>().children.last() - .cast<PlatformHintedContent>().children.single() - .cast<ContentGroup>().children.single() .cast<ContentGroup>().children.single() .cast<ContentCodeBlock>().children.single().cast<ContentText>().text Assertions.assertEquals( |