From ca4622e32326f804a1dd03e03f36e874657442d4 Mon Sep 17 00:00:00 2001 From: Filip ZybaƂa Date: Tue, 23 Jun 2020 08:59:22 +0200 Subject: Added fallbacks for samples, params and see also --- .../kotlin/translators/documentables/DefaultPageCreator.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'plugins/base') diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index bc3f79c8..fb8cbf9e 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -246,6 +246,12 @@ open class DefaultPageCreator( }.children } + private fun Documentable.getPossibleFallbackSourcesets(sourceSet: SourceSetData) = + this.sourceSets.filter { it.sourceSetID in sourceSet.dependentSourceSets } + + private fun Map.fallback(sourceSets: List) : V? = + sourceSets.firstOrNull { it in this.keys }.let { this[it] } + protected open fun contentForComments( d: Documentable ): List { @@ -264,7 +270,8 @@ open class DefaultPageCreator( val params = tags.withTypeNamed() table(kind = ContentKind.Parameters) { platforms.flatMap { platform -> - val receiverRow = receiver[platform]?.let { + val possibleFallbacks = d.getPossibleFallbackSourcesets(platform) + val receiverRow = (receiver[platform] ?: receiver.fallback(possibleFallbacks))?.let { buildGroup(sourceSets = setOf(platform), kind = ContentKind.Parameters) { text("", styles = mainStyles + ContentStyle.RowTitle) comment(it.root) @@ -272,7 +279,7 @@ open class DefaultPageCreator( } val paramRows = params.mapNotNull { (_, param) -> - param[platform]?.let { + (param[platform] ?: param.fallback(possibleFallbacks))?.let { buildGroup(sourceSets = setOf(platform), kind = ContentKind.Parameters) { text(it.name, kind = ContentKind.Parameters, styles = mainStyles + ContentStyle.RowTitle) comment(it.root) @@ -296,8 +303,9 @@ open class DefaultPageCreator( val seeAlsoTags = tags.withTypeNamed() table(kind = ContentKind.Sample) { platforms.flatMap { platform -> + val possibleFallbacks = d.getPossibleFallbackSourcesets(platform) seeAlsoTags.mapNotNull { (_, see) -> - see[platform]?.let { + (see[platform] ?: see.fallback(possibleFallbacks))?.let { buildGroup(sourceSets = setOf(platform), kind = ContentKind.Comment, styles = mainStyles + ContentStyle.RowTitle) { if (it.address != null) link(it.name, it.address!!, kind = ContentKind.Comment) else text(it.name, kind = ContentKind.Comment) -- cgit