diff options
| author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2023-11-10 11:46:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-10 11:46:54 +0100 |
| commit | 8e5c63d035ef44a269b8c43430f43f5c8eebfb63 (patch) | |
| tree | 1b915207b2b9f61951ddbf0ff2e687efd053d555 /plugins/base/src/main/kotlin/transformers/documentables | |
| parent | a44efd4ba0c2e4ab921ff75e0f53fc9335aa79db (diff) | |
| download | dokka-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')
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: DokkaSourceS |
