diff options
author | Ignat Beresnev <ignat.beresnev@jetbrains.com> | 2023-08-31 20:16:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-31 20:16:01 +0200 |
commit | 02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33 (patch) | |
tree | 66f6d6f089a93b863bf1144666491eca6729ad05 /core/src/main/kotlin/model/properties | |
parent | 6a181a7a2b03ec263788d137610e86937a57d434 (diff) | |
download | dokka-02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33.tar.gz dokka-02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33.tar.bz2 dokka-02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33.zip |
Enable explicit API mode (#3139)
Diffstat (limited to 'core/src/main/kotlin/model/properties')
-rw-r--r-- | core/src/main/kotlin/model/properties/PropertyContainer.kt | 31 | ||||
-rw-r--r-- | core/src/main/kotlin/model/properties/properties.kt | 32 |
2 files changed, 37 insertions, 26 deletions
diff --git a/core/src/main/kotlin/model/properties/PropertyContainer.kt b/core/src/main/kotlin/model/properties/PropertyContainer.kt index 24577bd5..7f5bb2f0 100644 --- a/core/src/main/kotlin/model/properties/PropertyContainer.kt +++ b/core/src/main/kotlin/model/properties/PropertyContainer.kt @@ -4,43 +4,44 @@ package org.jetbrains.dokka.model.properties -data class PropertyContainer<C : Any> internal constructor( +public data class PropertyContainer<C : Any> internal constructor( @PublishedApi internal val map: Map<ExtraProperty.Key<C, *>, ExtraProperty<C>> ) { - operator fun <D : C> plus(prop: ExtraProperty<D>): PropertyContainer<D> = + public operator fun <D : C> plus(prop: ExtraProperty<D>): PropertyContainer<D> = PropertyContainer(map + (prop.key to prop)) // TODO: Add logic for caching calculated properties - inline operator fun <reified T : Any> get(key: ExtraProperty.Key<C, T>): T? = when (val prop = map[key]) { + 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.") } - inline fun <reified T : Any> allOfType(): List<T> = map.values.filterIsInstance<T>() - fun <D : C> addAll(extras: Collection<ExtraProperty<D>>): PropertyContainer<D> = + 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 }) - operator fun <D : C> minus(prop: ExtraProperty.Key<C, *>): PropertyContainer<D> = + public operator fun <D : C> minus(prop: ExtraProperty.Key<C, *>): PropertyContainer<D> = PropertyContainer(map.filterNot { it.key == prop }) - companion object { - fun <T : Any> empty(): PropertyContainer<T> = PropertyContainer(emptyMap()) - fun <T : Any> withAll(vararg extras: ExtraProperty<T>?) = empty<T>().addAll(extras.filterNotNull()) - fun <T : Any> withAll(extras: Collection<ExtraProperty<T>>) = empty<T>().addAll(extras) + 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) } } -operator fun <D: Any> PropertyContainer<D>.plus(prop: ExtraProperty<D>?): PropertyContainer<D> = +public operator fun <D: Any> PropertyContainer<D>.plus(prop: ExtraProperty<D>?): PropertyContainer<D> = if (prop == null) this else PropertyContainer(map + (prop.key to prop)) -interface WithExtraProperties<C : Any> { - val extra: PropertyContainer<C> +public interface WithExtraProperties<C : Any> { + public val extra: PropertyContainer<C> - fun withNewExtras(newExtras: PropertyContainer<C>): C + public fun withNewExtras(newExtras: PropertyContainer<C>): C } -fun <C> C.mergeExtras(left: C, right: C): C where C : Any, C : WithExtraProperties<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 } diff --git a/core/src/main/kotlin/model/properties/properties.kt b/core/src/main/kotlin/model/properties/properties.kt index e15a1668..ea76dc72 100644 --- a/core/src/main/kotlin/model/properties/properties.kt +++ b/core/src/main/kotlin/model/properties/properties.kt @@ -4,23 +4,33 @@ package org.jetbrains.dokka.model.properties -interface ExtraProperty<in C : Any> { - interface Key<in C : Any, T : Any> { - fun mergeStrategyFor(left: T, right: T): MergeStrategy<C> = MergeStrategy.Fail { +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") } } - val key: Key<C, *> + public val key: Key<C, *> } -interface CalculatedProperty<in C : Any, T : Any> : ExtraProperty.Key<C, T> { - fun calculate(subject: C): T +public interface CalculatedProperty<in C : Any, T : Any> : ExtraProperty.Key<C, T> { + public fun calculate(subject: C): T } -sealed class MergeStrategy<in C> { - class Replace<in C : Any>(val newProperty: ExtraProperty<C>) : MergeStrategy<C>() - object Remove : MergeStrategy<Any>() - class Full<C : Any>(val merger: (preMerged: C, left: C, right: C) -> C) : MergeStrategy<C>() - class Fail(val error: () -> Nothing) : MergeStrategy<Any>() +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>() } |