aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/transformers/documentables
diff options
context:
space:
mode:
authorIgnat Beresnev <ignat.beresnev@jetbrains.com>2023-11-10 11:46:54 +0100
committerGitHub <noreply@github.com>2023-11-10 11:46:54 +0100
commit8e5c63d035ef44a269b8c43430f43f5c8eebfb63 (patch)
tree1b915207b2b9f61951ddbf0ff2e687efd053d555 /plugins/base/src/main/kotlin/transformers/documentables
parenta44efd4ba0c2e4ab921ff75e0f53fc9335aa79db (diff)
downloaddokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.gz
dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.tar.bz2
dokka-8e5c63d035ef44a269b8c43430f43f5c8eebfb63.zip
Restructure the project to utilize included builds (#3174)
* Refactor and simplify artifact publishing * Update Gradle to 8.4 * Refactor and simplify convention plugins and build scripts Fixes #3132 --------- Co-authored-by: Adam <897017+aSemy@users.noreply.github.com> Co-authored-by: Oleg Yukhnevich <whyoleg@gmail.com>
Diffstat (limited to 'plugins/base/src/main/kotlin/transformers/documentables')
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt127
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/ClashingDriIdentifier.kt12
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/DeprecatedDocumentableFilterTransformer.kt62
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/DocumentableReplacerTransformer.kt239
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt388
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/EmptyModulesFilterTransformer.kt14
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt30
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/ExtensionExtractorTransformer.kt160
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/InheritedEntriesDocumentableFilterTransformer.kt23
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/InheritorsExtractorTransformer.kt91
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/KotlinArrayDocumentableReplacerTransformer.kt68
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt47
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/ObviousFunctionsDocumentableFilterTransformer.kt17
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/ReportUndocumentedTransformer.kt143
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/SuppressTagDocumentableFilter.kt17
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer.kt146
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConfigurationDocumentableFilterTransformer.kt57
-rw-r--r--plugins/base/src/main/kotlin/transformers/documentables/utils.kt35
18 files changed, 0 insertions, 1676 deletions
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt b/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt
deleted file mode 100644
index dde1a2af..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/ActualTypealiasAdder.kt
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.model.properties.WithExtraProperties
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer
-
-/**
- * Since we can not merge [DClasslike] with [DTypeAlias.underlyingType] and [DTypeAlias.extra],
- * we have this transformer to add [ActualTypealias] extra in expect [DClasslike]
- *
- * The transformer should be applied after merging all documentables
- */
-// TODO assign actual [DTypeAlias.expectPresentInSet] an expect source set, currently, [DTypeAlias.expectPresentInSet] always = null
-public class ActualTypealiasAdder : DocumentableTransformer {
-
- override fun invoke(original: DModule, context: DokkaContext): DModule {
- return original.generateTypealiasesMap().let { aliases ->
- original.copy(packages = original.packages.map {
- it.copy(classlikes = addActualTypeAliasToClasslikes(it.classlikes, aliases))
- })
- }
- }
-
- private fun DModule.generateTypealiasesMap(): Map<DRI, DTypeAlias> =
- packages.flatMap { pkg ->
- pkg.typealiases.map { typeAlias ->
- typeAlias.dri to typeAlias
- }
- }.toMap()
-
-
- private fun addActualTypeAliasToClasslikes(
- elements: Iterable<DClasslike>,
- typealiases: Map<DRI, DTypeAlias>
- ): List<DClasslike> = elements.flatMap {
- when (it) {
- is DClass -> addActualTypeAlias(
- it.copy(
- classlikes = addActualTypeAliasToClasslikes(it.classlikes, typealiases)
- ).let(::listOf),
- typealiases
- )
- is DEnum -> addActualTypeAlias(
- it.copy(
- classlikes = addActualTypeAliasToClasslikes(it.classlikes, typealiases)
- ).let(::listOf),
- typealiases
- )
- is DInterface -> addActualTypeAlias(
- it.copy(
- classlikes = addActualTypeAliasToClasslikes(it.classlikes, typealiases)
- ).let(::listOf),
- typealiases
- )
- is DObject -> addActualTypeAlias(
- it.copy(
- classlikes = addActualTypeAliasToClasslikes(it.classlikes, typealiases)
- ).let(::listOf),
- typealiases
- )
- is DAnnotation -> addActualTypeAlias(
- it.copy(
- classlikes = addActualTypeAliasToClasslikes(it.classlikes, typealiases)
- ).let(::listOf),
- typealiases
- )
- else -> throw IllegalStateException("${it::class.qualifiedName} ${it.name} cannot have extra added")
- }
- }
-
- private fun <T> addActualTypeAlias(
- elements: Iterable<T>,
- typealiases: Map<DRI, DTypeAlias>
- ): List<T> where T : DClasslike, T : WithExtraProperties<T>, T : WithSources =
- elements.map { element ->
- if (element.expectPresentInSet != null) {
- typealiases[element.dri]?.let { ta ->
- val actualTypealiasExtra = ActualTypealias(ta.copy(expectPresentInSet = element.expectPresentInSet))
- val merged = element.withNewExtras(element.extra + actualTypealiasExtra).let {
- when (it) {
- is DClass -> it.copy(
- documentation = element.documentation + ta.documentation,
- sources = element.sources + ta.sources,
- sourceSets = element.sourceSets + ta.sourceSets
- )
-
- is DEnum -> it.copy(
- documentation = element.documentation + ta.documentation,
- sources = element.sources + ta.sources,
- sourceSets = element.sourceSets + ta.sourceSets
- )
-
- is DInterface -> it.copy(
- documentation = element.documentation + ta.documentation,
- sources = element.sources + ta.sources,
- sourceSets = element.sourceSets + ta.sourceSets
- )
-
- is DObject -> it.copy(
- documentation = element.documentation + ta.documentation,
- sources = element.sources + ta.sources,
- sourceSets = element.sourceSets + ta.sourceSets
- )
-
- is DAnnotation -> it.copy(
- documentation = element.documentation + ta.documentation,
- sources = element.sources + ta.sources,
- sourceSets = element.sourceSets + ta.sourceSets
- )
-
- else -> throw IllegalStateException("${it::class.qualifiedName} ${it.name} cannot have copy its sourceSets")
- }
- }
- @Suppress("UNCHECKED_CAST")
- merged as T
- } ?: element
- } else {
- element
- }
- }
-}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ClashingDriIdentifier.kt b/plugins/base/src/main/kotlin/transformers/documentables/ClashingDriIdentifier.kt
deleted file mode 100644
index e9c7342e..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/ClashingDriIdentifier.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-@Deprecated(
- message = "Declaration was moved to dokka-core",
- replaceWith = ReplaceWith("org.jetbrains.dokka.transformers.documentation.ClashingDriIdentifier"),
- level = DeprecationLevel.WARNING // TODO change to error after Kotlin 1.9.20
-)
-public typealias ClashingDriIdentifier = org.jetbrains.dokka.transformers.documentation.ClashingDriIdentifier
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DeprecatedDocumentableFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/DeprecatedDocumentableFilterTransformer.kt
deleted file mode 100644
index 4905e876..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/DeprecatedDocumentableFilterTransformer.kt
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.DokkaConfiguration
-import org.jetbrains.dokka.DokkaConfiguration.PackageOptions
-import org.jetbrains.dokka.model.Annotations
-import org.jetbrains.dokka.model.Documentable
-import org.jetbrains.dokka.model.EnumValue
-import org.jetbrains.dokka.model.properties.WithExtraProperties
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.transformers.documentation.perPackageOptions
-import org.jetbrains.dokka.transformers.documentation.sourceSet
-
-/**
- * If [PackageOptions.skipDeprecated] or [DokkaConfiguration.DokkaSourceSet.skipDeprecated] is set
- * to `true`, suppresses documentables marked with [kotlin.Deprecated] or [java.lang.Deprecated].
- * Package options are given preference over global options.
- *
- * Documentables with [kotlin.Deprecated.level] set to [DeprecationLevel.HIDDEN]
- * are suppressed regardless of global and package options.
- */
-public class DeprecatedDocumentableFilterTransformer(
- context: DokkaContext
-) : SuppressedByConditionDocumentableFilterTransformer(context) {
-
- override fun shouldBeSuppressed(d: Documentable): Boolean {
- val annotations = (d as? WithExtraProperties<*>)?.annotations() ?: return false
- if (annotations.isEmpty())
- return false
-
- val deprecatedAnnotations = filterDeprecatedAnnotations(annotations)
- if (deprecatedAnnotations.isEmpty())
- return false
-
- val kotlinDeprecated = deprecatedAnnotations.find { it.dri.packageName == "kotlin" }
- if (kotlinDeprecated?.isHidden() == true)
- return true
-
- return perPackageOptions(d)?.skipDeprecated ?: sourceSet(d).skipDeprecated
- }
-
- private fun WithExtraProperties<*>.annotations(): List<Annotations.Annotation> {
- return this.extra.allOfType<Annotations>().flatMap { annotations ->
- annotations.directAnnotations.values.singleOrNull() ?: emptyList()
- }
- }
-
- private fun filterDeprecatedAnnotations(annotations: List<Annotations.Annotation>): List<Annotations.Annotation> {
- return annotations.filter {
- (it.dri.packageName == "kotlin" && it.dri.classNames == "Deprecated") ||
- (it.dri.packageName == "java.lang" && it.dri.classNames == "Deprecated")
- }
- }
-
- private fun Annotations.Annotation.isHidden(): Boolean {
- val level = (this.params["level"] as? EnumValue) ?: return false
- return level.enumName == "DeprecationLevel.HIDDEN"
- }
-}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableReplacerTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableReplacerTransformer.kt
deleted file mode 100644
index 10b25a20..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableReplacerTransformer.kt
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer
-
-public abstract class DocumentableReplacerTransformer(
- public val context: DokkaContext
-) : PreMergeDocumentableTransformer {
- override fun invoke(modules: List<DModule>): List<DModule> =
- modules.map { module ->
- val (documentable, wasChanged) = processModule(module)
- documentable.takeIf { wasChanged } ?: module
- }
-
- protected open fun processModule(module: DModule): AnyWithChanges<DModule> {
- val afterProcessing = module.packages.map { processPackage(it) }
- val processedModule = module.takeIf { afterProcessing.none { it.changed } }
- ?: module.copy(packages = afterProcessing.mapNotNull { it.target })
- return AnyWithChanges(processedModule, afterProcessing.any { it.changed })
- }
-
- protected open fun processPackage(dPackage: DPackage): AnyWithChanges<DPackage> {
- val classlikes = dPackage.classlikes.map { processClassLike(it) }
- val typeAliases = dPackage.typealiases.map { processTypeAlias(it) }
- val functions = dPackage.functions.map { processFunction(it) }
- val properies = dPackage.properties.map { processProperty(it) }
-
- val wasChanged = (classlikes + typeAliases + functions + properies).any { it.changed }
- return (dPackage.takeIf { !wasChanged } ?: dPackage.copy(
- classlikes = classlikes.mapNotNull { it.target },
- typealiases = typeAliases.mapNotNull { it.target },
- functions = functions.mapNotNull { it.target },
- properties = properies.mapNotNull { it.target }
- )).let { processedPackage -> AnyWithChanges(processedPackage, wasChanged) }
- }
-
- protected open fun processClassLike(classlike: DClasslike): AnyWithChanges<DClasslike> {
- val functions = classlike.functions.map { processFunction(it) }
- val classlikes = classlike.classlikes.map { processClassLike(it) }
- val properties = classlike.properties.map { processProperty(it) }
- val companion = (classlike as? WithCompanion)?.companion?.let { processClassLike(it) }
-
- val wasClasslikeChanged = (functions + classlikes + properties).any { it.changed } || companion?.changed == true
- return when (classlike) {
- is DClass -> {
- val constructors = classlike.constructors.map { processFunction(it) }
- val generics = classlike.generics.map { processTypeParameter(it) }
- val wasClassChange =
- wasClasslikeChanged || constructors.any { it.changed } || generics.any { it.changed }
- (classlike.takeIf { !wasClassChange } ?: classlike.copy(
- functions = functions.mapNotNull { it.target },
- classlikes = classlikes.mapNotNull { it.target },
- properties = properties.mapNotNull { it.target },
- constructors = constructors.mapNotNull { it.target },
- generics = generics.mapNotNull { it.target },
- companion = companion?.target as? DObject
- )).let { AnyWithChanges(it, wasClassChange) }
- }
- is DInterface -> {
- val generics = classlike.generics.map { processTypeParameter(it) }
- val wasInterfaceChange = wasClasslikeChanged || generics.any { it.changed }
- (classlike.takeIf { !wasInterfaceChange } ?: classlike.copy(
- functions = functions.mapNotNull { it.target },
- classlikes = classlikes.mapNotNull { it.target },
- properties = properties.mapNotNull { it.target },
- generics = generics.mapNotNull { it.target },
- companion = companion?.target as? DObject
- )).let { AnyWithChanges(it, wasClasslikeChanged) }
- }
- is DObject -> (classlike.takeIf { !wasClasslikeChanged } ?: classlike.copy(
- functions = functions.mapNotNull { it.target },
- classlikes = classlikes.mapNotNull { it.target },
- properties = properties.mapNotNull { it.target },
- )).let { AnyWithChanges(it, wasClasslikeChanged) }
- is DAnnotation -> {
- val constructors = classlike.constructors.map { processFunction(it) }
- val generics = classlike.generics.map { processTypeParameter(it) }
- val wasClassChange =
- wasClasslikeChanged || constructors.any { it.changed } || generics.any { it.changed }
- (classlike.takeIf { !wasClassChange } ?: classlike.copy(
- functions = functions.mapNotNull { it.target },
- classlikes = classlikes.mapNotNull { it.target },
- properties = properties.mapNotNull { it.target },
- constructors = constructors.mapNotNull { it.target },
- generics = generics.mapNotNull { it.target },
- companion = companion?.target as? DObject
- )).let { AnyWithChanges(it, wasClassChange) }
- }
- is DEnum -> {
- val constructors = classlike.constructors.map { processFunction(it) }
- val entries = classlike.entries.map { processEnumEntry(it) }
- val wasClassChange =
- wasClasslikeChanged || (constructors + entries).any { it.changed }
- (classlike.takeIf { !wasClassChange } ?: classlike.copy(
- functions = functions.mapNotNull { it.target },
- classlikes = classlikes.mapNotNull { it.target },
- properties = properties.mapNotNull { it.target },
- constructors = constructors.mapNotNull { it.target },
- companion = companion?.target as? DObject,
- entries = entries.mapNotNull { it.target }
- )).let { AnyWithChanges(it, wasClassChange) }
- }
- }
- }
-
- protected open fun processEnumEntry(dEnumEntry: DEnumEntry): AnyWithChanges<DEnumEntry> {
- val functions = dEnumEntry.functions.map { processFunction(it) }
- val properties = dEnumEntry.properties.map { processProperty(it) }
- val classlikes = dEnumEntry.classlikes.map { processClassLike(it) }
-
- val wasChanged = (functions + properties + classlikes).any { it.changed }
- return (dEnumEntry.takeIf { !wasChanged } ?: dEnumEntry.copy(
- functions = functions.mapNotNull { it.target },
- classlikes = classlikes.mapNotNull { it.target },
- properties = properties.mapNotNull { it.target },
- )).let { AnyWithChanges(it, wasChanged) }
- }
-
- protected open fun processFunction(dFunction: DFunction): AnyWithChanges<DFunction> {
- val type = processBound(dFunction.type)
- val parameters = dFunction.parameters.map { processParameter(it) }
- val receiver = dFunction.receiver?.let { processParameter(it) }
- val generics = dFunction.generics.map { processTypeParameter(it) }
-
- val wasChanged = parameters.any { it.changed } || receiver?.changed == true
- || type.changed || generics.any { it.changed }
- return (dFunction.takeIf { !wasChanged } ?: dFunction.copy(
- type = type.target ?: dFunction.type,
- parameters = parameters.mapNotNull { it.target },
- receiver = receiver?.target,
- generics = generics.mapNotNull { it.target },
- )).let { AnyWithChanges(it, wasChanged) }
- }
-
- protected open fun processProperty(dProperty: DProperty): AnyWithChanges<DProperty> {
- val getter = dProperty.getter?.let { processFunction(it) }
- val setter = dProperty.setter?.let { processFunction(it) }
- val type = processBound(dProperty.type)
- val generics = dProperty.generics.map { processTypeParameter(it) }
-
- val wasChanged = getter?.changed == true || setter?.changed == true
- || type.changed || generics.any { it.changed }
- return (dProperty.takeIf { !wasChanged } ?: dProperty.copy(
- type = type.target ?: dProperty.type,
- setter = setter?.target,
- getter = getter?.target,
- generics = generics.mapNotNull { it.target }
- )).let { AnyWithChanges(it, wasChanged) }
- }
-
- protected open fun processParameter(dParameter: DParameter): AnyWithChanges<DParameter> {
- val type = processBound(dParameter.type)
-
- val wasChanged = type.changed
- return (dParameter.takeIf { !wasChanged } ?: dParameter.copy(
- type = type.target ?: dParameter.type,
- )).let { AnyWithChanges(it, wasChanged) }
- }
-
- protected open fun processTypeParameter(dTypeParameter: DTypeParameter): AnyWithChanges<DTypeParameter> {
- val bounds = dTypeParameter.bounds.map { processBound(it) }
-
- val wasChanged = bounds.any { it.changed }
- return (dTypeParameter.takeIf { !wasChanged } ?: dTypeParameter.copy(
- bounds = bounds.mapIndexed { i, v -> v.target ?: dTypeParameter.bounds[i] }
- )).let { AnyWithChanges(it, wasChanged) }
- }
-
- protected open fun processBound(bound: Bound): AnyWithChanges<Bound> {
- return when(bound) {
- is GenericTypeConstructor -> processGenericTypeConstructor(bound)
- is FunctionalTypeConstructor -> processFunctionalTypeConstructor(bound)
- else -> AnyWithChanges(bound, false)
- }
- }
-
- protected open fun processVariance(variance: Variance<*>): AnyWithChanges<Variance<*>> {
- val bound = processBound(variance.inner)
- if (!bound.changed)
- return AnyWithChanges(variance, false)
- return when (variance) {
- is Covariance<*> -> AnyWithChanges(
- Covariance(bound.target ?: variance.inner), true)
- is Contravariance<*> -> AnyWithChanges(
- Contravariance(bound.target ?: variance.inner), true)
- is Invariance<*> -> AnyWithChanges(
- Invariance(bound.target ?: variance.inner), true)
- else -> AnyWithChanges(variance, false)
- }
- }
-
- protected open fun processProjection(projection: Projection): AnyWithChanges<Projection> =
- when (projection) {
- is Bound -> processBound(projection)
- is Variance<Bound> -> processVariance(projection)
- else -> AnyWithChanges(projection, false)
- }
-
- protected open fun processGenericTypeConstructor(
- genericTypeConstructor: GenericTypeConstructor
- ): AnyWithChanges<GenericTypeConstructor> {
- val projections = genericTypeConstructor.projections.map { processProjection(it) }
-
- val wasChanged = projections.any { it.changed }
- return (genericTypeConstructor.takeIf { !wasChanged } ?: genericTypeConstructor.copy(
- projections = projections.mapNotNull { it.target }
- )).let { AnyWithChanges(it, wasChanged) }
- }
-
- protected open fun processFunctionalTypeConstructor(
- functionalTypeConstructor: FunctionalTypeConstructor
- ): AnyWithChanges<FunctionalTypeConstructor> {
- val projections = functionalTypeConstructor.projections.map { processProjection(it) }
-
- val wasChanged = projections.any { it.changed }
- return (functionalTypeConstructor.takeIf { !wasChanged } ?: functionalTypeConstructor.copy(
- projections = projections.mapNotNull { it.target }
- )).let { AnyWithChanges(it, wasChanged) }
- }
-
- protected open fun processTypeAlias(dTypeAlias: DTypeAlias): AnyWithChanges<DTypeAlias> {
- val underlyingType = dTypeAlias.underlyingType.mapValues { processBound(it.value) }
- val generics = dTypeAlias.generics.map { processTypeParameter(it) }
-
- val wasChanged = underlyingType.any { it.value.changed } || generics.any { it.changed }
- return (dTypeAlias.takeIf { !wasChanged } ?: dTypeAlias.copy(
- underlyingType = underlyingType.mapValues { it.value.target ?: dTypeAlias.underlyingType.getValue(it.key) },
- generics = generics.mapNotNull { it.target }
- )).let { AnyWithChanges(it, wasChanged) }
- }
-
-
- protected data class AnyWithChanges<out T>(val target: T?, val changed: Boolean = false)
-}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt
deleted file mode 100644
index 6155a71f..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/DocumentableVisibilityFilterTransformer.kt
+++ /dev/null
@@ -1,388 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.DokkaConfiguration
-import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
-import org.jetbrains.dokka.DokkaDefaults
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer
-
-public class DocumentableVisibilityFilterTransformer(
- public val context: DokkaContext
-) : PreMergeDocumentableTransformer {
-
- override fun invoke(modules: List<DModule>): List<DModule> {
- return modules.map { original ->
- val sourceSet = original.sourceSets.single()
- val packageOptions = sourceSet.perPackageOptions
- DocumentableVisibilityFilter(packageOptions, sourceSet).processModule(original)
- }
- }
-
- private class DocumentableVisibilityFilter(
- val packageOptions: List<DokkaConfiguration.PackageOptions>,
- val globalOptions: DokkaSourceSet
- ) {
- fun Visibility.isAllowedInPackage(packageName: String?) = when (this) {
- is JavaVisibility.Public,
- is KotlinVisibility.Public -> isAllowedInPackage(packageName, DokkaConfiguration.Visibility.PUBLIC)
- is JavaVisibility.Private,
- is KotlinVisibility.Private -> isAllowedInPackage(packageName, DokkaConfiguration.Visibility.PRIVATE)
- is JavaVisibility.Protected,
- is KotlinVisibility.Protected -> isAllowedInPackage(packageName, DokkaConfiguration.Visibility.PROTECTED)
- is KotlinVisibility.Internal -> isAllowedInPackage(packageName, DokkaConfiguration.Visibility.INTERNAL)
- is JavaVisibility.Default -> isAllowedInPackage(packageName, DokkaConfiguration.Visibility.PACKAGE)
- }
-
- private fun isAllowedInPackage(packageName: String?, visibility: DokkaConfiguration.Visibility): Boolean {
- val packageOpts = packageName.takeIf { it != null }?.let { name ->
- packageOptions.firstOrNull { Regex(it.matchingRegex).matches(name) }
- }
-
- val (documentedVisibilities, includeNonPublic) =
- @Suppress("DEPRECATION") // for includeNonPublic, preserve backwards compatibility
- when {
- packageOpts != null -> packageOpts.documentedVisibilities to packageOpts.includeNonPublic
- else -> globalOptions.documentedVisibilities to globalOptions.includeNonPublic
- }
-
- // if `documentedVisibilities` is explicitly overridden by the user (i.e. not default value by reference),
- // deprecated `includeNonPublic` should not be taken into account, so that only one setting prevails
- val isDocumentedVisibilitiesOverridden = documentedVisibilities !== DokkaDefaults.documentedVisibilities
- return documentedVisibilities.contains(visibility) || (!isDocumentedVisibilitiesOverridden && includeNonPublic)
- }
-
- fun processModule(original: DModule) =
- filterPackages(original.packages).let { (modified, packages) ->
- if (!modified) original
- else
- DModule(
- original.name,
- packages = packages,
- documentation = original.documentation,
- sourceSets = original.sourceSets,
- extra = original.extra
- )
- }
-
-
- private fun filterPackages(packages: List<DPackage>): Pair<Boolean, List<DPackage>> {
- var packagesListChanged = false
- val filteredPackages = packages.map {
- var modified = false
- val functions = filterFunctions(it.functions).let { (listModified, list) ->
- modified = modified || listModified
- list
- }
- val properties = filterProperties(it.properties).let { (listModified, list) ->
- modified = modified || listModified
- list
- }
- val classlikes = filterClasslikes(it.classlikes).let { (listModified, list) ->
- modified = modified || listModified
- list
- }
- val typeAliases = filterTypeAliases(it.typealiases).let { (listModified, list) ->
- modified = modified || listModified
- list
- }
- when {
- !modified -> it
- else -> {
- packagesListChanged = true
- DPackage(
- it.dri,
- functions,
- properties,
- classlikes,
- typeAliases,
- it.documentation,
- it.expectPresentInSet,
- it.sourceSets,
- it.extra
- )
- }
- }
- }
- return Pair(packagesListChanged, filteredPackages)
- }
-
- @Suppress("UNUSED_PARAMETER")
- private fun <T : WithVisibility> alwaysTrue(a: T, p: DokkaSourceSet) = true
- @Suppress("UNUSED_PARAMETER")
- private fun <T : WithVisibility> alwaysFalse(a: T, p: DokkaSourceSet) = false
- @Suppress("UNUSED_PARAMETER")
- private fun <T> alwaysNoModify(a: T, sourceSets: Set<DokkaSourceSet>) = false to a
-
- private fun WithVisibility.visibilityForPlatform(data: DokkaSourceSet): Visibility? = visibility[data]
-
- private fun <T> T.filterPlatforms(
- additionalCondition: (T, DokkaSourceSet) -> Boolean = ::alwaysTrue,
- alternativeCondition: (T, DokkaSourceSet) -> Boolean = ::alwaysFalse
- ) where T : Documentable, T : WithVisibility =
- sourceSets.filter { d ->
- visibilityForPlatform(d)?.isAllowedInPackage(dri.packageName) == true &&
- additionalCondition(this, d) ||
- alternativeCondition(this, d)
- }.toSet()
-
- private fun <T> List<T>.transform(
- additionalCondition: (T, DokkaSourceSet) -> Boolean = ::alwaysTrue,
- alternativeCondition: (T, DokkaSourceSet) -> Boolean = ::alwaysFalse,
- modify: (T, Set<DokkaSourceSet>) -> Pair<Boolean, T> = ::alwaysNoModify,
- recreate: (T, Set<DokkaSourceSet>) -> T,
- ): Pair<Boolean, List<T>> where T : Documentable, T : WithVisibility {
- var changed = false
- val values = mapNotNull { t ->
- val filteredPlatforms = t.filterPlatforms(additionalCondition, alternativeCondition)
- when (filteredPlatforms.size) {
- t.visibility.size -> {
- val (wasChanged, element) = modify(t, filteredPlatforms)
- changed = changed || wasChanged
- element
- }
- 0 -> {
- changed = true
- null
- }
- else -> {
- changed = true
- recreate(t, filteredPlatforms)
- }
- }
- }
- return Pair(changed, values)
- }
-
- private fun filterFunctions(
- functions: List<DFunction>,
- additionalCondition: (DFunction, DokkaSourceSet) -> Boolean = ::alwaysTrue
- ) =
- functions.transform(additionalCondition) { original, filteredPlatforms ->
- with(original) {
- copy(
- documentation = documentation.filtered(filteredPlatforms),
- expectPresentInSet = expectPresentInSet.filtered(filteredPlatforms),
- sources = sources.filtered(filteredPlatforms),
- visibility = visibility.filtered(filteredPlatforms),
- generics = generics.mapNotNull { it.filter(filteredPlatforms) },
- sourceSets = filteredPlatforms,
- )
- }
- }
-
- private fun hasVisibleAccessorsForPlatform(property: DProperty, data: DokkaSourceSet) =
- property.getter?.visibilityForPlatform(data)?.isAllowedInPackage(property.dri.packageName) == true ||
- property.setter?.visibilityForPlatform(data)?.isAllowedInPackage(property.dri.packageName) == true
-
- private fun filterProperties(
- properties: List<DProperty>,
- additionalCondition: (DProperty, DokkaSourceSet) -> Boolean = ::alwaysTrue,
- additionalConditionAccessors: (DFunction, DokkaSourceSet) -> Boolean = ::alwaysTrue
- ): Pair<Boolean, List<DProperty>> {
-
- val modifier: (DProperty, Set<DokkaSourceSet>) -> Pair<Boolean, DProperty> =
- { original, _ ->
- val setter = original.setter?.let { filterFunctions(listOf(it), additionalConditionAccessors) }
- val getter = original.getter?.let { filterFunctions(listOf(it), additionalConditionAccessors) }
-
- val modified = setter?.first == true || getter?.first == true
-
- val property =
- if (modified)
- original.copy(
- setter = setter?.second?.firstOrNull(),
- getter = getter?.second?.firstOrNull()
- )
- else original
- modified to property
- }
-
- return properties.transform(
- additionalCondition,
- ::hasVisibleAccessorsForPlatform,
- modifier
- ) { original, filteredPlatforms ->
- val setter = original.setter?.let { filterFunctions(listOf(it), additionalConditionAccessors) }
- val getter = original.getter?.let { filterFunctions(listOf(it), additionalConditionAccessors) }
-
- with(original) {
- copy(
- documentation = documentation.filtered(filteredPlatforms),
- expectPresentInSet = expectPresentInSet.filtered(filteredPlatforms),
- sources = sources.filtered(filteredPlatforms),
- visibility = visibility.filtered(filteredPlatforms),
- sourceSets = filteredPlatforms,
- generics = generics.mapNotNull { it.filter(filteredPlatforms) },
- setter = setter?.second?.firstOrNull(),
- getter = getter?.second?.firstOrNull()
- )
- }
- }
- }
-
- private fun filterEnumEntries(entries: List<DEnumEntry>, filteredPlatforms: Set<DokkaSourceSet>): Pair<Boolean, List<DEnumEntry>> =
- entries.fold(Pair(false, emptyList())) { acc, entry ->
- val intersection = filteredPlatforms.intersect(entry.sourceSets)
- if (intersection.isEmpty()) Pair(true, acc.second)
- else {
- val functions = filterFunctions(entry.functions) { _, data -> data in intersection }
- val properties = filterProperties(entry.properties) { _, data -> data in intersection }
- val classlikes = filterClasslikes(entry.classlikes) { _, data -> data in intersection }
-
- DEnumEntry(
- entry.dri,
- entry.name,
- entry.documentation.filtered(intersection),
- entry.expectPresentInSet.filtered(filteredPlatforms),
- functions.second,
- properties.second,
- classlikes.second,
- intersection,
- entry.extra
- ).let { Pair(functions.first || properties.first || classlikes.first, acc.second + it) }
- }
- }
-
- private fun filterClasslikes(
- classlikeList: List<DClasslike>,
- additionalCondition: (DClasslike, DokkaSourceSet) -> Boolean = ::alwaysTrue
- ): Pair<Boolean, List<DClasslike>> {
- var classlikesListChanged = false
- val filteredClasslikes: List<DClasslike> = classlikeList.mapNotNull {
- with(it) {
- val filteredPlatforms = filterPlatforms(additionalCondition)
- if (filteredPlatforms.isEmpty()) {
- classlikesListChanged = true
- null
- } else {
- var modified = sourceSets.size != filteredPlatforms.size
- val functions =
- filterFunctions(functions) { _, data -> data in filteredPlatforms }.let { (listModified, list) ->
- modified = modified || listModified
- list
- }
- val properties =
- filterProperties(properties) { _, data -> data in filteredPlatforms }.let { (listModified, list) ->
- modified = modified || listModified
- list
- }
- val classlikes =
- filterClasslikes(classlikes) { _, data -> data in filteredPlatforms }.let { (listModified, list) ->
- modified = modified || listModified
- list
- }
- val companion =
- if (this is WithCompanion) filterClasslikes(listOfNotNull(companion)) { _, data -> data in filteredPlatforms }.let { (listModified, list) ->
- modified = modified || listModified
- list.firstOrNull() as DObject?
- } else null
- val constructors = if (this is WithConstructors)
- filterFunctions(constructors) { _, data -> data in filteredPlatforms }.let { (listModified, list) ->
- modified = modified || listModified
- list
- } else emptyList()
- val generics =
- if (this is WithGenerics) generics.mapNotNull { param -> param.filter(filteredPlatforms) } else emptyList()
- val enumEntries =
- if (this is DEnum) filterEnumEntries(entries, filteredPlatforms).let { (listModified, list) ->
- modified = modified || listModified
- list
- } else emptyList()
- classlikesListChanged = classlikesListChanged || modified
- when {
- !modified -> this
- this is DClass -> copy(
- constructors = constructors,
- functions = functions,
- properties = properties,
- classlikes = classlikes,
- sources = sources.filtered(filteredPlatforms),
- visibility = visibility.filtered(filteredPlatforms),
- companion = companion,
- generics = generics,
- supertypes = supertypes.filtered(filteredPlatforms),
- documentation = documentation.filtered(filteredPlatforms),
- expectPresentInSet = expectPresentInSet.filtered(filteredPlatforms),
- sourceSets = filteredPlatforms
- )
- this is DAnnotation -> copy(
- documentation = documentation.filtered(filteredPlatforms),
- expectPresentInSet = expectPresentInSet.filtered(filteredPlatforms),
- sources = sources.filtered(filteredPlatforms),
- functions = functions,
- properties = properties,
- classlikes = classlikes,
- visibility = visibility.filtered(filteredPlatforms),
- companion = companion,
- constructors = constructors,
- generics = generics,
- sourceSets = filteredPlatforms
- )
- this is DEnum -> copy(
- entries = enumEntries,
- documentation = documentation.filtered(filteredPlatforms),
- expectPresentInSet = expectPresentInSet.filtered(filteredPlatforms),
- sources = sources.filtered(filteredPlatforms),
- functions = functions,
- properties = properties,
- classlikes = classlikes,
- visibility = visibility.filtered(filteredPlatforms),
- companion = companion,
- constructors = constructors,
- supertypes = supertypes.filtered(filteredPlatforms),
- sourceSets = filteredPlatforms
- )
- this is DInterface -> copy(
- documentation = documentation.filtered(filteredPlatforms),
- expectPresentInSet = expectPresentInSet.filtered(filteredPlatforms),
- sources = sources.filtered(filteredPlatforms),
- functions = functions,
- properties = properties,
- classlikes = classlikes,
- visibility = visibility.filtered(filteredPlatforms),
- companion = companion,
- generics = generics,
- supertypes = supertypes.filtered(filteredPlatforms),
- sourceSets = filteredPlatforms
- )
- this is DObject -> copy(
- documentation = documentation.filtered(filteredPlatforms),
- expectPresentInSet = expectPresentInSet.filtered(filteredPlatforms),
- sources = sources.filtered(filteredPlatforms),
- functions = functions,
- properties = properties,
- classlikes = classlikes,
- supertypes = supertypes.filtered(filteredPlatforms),
- sourceSets = filteredPlatforms
- )
- else -> null
- }
- }
- }
- }
- return Pair(classlikesListChanged, filteredClasslikes)
- }
-
- private fun filterTypeAliases(
- typeAliases: List<DTypeAlias>,
- additionalCondition: (DTypeAlias, DokkaSourceSet) -> Boolean = ::alwaysTrue
- ) =
- typeAliases.transform(additionalCondition) { original, filteredPlatforms ->
- with(original) {
- copy(
- documentation = documentation.filtered(filteredPlatforms),
- expectPresentInSet = expectPresentInSet.filtered(filteredPlatforms),
- underlyingType = underlyingType.filtered(filteredPlatforms),
- visibility = visibility.filtered(filteredPlatforms),
- generics = generics.mapNotNull { it.filter(filteredPlatforms) },
- sourceSets = filteredPlatforms,
- )
- }
- }
- }
-}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/EmptyModulesFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/EmptyModulesFilterTransformer.kt
deleted file mode 100644
index 7a2387dc..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/EmptyModulesFilterTransformer.kt
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.model.DModule
-import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer
-
-public class EmptyModulesFilterTransformer : PreMergeDocumentableTransformer {
- override fun invoke(modules: List<DModule>): List<DModule> {
- return modules.filter { it.children.isNotEmpty() }
- }
-}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt
deleted file mode 100644
index 30ac8f70..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/EmptyPackagesFilterTransformer.kt
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.model.DModule
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer
-import org.jetbrains.dokka.transformers.documentation.sourceSet
-
-public class EmptyPackagesFilterTransformer(
- public val context: DokkaContext
-) : PreMergeDocumentableTransformer {
- override fun invoke(modules: List<DModule>): List<DModule> {
- return modules.mapNotNull(::filterModule)
- }
-
- private fun filterModule(module: DModule): DModule? {
- val nonEmptyPackages = module.packages.filterNot { pkg ->
- sourceSet(pkg).skipEmptyPackages && pkg.children.isEmpty()
- }
-
- return when {
- nonEmptyPackages == module.packages -> module
- nonEmptyPackages.isEmpty() -> null
- else -> module.copy(packages = nonEmptyPackages)
- }
- }
-}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ExtensionExtractorTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/ExtensionExtractorTransformer.kt
deleted file mode 100644
index e6102622..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/ExtensionExtractorTransformer.kt
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import kotlinx.coroutines.*
-import kotlinx.coroutines.channels.*
-import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.links.DriOfAny
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.model.properties.ExtraProperty
-import org.jetbrains.dokka.model.properties.MergeStrategy
-import org.jetbrains.dokka.model.properties.plus
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.plugability.plugin
-import org.jetbrains.dokka.plugability.querySingle
-import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer
-import org.jetbrains.dokka.utilities.parallelForEach
-import org.jetbrains.dokka.utilities.parallelMap
-import org.jetbrains.dokka.analysis.kotlin.internal.InternalKotlinAnalysisPlugin
-
-public class ExtensionExtractorTransformer : DocumentableTransformer {
- override fun invoke(original: DModule, context: DokkaContext): DModule = runBlocking(Dispatchers.Default) {
- val classGraph = async {
- if (!context.configuration.suppressInheritedMembers)
- context.plugin<InternalKotlinAnalysisPlugin>().querySingle { fullClassHierarchyBuilder }.build(original)
- else
- emptyMap()
- }
-
- val channel = Channel<Pair<DRI, Callable>>(10)
- launch {
- original.packages.parallelForEach { collectExtensions(it, channel) }
- channel.close()
- }
- val extensionMap = channel.toList().toMultiMap()
-
- val newPackages = original.packages.parallelMap { it.addExtensionInformation(classGraph.await(), extensionMap) }
- original.copy(packages = newPackages)
- }
-
- private suspend fun <T : Documentable> T.addExtensionInformation(
- classGraph: SourceSetDependent<Map<DRI, List<DRI>>>,
- extensionMap: Map<DRI, List<Callable>>
- ): T = coroutineScope {
- val newClasslikes = (this@addExtensionInformation as? WithScope)
- ?.classlikes
- ?.map { async { it.addExtensionInformation(classGraph, extensionMap) } }
- .orEmpty()
-
- @Suppress("UNCHECKED_CAST")
- when (this@addExtensionInformation) {
- is DPackage -> {
- val newTypealiases = typealiases.map { async { it.addExtensionInformation(classGraph, extensionMap) } }
- copy(classlikes = newClasslikes.awaitAll(), typealiases = newTypealiases.awaitAll())
- }
-
- is DClass -> copy(
- classlikes = newClasslikes.awaitAll(),
- extra = extra + findExtensions(classGraph, extensionMap)
- )
-
- is DEnum -> copy(
- classlikes = newClasslikes.awaitAll(),
- extra = extra + findExtensions(classGraph, extensionMap)
- )
-
- is DInterface -> copy(
- classlikes = newClasslikes.awaitAll(),
- extra = extra + findExtensions(classGraph, extensionMap)
- )
-
- is DObject -> copy(
- classlikes = newClasslikes.awaitAll(),
- extra = extra + findExtensions(classGraph, extensionMap)
- )
-
- is DAnnotation -> copy(
- classlikes = newClasslikes.awaitAll(),
- extra = extra + findExtensions(classGraph, extensionMap)
- )
-
- is DTypeAlias -> copy(extra = extra + findExtensions(classGraph, extensionMap))
- else -> throw IllegalStateException(
- "${this@addExtensionInformation::class.simpleName} is not expected to have extensions"
- )
- } as T
- }
-
- private suspend fun collectExtensions(
- documentable: Documentable,
- channel: SendChannel<Pair<DRI, Callable>>
- ): Unit = coroutineScope {
- if (documentable is WithScope) {
- documentable.classlikes.forEach {
- launch { collectExtensions(it, channel) }
- }
-
- if (documentable is DObject || documentable is DPackage) {
- (documentable.properties.asSequence() + documentable.functions.asSequence())
- .flatMap { it.asPairsWithReceiverDRIs() }
- .forEach { channel.send(it) }
- }
- }
- }
-
- private fun <T : Documentable> T.findExtensions(
- classGraph: SourceSetDependent<Map<DRI, List<DRI>>>,
- extensionMap: Map<DRI, List<Callable>>
- ): CallableExtensions? {
- val resultSet = mutableSetOf<Callable>()
-
- fun collectFrom(element: DRI) {
- extensionMap[element]?.let { resultSet.addAll(it) }
- sourceSets.forEach { sourceSet -> classGraph[sourceSet]?.get(element)?.forEach { collectFrom(it) } }
- }
- collectFrom(dri)
-
- return if (resultSet.isEmpty()) null else CallableExtensions(resultSet)
- }
-
- private fun Callable.asPairsWithReceiverDRIs(): Sequence<Pair<DRI, Callable>> =
- receiver?.type?.let { findReceiverDRIs(it) }.orEmpty().map { it to this }
-
- // In normal cases we return at max one DRI, but sometimes receiver type can be bound by more than one type constructor
- // for example `fun <T> T.example() where T: A, T: B` is extension of both types A and B
- // another one `typealias A = B`
- // Note: in some cases returning empty sequence doesn't mean that we cannot determine the DRI but only that we don't
- // care about it since there is nowhere to put documentation of given extension.
- private fun Callable.findReceiverDRIs(bound: Bound): Sequence<DRI> = when (bound) {
- is Nullable -> findReceiverDRIs(bound.inner)
- is DefinitelyNonNullable -> findReceiverDRIs(bound.inner)
- is TypeParameter ->
- if (this is DFunction && bound.dri == this.dri)
- generics.find { it.name == bound.name }?.bounds?.asSequence()?.flatMap { findReceiverDRIs(it) }.orEmpty()
- else
- emptySequence()
-
- is TypeConstructor -> sequenceOf(bound.dri)
- is PrimitiveJavaType -> emptySequence()
- is Void -> emptySequence()
- is JavaObject -> sequenceOf(DriOfAny)
- is Dynamic -> sequenceOf(DriOfAny)
- is UnresolvedBound -> emptySequence()
- is TypeAliased -> findReceiverDRIs(bound.typeAlias) + findReceiverDRIs(bound.inner)
- }
-
- private fun <T, U> Iterable<Pair<T, U>>.toMultiMap(): Map<T, List<U>> =
- groupBy(Pair<T, *>::first, Pair<*, U>::second)
-}
-
-public data class CallableExtensions(val extensions: Set<Callable>) : ExtraProperty<Documentable> {
- public companion object Key : ExtraProperty.Key<Documentable, CallableExtensions> {
- override fun mergeStrategyFor(left: CallableExtensions, right: CallableExtensions): MergeStrategy<Documentable> =
- MergeStrategy.Replace(CallableExtensions(left.extensions + right.extensions))
- }
-
- override val key: Key = Key
-}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/InheritedEntriesDocumentableFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/InheritedEntriesDocumentableFilterTransformer.kt
deleted file mode 100644
index d9b7053a..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/InheritedEntriesDocumentableFilterTransformer.kt
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.model.Documentable
-import org.jetbrains.dokka.model.InheritedMember
-import org.jetbrains.dokka.model.properties.WithExtraProperties
-import org.jetbrains.dokka.plugability.DokkaContext
-
-public class InheritedEntriesDocumentableFilterTransformer(
- context: DokkaContext
-) : SuppressedByConditionDocumentableFilterTransformer(context) {
-
- override fun shouldBeSuppressed(d: Documentable): Boolean {
- @Suppress("UNCHECKED_CAST")
- val inheritedMember = (d as? WithExtraProperties<Documentable>)?.extra?.get(InheritedMember)
- val containsInheritedFrom = inheritedMember?.inheritedFrom?.any { entry -> entry.value != null } ?: false
-
- return context.configuration.suppressInheritedMembers && containsInheritedFrom
- }
-}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/InheritorsExtractorTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/InheritorsExtractorTransformer.kt
deleted file mode 100644
index 2c7d6b89..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/InheritorsExtractorTransformer.kt
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
-import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.model.properties.ExtraProperty
-import org.jetbrains.dokka.model.properties.MergeStrategy
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer
-
-public class InheritorsExtractorTransformer : DocumentableTransformer {
- override fun invoke(original: DModule, context: DokkaContext): DModule =
- original.generateInheritanceMap().let { inheritanceMap -> original.appendInheritors(inheritanceMap) as DModule }
-
- private fun <T : Documentable> T.appendInheritors(inheritanceMap: Map<DokkaSourceSet, Map<DRI, List<DRI>>>): Documentable =
- InheritorsInfo(inheritanceMap.getForDRI(dri)).let { info ->
- when (this) {
- is DModule -> copy(packages = packages.map { it.appendInheritors(inheritanceMap) as DPackage })
- is DPackage -> copy(classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
- is DClass -> if (info.isNotEmpty()) {
- copy(
- extra = extra + info,
- classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
- } else {
- copy(classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
- }
- is DEnum -> if (info.isNotEmpty()) {
- copy(
- extra = extra + info,
- classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
- } else {
- copy(classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
- }
- is DInterface -> if (info.isNotEmpty()) {
- copy(
- extra = extra + info,
- classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
- } else {
- copy(classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
- }
- is DObject -> copy(classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
- is DAnnotation -> copy(classlikes = classlikes.map { it.appendInheritors(inheritanceMap) as DClasslike })
- else -> this
- }
- }
-
- private fun InheritorsInfo.isNotEmpty() = this.value.values.fold(0) { acc, list -> acc + list.size } > 0
-
- private fun Map<DokkaSourceSet, Map<DRI, List<DRI>>>.getForDRI(dri: DRI) =
- map { (v, k) ->
- v to k[dri]
- }.associate { (k, v) -> k to v.orEmpty() }
-
- private fun DModule.generateInheritanceMap() =
- getInheritanceEntriesRec().filterNot { it.second.isEmpty() }.groupBy({ it.first }) { it.second }
- .map { (k, v) ->
- k to v.flatMap { p -> p.groupBy({ it.first }) { it.second }.toList() }
- .groupBy({ it.first }) { it.second }.map { (k2, v2) -> k2 to v2.flatten() }.toMap()
- }.filter { it.second.values.isNotEmpty() }.toMap()
-
- private fun <T : Documentable> T.getInheritanceEntriesRec(): List<Pair<DokkaSourceSet, List<Pair<DRI, DRI>>>> =
- this.toInheritanceEntries() + children.flatMap { it.getInheritanceEntriesRec() }
-
- private fun <T : Documentable> T.toInheritanceEntries() =
- (this as? WithSupertypes)?.let {
- it.supertypes.map { (k, v) -> k to v.map { it.typeConstructor.dri to dri } }
- }.orEmpty()
-
-}
-
-public class InheritorsInfo(
- public val value: SourceSetDependent<List<DRI>>
-) : ExtraProperty<Documentable> {
- public companion object : ExtraProperty.Key<Documentable, InheritorsInfo> {
- override fun mergeStrategyFor(left: InheritorsInfo, right: InheritorsInfo): MergeStrategy<Documentable> =
- MergeStrategy.Replace(
- InheritorsInfo(
- (left.value.entries.toList() + right.value.entries.toList())
- .groupBy({ it.key }) { it.value }
- .map { (k, v) -> k to v.flatten() }.toMap()
- )
- )
- }
-
- override val key: ExtraProperty.Key<Documentable, *> = InheritorsInfo
-}
-
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/KotlinArrayDocumentableReplacerTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/KotlinArrayDocumentableReplacerTransformer.kt
deleted file mode 100644
index 7a360cb8..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/KotlinArrayDocumentableReplacerTransformer.kt
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.Platform
-import org.jetbrains.dokka.links.DRI
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.plugability.DokkaContext
-
-public class KotlinArrayDocumentableReplacerTransformer(
- context: DokkaContext
-): DocumentableReplacerTransformer(context) {
-
- private fun Documentable.isJVM() =
- sourceSets.any{ it.analysisPlatform == Platform.jvm }
-
- override fun processGenericTypeConstructor(genericTypeConstructor: GenericTypeConstructor): AnyWithChanges<GenericTypeConstructor> =
- genericTypeConstructor.takeIf { genericTypeConstructor.dri == DRI("kotlin", "Array") }
- ?.let {
- with(it.projections.firstOrNull() as? Variance<Bound>) {
- with(this?.inner as? GenericTypeConstructor) {
- when (this?.dri) {
- DRI("kotlin", "Int") ->
- AnyWithChanges(
- GenericTypeConstructor(DRI("kotlin", "IntArray"), emptyList()),
- true)
- DRI("kotlin", "Boolean") ->
- AnyWithChanges(
- GenericTypeConstructor(DRI("kotlin", "BooleanArray"), emptyList()),
- true)
- DRI("kotlin", "Float") ->
- AnyWithChanges(
- GenericTypeConstructor(DRI("kotlin", "FloatArray"), emptyList()),
- true)
- DRI("kotlin", "Double") ->
- AnyWithChanges(
- GenericTypeConstructor(DRI("kotlin", "DoubleArray"), emptyList()),
- true)
- DRI("kotlin", "Long") ->
- AnyWithChanges(
- GenericTypeConstructor(DRI("kotlin", "LongArray"), emptyList()),
- true)
- DRI("kotlin", "Short") ->
- AnyWithChanges(
- GenericTypeConstructor(DRI("kotlin", "ShortArray"), emptyList()),
- true)
- DRI("kotlin", "Char") ->
- AnyWithChanges(
- GenericTypeConstructor(DRI("kotlin", "CharArray"), emptyList()),
- true)
- DRI("kotlin", "Byte") ->
- AnyWithChanges(
- GenericTypeConstructor(DRI("kotlin", "ByteArray"), emptyList()),
- true)
- else -> null
- }
- }
- }
- }
- ?: super.processGenericTypeConstructor(genericTypeConstructor)
-
- override fun processModule(module: DModule): AnyWithChanges<DModule> =
- if(module.isJVM())
- super.processModule(module)
- else AnyWithChanges(module)
-}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt
deleted file mode 100644
index c19bc15e..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/ModuleAndPackageDocumentationTransformer.kt
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
-import org.jetbrains.dokka.model.DModule
-import org.jetbrains.dokka.model.SourceSetDependent
-import org.jetbrains.dokka.model.doc.DocumentationNode
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.plugability.plugin
-import org.jetbrains.dokka.plugability.querySingle
-import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer
-import org.jetbrains.dokka.analysis.kotlin.internal.InternalKotlinAnalysisPlugin
-import org.jetbrains.dokka.analysis.kotlin.internal.ModuleAndPackageDocumentationReader
-
-internal class ModuleAndPackageDocumentationTransformer(
- private val moduleAndPackageDocumentationReader: ModuleAndPackageDocumentationReader
-) : PreMergeDocumentableTransformer {
-
- constructor(context: DokkaContext) : this(
- context.plugin<InternalKotlinAnalysisPlugin>().querySingle { moduleAndPackageDocumentationReader }
- )
-
- override fun invoke(modules: List<DModule>): List<DModule> {
- return modules.map { module ->
- module.copy(
- documentation = module.documentation + moduleAndPackageDocumentationReader.read(module),
- packages = module.packages.map { pkg ->
- pkg.copy(
- documentation = pkg.documentation + moduleAndPackageDocumentationReader.read(pkg)
- )
- }
- )
- }
- }
-
- private operator fun SourceSetDependent<DocumentationNode>.plus(
- other: SourceSetDependent<DocumentationNode>
- ): Map<DokkaSourceSet, DocumentationNode> =
- (asSequence() + other.asSequence())
- .distinct()
- .groupBy({ it.key }, { it.value })
- .mapValues { (_, values) -> DocumentationNode(values.flatMap { it.children }) }
-
-}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ObviousFunctionsDocumentableFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/ObviousFunctionsDocumentableFilterTransformer.kt
deleted file mode 100644
index 09c6ac87..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/ObviousFunctionsDocumentableFilterTransformer.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.model.DFunction
-import org.jetbrains.dokka.model.Documentable
-import org.jetbrains.dokka.model.ObviousMember
-import org.jetbrains.dokka.plugability.DokkaContext
-
-public class ObviousFunctionsDocumentableFilterTransformer(
- context: DokkaContext
-) : SuppressedByConditionDocumentableFilterTransformer(context) {
- override fun shouldBeSuppressed(d: Documentable): Boolean =
- context.configuration.suppressObviousFunctions && d is DFunction && d.extra[ObviousMember] != null
-}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/ReportUndocumentedTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/ReportUndocumentedTransformer.kt
deleted file mode 100644
index 2b270f18..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/ReportUndocumentedTransformer.kt
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.DokkaConfiguration
-import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.plugability.plugin
-import org.jetbrains.dokka.plugability.querySingle
-import org.jetbrains.dokka.transformers.documentation.DocumentableTransformer
-import org.jetbrains.dokka.analysis.kotlin.internal.InternalKotlinAnalysisPlugin
-
-internal class ReportUndocumentedTransformer : DocumentableTransformer {
-
- override fun invoke(original: DModule, context: DokkaContext): DModule = original.apply {
- withDescendants().forEach { documentable -> invoke(documentable, context) }
- }
-
- private fun invoke(documentable: Documentable, context: DokkaContext) {
- documentable.sourceSets.forEach { sourceSet ->
- if (shouldBeReportedIfNotDocumented(documentable, sourceSet, context)) {
- reportIfUndocumented(context, documentable, sourceSet)
- }
- }
- }
-
- private fun shouldBeReportedIfNotDocumented(
- documentable: Documentable, sourceSet: DokkaSourceSet, context: DokkaContext
- ): Boolean {
- val packageOptionsOrNull = packageOptionsOrNull(sourceSet, documentable)
-
- if (!(packageOptionsOrNull?.reportUndocumented ?: sourceSet.reportUndocumented)) {
- return false
- }
-
- if (documentable is DParameter || documentable is DPackage || documentable is DModule) {
- return false
- }
-
- if (isConstructor(documentable)) {
- return false
- }
-
- val syntheticDetector = context.plugin<InternalKotlinAnalysisPlugin>().querySingle { syntheticDocumentableDetector }
- if (syntheticDetector.isSynthetic(documentable, sourceSet)) {
- return false
- }
-
- if (isPrivateOrInternalApi(documentable, sourceSet)) {
- return false
- }
-
- return true
- }
-
- private fun reportIfUndocumented(
- context: DokkaContext,
- documentable: Documentable,
- sourceSet: DokkaSourceSet
- ) {
- if (isUndocumented(documentable, sourceSet)) {
- val documentableDescription = with(documentable) {
- buildString {
- dri.packageName?.run {
- append(this)
- append("/")
- }
-
- dri.classNames?.run {
- append(this)
- append("/")
- }
-
- dri.callable?.run {
- append(name)
- append("/")
- append(signature())
- append("/")
- }
-
- val sourceSetName = sourceSet.displayName
- if (sourceSetName != null.toString()) {
- append(" ($sourceSetName)")
- }
- }
- }
-
- context.logger.warn("Undocumented: $documentableDescription")
- }
- }
-
- private fun isUndocumented(documentable: Documentable, sourceSet: DokkaSourceSet): Boolean {
- fun resolveDependentSourceSets(sourceSet: DokkaSourceSet): List<DokkaSourceSet> {
- return sourceSet.dependentSourceSets.mapNotNull { sourceSetID ->
- documentable.sourceSets.singleOrNull { it.sourceSetID == sourceSetID }
- }
- }
-
- fun withAllDependentSourceSets(sourceSet: DokkaSourceSet): Sequence<DokkaSourceSet> = sequence {
- yield(sourceSet)
- for (dependentSourceSet in resolveDependentSourceSets(sourceSet)) {
- yieldAll(withAllDependentSourceSets(dependentSourceSet))
- }
- }
-
-
- return withAllDependentSourceSets(sourceSet).all { sourceSetOrDependentSourceSet ->
- documentable.documentation[sourceSetOrDependentSourceSet]?.children?.isEmpty() ?: true
- }
- }
-
- private fun isConstructor(documentable: Documentable): Boolean {
- if (documentable !is DFunction) return false
- return documentable.isConstructor
- }
-
- private fun isPrivateOrInternalApi(documentable: Documentable, sourceSet: DokkaSourceSet): Boolean {
- return when ((documentable as? WithVisibility)?.visibility?.get(sourceSet)) {
- KotlinVisibility.Public -> false
- KotlinVisibility.Private -> true
- KotlinVisibility.Protected -> true
- KotlinVisibility.Internal -> true
- JavaVisibility.Public -> false
- JavaVisibility.Private -> true
- JavaVisibility.Protected -> true
- JavaVisibility.Default -> true
- null -> false
- }
- }
-
- private fun packageOptionsOrNull(
- dokkaSourceSet: DokkaSourceSet,
- documentable: Documentable
- ): DokkaConfiguration.PackageOptions? {
- val packageName = documentable.dri.packageName ?: return null
- return dokkaSourceSet.perPackageOptions
- .filter { packageOptions -> Regex(packageOptions.matchingRegex).matches(packageName) }
- .maxByOrNull { packageOptions -> packageOptions.matchingRegex.length }
- }
-}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/SuppressTagDocumentableFilter.kt b/plugins/base/src/main/kotlin/transformers/documentables/SuppressTagDocumentableFilter.kt
deleted file mode 100644
index 1dbf1262..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/SuppressTagDocumentableFilter.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.model.Documentable
-import org.jetbrains.dokka.model.dfs
-import org.jetbrains.dokka.model.doc.Suppress
-import org.jetbrains.dokka.plugability.DokkaContext
-
-public class SuppressTagDocumentableFilter(
- public val dokkaContext: DokkaContext
-) : SuppressedByConditionDocumentableFilterTransformer(dokkaContext) {
- override fun shouldBeSuppressed(d: Documentable): Boolean =
- d.documentation.any { (_, docs) -> docs.dfs { it is Suppress } != null }
-}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer.kt
deleted file mode 100644
index 4631cece..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConditionDocumentableFilterTransformer.kt
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer
-
-public abstract class SuppressedByConditionDocumentableFilterTransformer(
- public val context: DokkaContext
-) : PreMergeDocumentableTransformer {
- override fun invoke(modules: List<DModule>): List<DModule> =
- modules.map { module ->
- val (documentable, wasChanged) = processModule(module)
- documentable.takeIf { wasChanged } ?: module
- }
-
- public abstract fun shouldBeSuppressed(d: Documentable): Boolean
-
- private fun processModule(module: DModule): DocumentableWithChanges<DModule> {
- val afterProcessing = module.packages.map { processPackage(it) }
- val processedModule = module.takeIf { afterProcessing.none { it.changed } }
- ?: module.copy(packages = afterProcessing.mapNotNull { it.documentable })
- return DocumentableWithChanges(processedModule, afterProcessing.any { it.changed })
- }
-
- private fun processPackage(dPackage: DPackage): DocumentableWithChanges<DPackage> {
- if (shouldBeSuppressed(dPackage)) return DocumentableWithChanges.filteredDocumentable()
-
- val classlikes = dPackage.classlikes.map { processClassLike(it) }
- val typeAliases = dPackage.typealiases.map { processMember(it) }
- val functions = dPackage.functions.map { processMember(it) }
- val properies = dPackage.properties.map { processProperty(it) }
-
- val wasChanged = (classlikes + typeAliases + functions + properies).any { it.changed }
- return (dPackage.takeIf { !wasChanged } ?: dPackage.copy(
- classlikes = classlikes.mapNotNull { it.documentable },
- typealiases = typeAliases.mapNotNull { it.documentable },
- functions = functions.mapNotNull { it.documentable },
- properties = properies.mapNotNull { it.documentable }
- )).let { processedPackage -> DocumentableWithChanges(processedPackage, wasChanged) }
- }
-
- private fun processClassLike(classlike: DClasslike): DocumentableWithChanges<DClasslike> {
- if (shouldBeSuppressed(classlike)) return DocumentableWithChanges.filteredDocumentable()
-
- val functions = classlike.functions.map { processMember(it) }
- val classlikes = classlike.classlikes.map { processClassLike(it) }
- val properties = classlike.properties.map { processProperty(it) }
- val companion = (classlike as? WithCompanion)?.companion?.let { processClassLike(it) }
-
- val wasClasslikeChanged = (functions + classlikes + properties).any { it.changed } || companion?.changed == true
- return when (classlike) {
- is DClass -> {
- val constructors = classlike.constructors.map { processMember(it) }
- val wasClassChange =
- wasClasslikeChanged || constructors.any { it.changed }
- (classlike.takeIf { !wasClassChange } ?: classlike.copy(
- functions = functions.mapNotNull { it.documentable },
- classlikes = classlikes.mapNotNull { it.documentable },
- properties = properties.mapNotNull { it.documentable },
- constructors = constructors.mapNotNull { it.documentable },
- companion = companion?.documentable as? DObject
- )).let { DocumentableWithChanges(it, wasClassChange) }
- }
- is DInterface -> (classlike.takeIf { !wasClasslikeChanged } ?: classlike.copy(
- functions = functions.mapNotNull { it.documentable },
- classlikes = classlikes.mapNotNull { it.documentable },
- properties = properties.mapNotNull { it.documentable },
- companion = companion?.documentable as? DObject
- )).let { DocumentableWithChanges(it, wasClasslikeChanged) }
- is DObject -> (classlike.takeIf { !wasClasslikeChanged } ?: classlike.copy(
- functions = functions.mapNotNull { it.documentable },
- classlikes = classlikes.mapNotNull { it.documentable },
- properties = properties.mapNotNull { it.documentable },
- )).let { DocumentableWithChanges(it, wasClasslikeChanged) }
- is DAnnotation -> {
- val constructors = classlike.constructors.map { processMember(it) }
- val wasClassChange =
- wasClasslikeChanged || constructors.any { it.changed }
- (classlike.takeIf { !wasClassChange } ?: classlike.copy(
- functions = functions.mapNotNull { it.documentable },
- classlikes = classlikes.mapNotNull { it.documentable },
- properties = properties.mapNotNull { it.documentable },
- constructors = constructors.mapNotNull { it.documentable },
- companion = companion?.documentable as? DObject
- )).let { DocumentableWithChanges(it, wasClassChange) }
- }
- is DEnum -> {
- val constructors = classlike.constructors.map { processMember(it) }
- val entries = classlike.entries.map { processEnumEntry(it) }
- val wasClassChange =
- wasClasslikeChanged || (constructors + entries).any { it.changed }
- (classlike.takeIf { !wasClassChange } ?: classlike.copy(
- functions = functions.mapNotNull { it.documentable },
- classlikes = classlikes.mapNotNull { it.documentable },
- properties = properties.mapNotNull { it.documentable },
- constructors = constructors.mapNotNull { it.documentable },
- companion = companion?.documentable as? DObject,
- entries = entries.mapNotNull { it.documentable }
- )).let { DocumentableWithChanges(it, wasClassChange) }
- }
- }
- }
-
- private fun processEnumEntry(dEnumEntry: DEnumEntry): DocumentableWithChanges<DEnumEntry> {
- if (shouldBeSuppressed(dEnumEntry)) return DocumentableWithChanges.filteredDocumentable()
-
- val functions = dEnumEntry.functions.map { processMember(it) }
- val properties = dEnumEntry.properties.map { processProperty(it) }
- val classlikes = dEnumEntry.classlikes.map { processClassLike(it) }
-
- val wasChanged = (functions + properties + classlikes).any { it.changed }
- return (dEnumEntry.takeIf { !wasChanged } ?: dEnumEntry.copy(
- functions = functions.mapNotNull { it.documentable },
- classlikes = classlikes.mapNotNull { it.documentable },
- properties = properties.mapNotNull { it.documentable },
- )).let { DocumentableWithChanges(it, wasChanged) }
- }
-
- private fun processProperty(dProperty: DProperty): DocumentableWithChanges<DProperty> {
- if (shouldBeSuppressed(dProperty)) return DocumentableWithChanges.filteredDocumentable()
-
- val getter = dProperty.getter?.let { processMember(it) } ?: DocumentableWithChanges(null, false)
- val setter = dProperty.setter?.let { processMember(it) } ?: DocumentableWithChanges(null, false)
-
- val wasChanged = getter.changed || setter.changed
- return (dProperty.takeIf { !wasChanged } ?: dProperty.copy(
- getter = getter.documentable,
- setter = setter.documentable
- )).let { DocumentableWithChanges(it, wasChanged) }
- }
-
- private fun <T : Documentable> processMember(member: T): DocumentableWithChanges<T> =
- if (shouldBeSuppressed(member)) DocumentableWithChanges.filteredDocumentable()
- else DocumentableWithChanges(member, false)
-
- private data class DocumentableWithChanges<T : Documentable>(val documentable: T?, val changed: Boolean = false) {
- companion object {
- fun <T : Documentable> filteredDocumentable(): DocumentableWithChanges<T> =
- DocumentableWithChanges(null, true)
- }
- }
-}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConfigurationDocumentableFilterTransformer.kt b/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConfigurationDocumentableFilterTransformer.kt
deleted file mode 100644
index 3195f88d..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/SuppressedByConfigurationDocumentableFilterTransformer.kt
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.model.*
-import org.jetbrains.dokka.plugability.DokkaContext
-import org.jetbrains.dokka.transformers.documentation.PreMergeDocumentableTransformer
-import org.jetbrains.dokka.transformers.documentation.perPackageOptions
-import org.jetbrains.dokka.transformers.documentation.source
-import org.jetbrains.dokka.transformers.documentation.sourceSet
-import java.io.File
-
-public class SuppressedByConfigurationDocumentableFilterTransformer(
- public val context: DokkaContext
-) : PreMergeDocumentableTransformer {
- override fun invoke(modules: List<DModule>): List<DModule> {
- return modules.mapNotNull(::filterModule)
- }
-
- private fun filterModule(module: DModule): DModule? {
- val packages = module.packages.mapNotNull { pkg -> filterPackage(pkg) }
- return when {
- packages == module.packages -> module
- packages.isEmpty() -> null
- else -> module.copy(packages = packages)
- }
- }
-
- private fun filterPackage(pkg: DPackage): DPackage? {
- val options = perPackageOptions(pkg)
- if (options?.suppress == true) {
- return null
- }
-
- val filteredChildren = pkg.children.filterNot(::isSuppressed)
- return when {
- filteredChildren == pkg.children -> pkg
- filteredChildren.isEmpty() -> null
- else -> pkg.copy(
- functions = filteredChildren.filterIsInstance<DFunction>(),
- classlikes = filteredChildren.filterIsInstance<DClasslike>(),
- typealiases = filteredChildren.filterIsInstance<DTypeAlias>(),
- properties = filteredChildren.filterIsInstance<DProperty>()
- )
- }
- }
-
- private fun isSuppressed(documentable: Documentable): Boolean {
- if (documentable !is WithSources) return false
- val sourceFile = File(source(documentable).path).absoluteFile
- return sourceSet(documentable).suppressedFiles.any { suppressedFile ->
- sourceFile.startsWith(suppressedFile.absoluteFile)
- }
- }
-}
diff --git a/plugins/base/src/main/kotlin/transformers/documentables/utils.kt b/plugins/base/src/main/kotlin/transformers/documentables/utils.kt
deleted file mode 100644
index 60a6396a..00000000
--- a/plugins/base/src/main/kotlin/transformers/documentables/utils.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright 2014-2023 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
- */
-
-package org.jetbrains.dokka.base.transformers.documentables
-
-import org.jetbrains.dokka.model.Annotations
-import org.jetbrains.dokka.model.Documentable
-import org.jetbrains.dokka.model.ExceptionInSupertypes
-import org.jetbrains.dokka.model.properties.WithExtraProperties
-
-public val <T : Documentable> WithExtraProperties<T>.isException: Boolean
- get() = extra[ExceptionInSupertypes] != null
-
-
-public val <T : Documentable> WithExtraProperties<T>.deprecatedAnnotation: Annotations.Annotation?
- get() = extra[Annotations]?.let { annotations ->
- annotations.directAnnotations.values.flatten().firstOrNull {
- it.isDeprecated()
- }
- }
-
-/**
- * @return true if [T] has [kotlin.Deprecated] or [java.lang.Deprecated]
- * annotation for **any** source set
- */
-public fun <T : Documentable> WithExtraProperties<T>.isDeprecated(): Boolean = deprecatedAnnotation != null
-
-/**
- * @return true for [kotlin.Deprecated] and [java.lang.Deprecated]
- */
-public fun Annotations.Annotation.isDeprecated(): Boolean {
- return (this.dri.packageName == "kotlin" && this.dri.classNames == "Deprecated") ||
- (this.dri.packageName == "java.lang" && this.dri.classNames == "Deprecated")
-}