aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/model/properties
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 /core/src/main/kotlin/model/properties
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 'core/src/main/kotlin/model/properties')
-rw-r--r--core/src/main/kotlin/model/properties/PropertyContainer.kt69
-rw-r--r--core/src/main/kotlin/model/properties/properties.kt36
2 files changed, 0 insertions, 105 deletions
diff --git a/core/src/main/kotlin/model/properties/PropertyContainer.kt b/core/src/main/kotlin/model/properties/PropertyContainer.kt
deleted file mode 100644
index 7f5bb2f0..00000000
--- a/core/src/main/kotlin/model/properties/PropertyContainer.kt
+++ /dev/null
@@ -1,69 +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.model.properties
-
-public data class PropertyContainer<C : Any> internal constructor(
- @PublishedApi internal val map: Map<ExtraProperty.Key<C, *>, ExtraProperty<C>>
-) {
- public operator fun <D : C> plus(prop: ExtraProperty<D>): PropertyContainer<D> =
- PropertyContainer(map + (prop.key to prop))
-
- // TODO: Add logic for caching calculated properties
- public inline operator fun <reified T : Any> get(key: ExtraProperty.Key<C, T>): T? = when (val prop = map[key]) {
- is T? -> prop
- else -> throw ClassCastException("Property for $key stored under not matching key type.")
- }
-
- public inline fun <reified T : Any> allOfType(): List<T> = map.values.filterIsInstance<T>()
-
- public fun <D : C> addAll(extras: Collection<ExtraProperty<D>>): PropertyContainer<D> =
- PropertyContainer(map + extras.map { p -> p.key to p })
-
- public operator fun <D : C> minus(prop: ExtraProperty.Key<C, *>): PropertyContainer<D> =
- PropertyContainer(map.filterNot { it.key == prop })
-
- public companion object {
- public fun <T : Any> empty(): PropertyContainer<T> = PropertyContainer(emptyMap())
- public fun <T : Any> withAll(vararg extras: ExtraProperty<T>?): PropertyContainer<T> = empty<T>().addAll(extras.filterNotNull())
- public fun <T : Any> withAll(extras: Collection<ExtraProperty<T>>): PropertyContainer<T> = empty<T>().addAll(extras)
- }
-}
-
-public operator fun <D: Any> PropertyContainer<D>.plus(prop: ExtraProperty<D>?): PropertyContainer<D> =
- if (prop == null) this else PropertyContainer(map + (prop.key to prop))
-
-
-public interface WithExtraProperties<C : Any> {
- public val extra: PropertyContainer<C>
-
- public fun withNewExtras(newExtras: PropertyContainer<C>): C
-}
-
-public fun <C> C.mergeExtras(left: C, right: C): C where C : Any, C : WithExtraProperties<C> {
- val aggregatedExtras: List<List<ExtraProperty<C>>> =
- (left.extra.map.values + right.extra.map.values)
- .groupBy { it.key }
- .values
- .map { it.distinct() }
-
- val (unambiguous, toMerge) = aggregatedExtras.partition { it.size == 1 }
-
- @Suppress("UNCHECKED_CAST")
- val strategies: List<MergeStrategy<C>> = toMerge.map { (l, r) ->
- (l.key as ExtraProperty.Key<C, ExtraProperty<C>>).mergeStrategyFor(l, r)
- }
-
- strategies.filterIsInstance<MergeStrategy.Fail>().firstOrNull()?.error?.invoke()
-
- val replaces: List<ExtraProperty<C>> =
- strategies.filterIsInstance<MergeStrategy.Replace<C>>().map { it.newProperty }
-
- val needingFullMerge: List<(preMerged: C, left: C, right: C) -> C> =
- strategies.filterIsInstance<MergeStrategy.Full<C>>().map { it.merger }
-
- val newExtras = PropertyContainer((unambiguous.flatten() + replaces).associateBy { it.key })
-
- return needingFullMerge.fold(withNewExtras(newExtras)) { acc, merger -> merger(acc, left, right) }
-}
diff --git a/core/src/main/kotlin/model/properties/properties.kt b/core/src/main/kotlin/model/properties/properties.kt
deleted file mode 100644
index ea76dc72..00000000
--- a/core/src/main/kotlin/model/properties/properties.kt
+++ /dev/null
@@ -1,36 +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.model.properties
-
-public interface ExtraProperty<in C : Any> {
- public interface Key<in C : Any, T : Any> {
- public fun mergeStrategyFor(left: T, right: T): MergeStrategy<C> = MergeStrategy.Fail {
- throw NotImplementedError("Property merging for $this is not implemented")
- }
- }
-
- public val key: Key<C, *>
-}
-
-public interface CalculatedProperty<in C : Any, T : Any> : ExtraProperty.Key<C, T> {
- public fun calculate(subject: C): T
-}
-
-public sealed class MergeStrategy<in C> {
-
- public class Replace<in C : Any>(
- public val newProperty: ExtraProperty<C>
- ) : MergeStrategy<C>()
-
- public object Remove : MergeStrategy<Any>()
-
- public class Full<C : Any>(
- public val merger: (preMerged: C, left: C, right: C) -> C
- ) : MergeStrategy<C>()
-
- public class Fail(
- public val error: () -> Nothing
- ) : MergeStrategy<Any>()
-}