diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/api/core.api | 24 | ||||
-rw-r--r-- | core/src/main/kotlin/model/CompositeSourceSetID.kt | 32 | ||||
-rw-r--r-- | core/src/main/kotlin/model/DisplaySourceSet.kt | 55 | ||||
-rw-r--r-- | core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt | 2 | ||||
-rw-r--r-- | core/src/test/kotlin/model/CompositeSourceSetIDTest.kt | 6 | ||||
-rw-r--r-- | core/src/test/kotlin/model/DisplaySourceSetTest.kt | 10 | ||||
-rw-r--r-- | core/src/test/kotlin/utilities/SelfRepresentingSingletonSetTest.kt | 60 |
7 files changed, 69 insertions, 120 deletions
diff --git a/core/api/core.api b/core/api/core.api index 9530899d..6da499ee 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -863,10 +863,6 @@ public final class org/jetbrains/dokka/model/CompositeSourceSetID { public fun toString ()Ljava/lang/String; } -public final class org/jetbrains/dokka/model/CompositeSourceSetIDKt { - public static final fun plus (Lorg/jetbrains/dokka/DokkaSourceSetID;Lorg/jetbrains/dokka/DokkaSourceSetID;)Lorg/jetbrains/dokka/model/CompositeSourceSetID; -} - public final class org/jetbrains/dokka/model/Contravariance : org/jetbrains/dokka/model/Variance { public fun <init> (Lorg/jetbrains/dokka/model/Bound;)V public final fun component1 ()Lorg/jetbrains/dokka/model/Bound; @@ -1400,40 +1396,24 @@ public final class org/jetbrains/dokka/model/DefinitelyNonNullable : org/jetbrai public fun toString ()Ljava/lang/String; } -public final class org/jetbrains/dokka/model/DisplaySourceSet : org/jetbrains/dokka/utilities/SelfRepresentingSingletonSet { +public final class org/jetbrains/dokka/model/DisplaySourceSet { public fun <init> (Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;)V public fun <init> (Lorg/jetbrains/dokka/model/CompositeSourceSetID;Ljava/lang/String;Lorg/jetbrains/dokka/Platform;)V - public synthetic fun add (Ljava/lang/Object;)Z - public fun add (Lorg/jetbrains/dokka/model/DisplaySourceSet;)Z - public fun addAll (Ljava/util/Collection;)Z - public fun clear ()V public final fun component1 ()Lorg/jetbrains/dokka/model/CompositeSourceSetID; public final fun component2 ()Ljava/lang/String; public final fun component3 ()Lorg/jetbrains/dokka/Platform; - public final fun contains (Ljava/lang/Object;)Z - public fun contains (Lorg/jetbrains/dokka/model/DisplaySourceSet;)Z - public synthetic fun contains (Lorg/jetbrains/dokka/utilities/SelfRepresentingSingletonSet;)Z - public fun containsAll (Ljava/util/Collection;)Z public final fun copy (Lorg/jetbrains/dokka/model/CompositeSourceSetID;Ljava/lang/String;Lorg/jetbrains/dokka/Platform;)Lorg/jetbrains/dokka/model/DisplaySourceSet; public static synthetic fun copy$default (Lorg/jetbrains/dokka/model/DisplaySourceSet;Lorg/jetbrains/dokka/model/CompositeSourceSetID;Ljava/lang/String;Lorg/jetbrains/dokka/Platform;ILjava/lang/Object;)Lorg/jetbrains/dokka/model/DisplaySourceSet; public fun equals (Ljava/lang/Object;)Z public final fun getName ()Ljava/lang/String; public final fun getPlatform ()Lorg/jetbrains/dokka/Platform; - public fun getSize ()I public final fun getSourceSetIDs ()Lorg/jetbrains/dokka/model/CompositeSourceSetID; public fun hashCode ()I - public fun isEmpty ()Z - public fun iterator ()Ljava/util/Iterator; - public fun remove (Ljava/lang/Object;)Z - public fun removeAll (Ljava/util/Collection;)Z - public fun retainAll (Ljava/util/Collection;)Z - public final fun size ()I - public fun toArray ()[Ljava/lang/Object; - public fun toArray ([Ljava/lang/Object;)[Ljava/lang/Object; public fun toString ()Ljava/lang/String; } public final class org/jetbrains/dokka/model/DisplaySourceSetKt { + public static final fun computeSourceSetIds (Ljava/lang/Iterable;)Ljava/util/Set; public static final fun getSourceSetIDs (Ljava/lang/Iterable;)Ljava/util/List; public static final fun toDisplaySourceSet (Lorg/jetbrains/dokka/DokkaConfiguration$DokkaSourceSet;)Lorg/jetbrains/dokka/model/DisplaySourceSet; public static final fun toDisplaySourceSets (Ljava/lang/Iterable;)Ljava/util/Set; diff --git a/core/src/main/kotlin/model/CompositeSourceSetID.kt b/core/src/main/kotlin/model/CompositeSourceSetID.kt index 3eaf6407..5b6ecb2a 100644 --- a/core/src/main/kotlin/model/CompositeSourceSetID.kt +++ b/core/src/main/kotlin/model/CompositeSourceSetID.kt @@ -3,26 +3,30 @@ package org.jetbrains.dokka.model import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.DokkaSourceSetID -data class CompositeSourceSetID( +/** + * A unique composite key of multiple [DokkaSourceSetID] that identifies [DisplaySourceSet]. + * Consists of multiple (non-zero) [DokkaSourceSetID] that the corresponding [DisplaySourceSet] was built from. + * + * Should not be constructed or copied outside of [DisplaySourceSet] instantiation. + */ +public data class CompositeSourceSetID( private val children: Set<DokkaSourceSetID> ) { - constructor(sourceSetIDs: Iterable<DokkaSourceSetID>) : this(sourceSetIDs.toSet()) - constructor(sourceSetId: DokkaSourceSetID) : this(setOf(sourceSetId)) + public constructor(sourceSetIDs: Iterable<DokkaSourceSetID>) : this(sourceSetIDs.toSet()) + public constructor(sourceSetId: DokkaSourceSetID) : this(setOf(sourceSetId)) init { require(children.isNotEmpty()) { "Expected at least one source set id" } } - val merged: DokkaSourceSetID - get() = children.sortedBy { it.scopeId + it.sourceSetName }.let { sortedChildren -> - DokkaSourceSetID( - scopeId = sortedChildren.joinToString(separator = "+") { it.scopeId }, - sourceSetName = sortedChildren.joinToString(separator = "+") { it.sourceSetName } - ) - } + public val merged: DokkaSourceSetID = children.sortedBy { it.scopeId + it.sourceSetName }.let { sortedChildren -> + DokkaSourceSetID( + scopeId = sortedChildren.joinToString(separator = "+") { it.scopeId }, + sourceSetName = sortedChildren.joinToString(separator = "+") { it.sourceSetName } + ) + } - val all: Set<DokkaSourceSetID> - get() = setOf(merged, *children.toTypedArray()) + public val all: Set<DokkaSourceSetID> = setOf(merged, *children.toTypedArray()) operator fun contains(sourceSetId: DokkaSourceSetID): Boolean { return sourceSetId in all @@ -36,7 +40,3 @@ data class CompositeSourceSetID( return copy(children = children + other) } } - -operator fun DokkaSourceSetID.plus(other: DokkaSourceSetID): CompositeSourceSetID { - return CompositeSourceSetID(listOf(this, other)) -} diff --git a/core/src/main/kotlin/model/DisplaySourceSet.kt b/core/src/main/kotlin/model/DisplaySourceSet.kt index 5ea1ba3d..e2818a70 100644 --- a/core/src/main/kotlin/model/DisplaySourceSet.kt +++ b/core/src/main/kotlin/model/DisplaySourceSet.kt @@ -1,32 +1,57 @@ package org.jetbrains.dokka.model +import org.jetbrains.dokka.* import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet -import org.jetbrains.dokka.DokkaSourceSetID -import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.utilities.SelfRepresentingSingletonSet /** - * TODO: fix the example (asymmetric equivalence relation with [Set]): - * ``` - * val ds = DokkaSourceSetImpl(sourceSetID = DokkaSourceSetID("", "")).toDisplaySourceSet() - * println(setOf(ds) == ds) // true - * println(ds == setOf(ds)) // false - * ``` + * Represents a final user-visible source set in the documentable model that is + * used to specify under which source sets/targets current signatures are available, + * can be used to filter in and out all available signatures under the specified source set, + * and, depending on the format, are rendered as "platform" selectors. + * + * E.g. HTML format renders display source sets as "bubbles" that later are used for filtering + * and informational purposes. + * + * [DisplaySourceSet]s typically have a one-to-one correspondence to the build system source sets, + * are created by the base plugin from [DokkaSourceSet] and never tweaked manually. + * [DisplaySourceSet] is uniquely identified by the corresponding [CompositeSourceSetID]. + * + * @property sourceSetIDs unique stable id of the display source set. + * It is composite by definition, as it uniquely defines the source set and all nested source sets. + * Apart from names, it also contains a substitute to a full source set path in order to differentiate + * source sets with the same name in a stable manner. + * @property name corresponds to the name of the original [DokkaSourceSet] + * @property platform the platform of the source set. If the source set is a mix of multiple source sets + * that correspond to multiple KMP platforms, then it is [Platform.common] */ -data class DisplaySourceSet( +public data class DisplaySourceSet( val sourceSetIDs: CompositeSourceSetID, val name: String, val platform: Platform -) : SelfRepresentingSingletonSet<DisplaySourceSet> { - constructor(sourceSet: DokkaSourceSet) : this( +) { + public constructor(sourceSet: DokkaSourceSet) : this( sourceSetIDs = CompositeSourceSetID(sourceSet.sourceSetID), name = sourceSet.displayName, platform = sourceSet.analysisPlatform ) } -fun DokkaSourceSet.toDisplaySourceSet(): DisplaySourceSet = DisplaySourceSet(this) +/** + * Transforms the current [DokkaSourceSet] into [DisplaySourceSet], + * matching the corresponding subset of its properties to [DisplaySourceSet] properties. + */ +public fun DokkaSourceSet.toDisplaySourceSet(): DisplaySourceSet = DisplaySourceSet(this) + +/** + * Transforms all the given [DokkaSourceSet]s into [DisplaySourceSet]s. + */ +public fun Iterable<DokkaSourceSet>.toDisplaySourceSets(): Set<DisplaySourceSet> = + map { it.toDisplaySourceSet() }.toSet() -fun Iterable<DokkaSourceSet>.toDisplaySourceSets(): Set<DisplaySourceSet> = map { it.toDisplaySourceSet() }.toSet() +@InternalDokkaApi +@Deprecated("Use computeSourceSetIds() and cache its results instead", replaceWith = ReplaceWith("computeSourceSetIds()")) +public val Iterable<DisplaySourceSet>.sourceSetIDs: List<DokkaSourceSetID> get() = this.flatMap { it.sourceSetIDs.all } -val Iterable<DisplaySourceSet>.sourceSetIDs: List<DokkaSourceSetID> get() = this.flatMap { it.sourceSetIDs.all } +@InternalDokkaApi +public fun Iterable<DisplaySourceSet>.computeSourceSetIds(): Set<DokkaSourceSetID> = + fold(hashSetOf()) { acc, set -> acc.addAll(set.sourceSetIDs.all); acc } diff --git a/core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt b/core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt index e1b42388..95cc9eb9 100644 --- a/core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt +++ b/core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt @@ -3,6 +3,8 @@ package org.jetbrains.dokka.utilities import org.jetbrains.dokka.InternalDokkaApi @InternalDokkaApi +@Suppress("DEPRECATION_ERROR") +@Deprecated(message = "SelfRepresentingSingletonSet is an incorrect set implementation that breaks set invariants", level = DeprecationLevel.ERROR) interface SelfRepresentingSingletonSet<T : SelfRepresentingSingletonSet<T>> : Set<T> { override val size: Int get() = 1 diff --git a/core/src/test/kotlin/model/CompositeSourceSetIDTest.kt b/core/src/test/kotlin/model/CompositeSourceSetIDTest.kt index 472581e7..aa5a801d 100644 --- a/core/src/test/kotlin/model/CompositeSourceSetIDTest.kt +++ b/core/src/test/kotlin/model/CompositeSourceSetIDTest.kt @@ -2,7 +2,6 @@ package model import org.jetbrains.dokka.DokkaSourceSetID import org.jetbrains.dokka.model.CompositeSourceSetID -import org.jetbrains.dokka.model.plus import kotlin.test.* class CompositeSourceSetIDTest { @@ -65,4 +64,9 @@ class CompositeSourceSetIDTest { "Expected all three source sets being merged in order" ) } + + operator fun DokkaSourceSetID.plus(other: DokkaSourceSetID): CompositeSourceSetID { + return CompositeSourceSetID(listOf(this, other)) + } + } diff --git a/core/src/test/kotlin/model/DisplaySourceSetTest.kt b/core/src/test/kotlin/model/DisplaySourceSetTest.kt index adabdbdb..04ad07d6 100644 --- a/core/src/test/kotlin/model/DisplaySourceSetTest.kt +++ b/core/src/test/kotlin/model/DisplaySourceSetTest.kt @@ -2,9 +2,7 @@ package model import org.jetbrains.dokka.DokkaSourceSetID import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.model.CompositeSourceSetID -import org.jetbrains.dokka.model.DisplaySourceSet -import org.jetbrains.dokka.model.sourceSetIDs +import org.jetbrains.dokka.model.* import kotlin.test.Test import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -44,17 +42,17 @@ class DisplaySourceSetTest { ) assertFalse( - DokkaSourceSetID("m3", "s3") in listOf(contentSourceSet).sourceSetIDs, + DokkaSourceSetID("m3", "s3") in listOf(contentSourceSet).computeSourceSetIds(), "Expected source set id not being contained in content source set" ) assertTrue( - DokkaSourceSetID("m1", "s1") in listOf(contentSourceSet).sourceSetIDs, + DokkaSourceSetID("m1", "s1") in listOf(contentSourceSet).computeSourceSetIds(), "Expected source set id being contained in content source set" ) assertTrue( - DokkaSourceSetID("m1+m2", "s1+s2") in listOf(contentSourceSet).sourceSetIDs, + DokkaSourceSetID("m1+m2", "s1+s2") in listOf(contentSourceSet).computeSourceSetIds(), "Expected merged source set being contained in content source set" ) } diff --git a/core/src/test/kotlin/utilities/SelfRepresentingSingletonSetTest.kt b/core/src/test/kotlin/utilities/SelfRepresentingSingletonSetTest.kt deleted file mode 100644 index bef43565..00000000 --- a/core/src/test/kotlin/utilities/SelfRepresentingSingletonSetTest.kt +++ /dev/null @@ -1,60 +0,0 @@ -package utilities - -import org.jetbrains.dokka.utilities.SelfRepresentingSingletonSet -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertFalse -import kotlin.test.assertTrue - -class SelfRepresentingSingletonSetTest { - - data class TestModel(val index: Int = 0) : SelfRepresentingSingletonSet<TestModel> - - @Test - fun size() { - assertEquals(1, TestModel().size) - } - - @Test - fun contains() { - val m0 = TestModel(0) - val m1 = TestModel(1) - - assertFalse(m1 in m0) - assertFalse(m0 in m1) - assertTrue(m0 in m0) - assertTrue(m1 in m1) - assertTrue(TestModel(0) in m0) - } - - @Test - fun `containsAll is compliant to setOf`() { - val setOf = setOf(TestModel()) - val testModel = TestModel() - - assertEquals( - setOf.containsAll(emptyList()), testModel.containsAll(emptyList()) - ) - - assertEquals( - setOf.containsAll(listOf(TestModel())), testModel.containsAll(listOf(TestModel())) - ) - - assertEquals( - setOf.containsAll(listOf(TestModel(0), TestModel(1))), - testModel.containsAll(listOf(TestModel(0), TestModel(1))) - ) - } - - @Test - fun isEmpty() { - assertFalse(TestModel().isEmpty()) - } - - @Test - fun iterator() { - assertEquals( - listOf(TestModel()), TestModel(0).iterator().asSequence().toList() - ) - } -} |