aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/kotlin/model/ContentSourceSet.kt12
-rw-r--r--core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt18
-rw-r--r--core/src/test/kotlin/model/ContentSourceSetTest.kt6
-rw-r--r--core/src/test/kotlin/utilities/SelfRepresentingSingletonSetTest.kt60
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt6
-rw-r--r--plugins/gfm/src/main/kotlin/GfmPlugin.kt8
6 files changed, 90 insertions, 20 deletions
diff --git a/core/src/main/kotlin/model/ContentSourceSet.kt b/core/src/main/kotlin/model/ContentSourceSet.kt
index 6eee4c94..8a1bf53c 100644
--- a/core/src/main/kotlin/model/ContentSourceSet.kt
+++ b/core/src/main/kotlin/model/ContentSourceSet.kt
@@ -3,28 +3,20 @@ package org.jetbrains.dokka.model
import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet
import org.jetbrains.dokka.DokkaSourceSetID
import org.jetbrains.dokka.Platform
+import org.jetbrains.dokka.utilities.SelfRepresentingSingletonSet
data class ContentSourceSet(
val sourceSetIDs: CompositeSourceSetID,
val displayName: String,
val analysisPlatform: Platform
-) {
+) : SelfRepresentingSingletonSet<ContentSourceSet> {
constructor(sourceSet: DokkaSourceSet) : this(
sourceSetIDs = CompositeSourceSetID(sourceSet.sourceSetID),
displayName = sourceSet.displayName,
analysisPlatform = sourceSet.analysisPlatform
)
-
- operator fun contains(sourceSetID: DokkaSourceSetID): Boolean {
- return sourceSetID in sourceSetIDs
- }
-
- operator fun contains(sourceSet: DokkaSourceSet): Boolean {
- return sourceSet.sourceSetID in this
- }
}
-
fun DokkaSourceSet.toContentSourceSet(): ContentSourceSet = ContentSourceSet(this)
fun Iterable<DokkaSourceSet>.toContentSourceSets(): Set<ContentSourceSet> = map { it.toContentSourceSet() }.toSet()
diff --git a/core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt b/core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt
new file mode 100644
index 00000000..d384bda4
--- /dev/null
+++ b/core/src/main/kotlin/utilities/SelfRepresentingSingletonSet.kt
@@ -0,0 +1,18 @@
+package org.jetbrains.dokka.utilities
+
+interface SelfRepresentingSingletonSet<T : SelfRepresentingSingletonSet<T>> : Set<T> {
+ override val size: Int get() = 1
+
+ override fun contains(element: T): Boolean = this == element
+
+ override fun containsAll(elements: Collection<T>): Boolean =
+ if (elements.isEmpty()) true
+ else elements.all { this == it }
+
+ override fun isEmpty(): Boolean = false
+
+ override fun iterator(): Iterator<T> = iterator {
+ @Suppress("UNCHECKED_CAST")
+ yield(this@SelfRepresentingSingletonSet as T)
+ }
+}
diff --git a/core/src/test/kotlin/model/ContentSourceSetTest.kt b/core/src/test/kotlin/model/ContentSourceSetTest.kt
index b96180a2..74f7854b 100644
--- a/core/src/test/kotlin/model/ContentSourceSetTest.kt
+++ b/core/src/test/kotlin/model/ContentSourceSetTest.kt
@@ -19,17 +19,17 @@ class ContentSourceSetTest {
)
assertFalse(
- DokkaSourceSetID("m3", "s3") in contentSourceSet,
+ DokkaSourceSetID("m3", "s3") in contentSourceSet.sourceSetIDs,
"Expected source set id not being contained in content source set"
)
assertTrue(
- DokkaSourceSetID("m1", "s1") in contentSourceSet,
+ DokkaSourceSetID("m1", "s1") in contentSourceSet.sourceSetIDs,
"Expected source set id being contained in content source set"
)
assertTrue(
- DokkaSourceSetID("m1+m2", "s1+s2") in contentSourceSet,
+ DokkaSourceSetID("m1+m2", "s1+s2") in contentSourceSet.sourceSetIDs,
"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
new file mode 100644
index 00000000..bef43565
--- /dev/null
+++ b/core/src/test/kotlin/utilities/SelfRepresentingSingletonSetTest.kt
@@ -0,0 +1,60 @@
+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()
+ )
+ }
+}
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
index d776e602..529caa93 100644
--- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -220,7 +220,7 @@ open class HtmlRenderer(
return nodes.toList().map { (sourceSet, elements) ->
sourceSet to createHTML(prettyPrint = false).div {
elements.forEach {
- buildContentNode(it, pageContext, setOf(sourceSet))
+ buildContentNode(it, pageContext, sourceSet.toSet())
}
}.stripDiv()
}.groupBy(
@@ -248,13 +248,13 @@ open class HtmlRenderer(
node.groupDivergentInstances(pageContext, { instance, contentPage, sourceSet ->
createHTML(prettyPrint = false).div {
instance.before?.let { before ->
- buildContentNode(before, pageContext, setOf(sourceSet))
+ buildContentNode(before, pageContext, sourceSet)
}
}.stripDiv()
}, { instance, contentPage, sourceSet ->
createHTML(prettyPrint = false).div {
instance.after?.let { after ->
- buildContentNode(after, pageContext, setOf(sourceSet))
+ buildContentNode(after, pageContext, sourceSet)
}
}.stripDiv()
})
diff --git a/plugins/gfm/src/main/kotlin/GfmPlugin.kt b/plugins/gfm/src/main/kotlin/GfmPlugin.kt
index d93b4e98..8ae4a78a 100644
--- a/plugins/gfm/src/main/kotlin/GfmPlugin.kt
+++ b/plugins/gfm/src/main/kotlin/GfmPlugin.kt
@@ -246,11 +246,11 @@ open class CommonmarkRenderer(
val distinct =
node.groupDivergentInstances(pageContext, { instance, contentPage, sourceSet ->
instance.before?.let { before ->
- buildString { buildContentNode(before, pageContext, setOf(sourceSet)) }
+ buildString { buildContentNode(before, pageContext, sourceSet) }
} ?: ""
}, { instance, contentPage, sourceSet ->
instance.after?.let { after ->
- buildString { buildContentNode(after, pageContext, setOf(sourceSet)) }
+ buildString { buildContentNode(after, pageContext, sourceSet) }
} ?: ""
})
@@ -265,7 +265,7 @@ open class CommonmarkRenderer(
buildContentNode(
it,
pageContext,
- setOf(sourceSets.first())
+ sourceSets.first()
) // It's workaround to render content only once
buildNewLine()
}
@@ -293,7 +293,7 @@ open class CommonmarkRenderer(
buildContentNode(
it,
pageContext,
- setOf(sourceSets.first())
+ sourceSets.first()
) // It's workaround to render content only once
buildNewLine()
}