diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-06-10 14:59:32 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-06-25 14:56:46 +0200 |
commit | 44650369a1f151ddbf890a1d370daea0b7982124 (patch) | |
tree | 5a622399b79a6748a1660d158917d813d14a3323 /plugins | |
parent | 75efaa5662fd7bfe9ada0756509f34bdb35f3341 (diff) | |
download | dokka-44650369a1f151ddbf890a1d370daea0b7982124.tar.gz dokka-44650369a1f151ddbf890a1d370daea0b7982124.tar.bz2 dokka-44650369a1f151ddbf890a1d370daea0b7982124.zip |
Refactor deprecated transformer
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt b/plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt index f7d6f88f..ffee64ed 100644 --- a/plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt +++ b/plugins/base/src/main/kotlin/transformers/pages/annotations/DeprecatedStrikethroughTransformer.kt @@ -7,36 +7,39 @@ import org.jetbrains.dokka.model.properties.WithExtraProperties import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.pages.PageTransformer +import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty class DeprecatedStrikethroughTransformer(val context: DokkaContext) : PageTransformer { + override fun invoke(input: RootPageNode): RootPageNode = input.transformContentPagesTree { contentPage -> contentPage.platforms().fold(contentPage) { acc, sourceSetData -> - if (acc.documentable?.isDeprecated(sourceSetData) == true || acc.documentable?.hasDeprecatedChildren( - sourceSetData - ) == true - ) { - val deprecatedDRIs = - if (acc.documentable?.isDeprecated(sourceSetData) == true) contentPage.dri else emptySet<DRI>() + - contentPage.documentable?.children - ?.filter { it.isDeprecated(sourceSetData) } - ?.map { it.dri } - ?.toSet().orEmpty() - - acc.modified(content = acc.content.addStrikethroughToSignature(deprecatedDRIs)) - } else { - acc - } + listOfNotNull( + contentPage.documentable?.children?.filter { it.isDeprecated(sourceSetData) }?.map { it.dri }, + contentPage.dri.takeIf { acc.documentable?.isDeprecated(sourceSetData) == true }?.toList() + ).flatten().ifNotEmpty { + acc.modified(content = acc.content.addStrikethroughToSignature(sourceSetData, this.toSet())) + } ?: acc } } - private fun ContentNode.addStrikethroughToSignature(deprecatedDRIs: Set<DRI>): ContentNode = when (this) { - is ContentGroup -> if (dci.kind == ContentKind.Symbol && deprecatedDRIs.containsAll(dci.dri)) { + private fun ContentNode.addStrikethroughToSignature( + sourceSetData: SourceSetData, + deprecatedDRIs: Set<DRI> + ): ContentNode = when (this) { + is ContentGroup -> if (setOf(sourceSetData) == sourceSets && deprecatedDRIs.containsAll(dci.dri)) { copy(style = this.style + setOf(TextStyle.Strikethrough)) } else { - copy(children = children.map { it.addStrikethroughToSignature(deprecatedDRIs) }) + copy(children = children.map { it.addStrikethroughToSignature(sourceSetData, deprecatedDRIs) }) } - is ContentTable -> copy(children = children.map { it.addStrikethroughToSignature(deprecatedDRIs) as ContentGroup }) - is PlatformHintedContent -> copy(inner = inner.addStrikethroughToSignature(deprecatedDRIs)) + is ContentTable -> copy(children = children.map { + it.addStrikethroughToSignature( + sourceSetData, + deprecatedDRIs + ) as ContentGroup + }) + is PlatformHintedContent -> copy(inner = inner.addStrikethroughToSignature(sourceSetData, deprecatedDRIs)) + is ContentDivergentGroup -> copy(children = children.map { it.addStrikethroughToSignature(sourceSetData, deprecatedDRIs) } as List<ContentDivergentInstance>) + is ContentDivergentInstance -> copy(divergent = divergent.addStrikethroughToSignature(sourceSetData, deprecatedDRIs)) else -> this } |