From 02f30b142aa467d3a24cc52a1fe3f2fed7ea1e33 Mon Sep 17 00:00:00 2001 From: Ignat Beresnev Date: Thu, 31 Aug 2023 20:16:01 +0200 Subject: Enable explicit API mode (#3139) --- .../kotlin/model/properties/PropertyContainer.kt | 31 +++++++++++---------- .../src/main/kotlin/model/properties/properties.kt | 32 ++++++++++++++-------- 2 files changed, 37 insertions(+), 26 deletions(-) (limited to 'core/src/main/kotlin/model/properties') 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 internal constructor( +public data class PropertyContainer internal constructor( @PublishedApi internal val map: Map, ExtraProperty> ) { - operator fun plus(prop: ExtraProperty): PropertyContainer = + public operator fun plus(prop: ExtraProperty): PropertyContainer = PropertyContainer(map + (prop.key to prop)) // TODO: Add logic for caching calculated properties - inline operator fun get(key: ExtraProperty.Key): T? = when (val prop = map[key]) { + public inline operator fun get(key: ExtraProperty.Key): T? = when (val prop = map[key]) { is T? -> prop else -> throw ClassCastException("Property for $key stored under not matching key type.") } - inline fun allOfType(): List = map.values.filterIsInstance() - fun addAll(extras: Collection>): PropertyContainer = + public inline fun allOfType(): List = map.values.filterIsInstance() + + public fun addAll(extras: Collection>): PropertyContainer = PropertyContainer(map + extras.map { p -> p.key to p }) - operator fun minus(prop: ExtraProperty.Key): PropertyContainer = + public operator fun minus(prop: ExtraProperty.Key): PropertyContainer = PropertyContainer(map.filterNot { it.key == prop }) - companion object { - fun empty(): PropertyContainer = PropertyContainer(emptyMap()) - fun withAll(vararg extras: ExtraProperty?) = empty().addAll(extras.filterNotNull()) - fun withAll(extras: Collection>) = empty().addAll(extras) + public companion object { + public fun empty(): PropertyContainer = PropertyContainer(emptyMap()) + public fun withAll(vararg extras: ExtraProperty?): PropertyContainer = empty().addAll(extras.filterNotNull()) + public fun withAll(extras: Collection>): PropertyContainer = empty().addAll(extras) } } -operator fun PropertyContainer.plus(prop: ExtraProperty?): PropertyContainer = +public operator fun PropertyContainer.plus(prop: ExtraProperty?): PropertyContainer = if (prop == null) this else PropertyContainer(map + (prop.key to prop)) -interface WithExtraProperties { - val extra: PropertyContainer +public interface WithExtraProperties { + public val extra: PropertyContainer - fun withNewExtras(newExtras: PropertyContainer): C + public fun withNewExtras(newExtras: PropertyContainer): C } -fun C.mergeExtras(left: C, right: C): C where C : Any, C : WithExtraProperties { +public fun C.mergeExtras(left: C, right: C): C where C : Any, C : WithExtraProperties { val aggregatedExtras: List>> = (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 { - interface Key { - fun mergeStrategyFor(left: T, right: T): MergeStrategy = MergeStrategy.Fail { +public interface ExtraProperty { + public interface Key { + public fun mergeStrategyFor(left: T, right: T): MergeStrategy = MergeStrategy.Fail { throw NotImplementedError("Property merging for $this is not implemented") } } - val key: Key + public val key: Key } -interface CalculatedProperty : ExtraProperty.Key { - fun calculate(subject: C): T +public interface CalculatedProperty : ExtraProperty.Key { + public fun calculate(subject: C): T } -sealed class MergeStrategy { - class Replace(val newProperty: ExtraProperty) : MergeStrategy() - object Remove : MergeStrategy() - class Full(val merger: (preMerged: C, left: C, right: C) -> C) : MergeStrategy() - class Fail(val error: () -> Nothing) : MergeStrategy() +public sealed class MergeStrategy { + + public class Replace( + public val newProperty: ExtraProperty + ) : MergeStrategy() + + public object Remove : MergeStrategy() + + public class Full( + public val merger: (preMerged: C, left: C, right: C) -> C + ) : MergeStrategy() + + public class Fail( + public val error: () -> Nothing + ) : MergeStrategy() } -- cgit