aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/main/kotlin/model/defaultValues.kt18
-rw-r--r--core/src/main/kotlin/model/properties/PropertyContainer.kt5
-rw-r--r--core/src/main/kotlin/transformers/pages/PageTransformerBuilders.kt6
-rw-r--r--core/src/test/kotlin/transformerBuilders/PageTransformerBuilderTest.kt149
4 files changed, 24 insertions, 154 deletions
diff --git a/core/src/main/kotlin/model/defaultValues.kt b/core/src/main/kotlin/model/defaultValues.kt
new file mode 100644
index 00000000..63b69cbb
--- /dev/null
+++ b/core/src/main/kotlin/model/defaultValues.kt
@@ -0,0 +1,18 @@
+package org.jetbrains.dokka.model
+
+import org.jetbrains.dokka.model.properties.ExtraProperty
+import org.jetbrains.dokka.model.properties.MergeStrategy
+import java.lang.IllegalStateException
+
+class DefaultValue(val value: String): ExtraProperty<DParameter> {
+ companion object : ExtraProperty.Key<DParameter, DefaultValue> {
+ override fun mergeStrategyFor(left: DefaultValue, right: DefaultValue): MergeStrategy<DParameter> = if (left.value == right.value)
+ MergeStrategy.Replace(left)
+ else
+ MergeStrategy.Fail {throw IllegalStateException("Default values need to be the same")}
+
+ }
+
+ override val key: ExtraProperty.Key<DParameter, *>
+ get() = Companion
+} \ No newline at end of file
diff --git a/core/src/main/kotlin/model/properties/PropertyContainer.kt b/core/src/main/kotlin/model/properties/PropertyContainer.kt
index 5ea42e42..107bede5 100644
--- a/core/src/main/kotlin/model/properties/PropertyContainer.kt
+++ b/core/src/main/kotlin/model/properties/PropertyContainer.kt
@@ -15,12 +15,13 @@ class PropertyContainer<C : Any> internal constructor(
}
inline fun <reified T : Any> allOfType(): List<T> = map.values.filterIsInstance<T>()
- fun <D : C> addAll(vararg extras: ExtraProperty<D>): PropertyContainer<D> =
+ fun <D : C> addAll(extras: Collection<ExtraProperty<D>>): PropertyContainer<D> =
PropertyContainer(map + extras.map { p -> p.key to p })
companion object {
fun <T : Any> empty(): PropertyContainer<T> = PropertyContainer(emptyMap())
- fun <T : Any> withAll(vararg extras: ExtraProperty<T>) = empty<T>().addAll(*extras)
+ fun <T : Any> withAll(vararg extras: ExtraProperty<T>) = empty<T>().addAll(extras.toList())
+ fun <T : Any> withAll(extras: Collection<ExtraProperty<T>>) = empty<T>().addAll(extras)
}
}
diff --git a/core/src/main/kotlin/transformers/pages/PageTransformerBuilders.kt b/core/src/main/kotlin/transformers/pages/PageTransformerBuilders.kt
index 89b22c19..291b72ef 100644
--- a/core/src/main/kotlin/transformers/pages/PageTransformerBuilders.kt
+++ b/core/src/main/kotlin/transformers/pages/PageTransformerBuilders.kt
@@ -3,15 +3,15 @@ package org.jetbrains.dokka.transformers.pages
import org.jetbrains.dokka.pages.PageNode
import org.jetbrains.dokka.pages.RootPageNode
-fun pageScanner(block: PageNode.() -> Unit) = object : PageNodeTransformer {
+fun pageScanner(block: PageNode.() -> Unit) = object : PageTransformer {
override fun invoke(input: RootPageNode): RootPageNode = input.invokeOnAll(block) as RootPageNode
}
-fun pageMapper(block: PageNode.() -> PageNode) = object : PageNodeTransformer {
+fun pageMapper(block: PageNode.() -> PageNode) = object : PageTransformer {
override fun invoke(input: RootPageNode): RootPageNode = input.alterChildren(block) as RootPageNode
}
-fun pageStructureTransformer(block: RootPageNode.() -> RootPageNode) = object : PageNodeTransformer {
+fun pageStructureTransformer(block: RootPageNode.() -> RootPageNode) = object : PageTransformer {
override fun invoke(input: RootPageNode): RootPageNode = block(input)
}
diff --git a/core/src/test/kotlin/transformerBuilders/PageTransformerBuilderTest.kt b/core/src/test/kotlin/transformerBuilders/PageTransformerBuilderTest.kt
deleted file mode 100644
index 13ea5580..00000000
--- a/core/src/test/kotlin/transformerBuilders/PageTransformerBuilderTest.kt
+++ /dev/null
@@ -1,149 +0,0 @@
-package transformerBuilders;
-
-import org.jetbrains.dokka.CoreExtensions
-import org.jetbrains.dokka.pages.*
-import org.jetbrains.dokka.plugability.DokkaPlugin
-import org.jetbrains.dokka.transformers.pages.PageNodeTransformer
-import org.jetbrains.dokka.transformers.pages.pageMapper
-import org.jetbrains.dokka.transformers.pages.pageScanner
-import org.jetbrains.dokka.transformers.pages.pageStructureTransformer
-import org.jetbrains.dokka.utilities.DokkaConsoleLogger
-import org.junit.Test
-import testApi.testRunner.AbstractCoreTest
-
-class PageTransformerBuilderTest : AbstractCoreTest() {
-
- class ProxyPlugin(transformer: PageNodeTransformer) : DokkaPlugin() {
- val pageTransformer by extending { CoreExtensions.pageTransformer with transformer }
- }
-
- @Test
- fun scannerTest() {
- val configuration = dokkaConfiguration {
- passes {
- pass {
- sourceRoots = listOf("src/main/kotlin/transformerBuilder/Test.kt")
- }
- }
- }
- val list = mutableListOf<String>()
-
- var orig: PageNode? = null
-
- testInline(
- """
- |/src/main/kotlin/transformerBuilder/Test.kt
- |package transformerBuilder
- |
- |object Test {
- | fun test2(str: String): Unit {println(str)}
- |}
- """.trimMargin(),
- configuration,
- pluginOverrides = listOf(ProxyPlugin(pageScanner {
- list += name
- }))
- ) {
- pagesGenerationStage = {
- orig = it
- }
- pagesTransformationStage = { root ->
- list.assertCount(8, "Page list: ")
- orig?.let { root.assertTransform(it) }
- }
- }
- }
-
- @Test
- fun mapperTest() {
- val configuration = dokkaConfiguration {
- passes {
- pass {
- sourceRoots = listOf("src/main/kotlin/transformerBuilder/Test.kt")
- }
- }
- }
-
- var orig: PageNode? = null
-
- testInline(
- """
- |/src/main/kotlin/transformerBuilder/Test.kt
- |package transformerBuilder
- |
- |object Test {
- | fun test2(str: String): Unit {println(str)}
- |}
- """.trimMargin(),
- configuration,
- pluginOverrides = listOf(ProxyPlugin(pageMapper {
- modified(name = name + "2")
- }))
- ) {
- pagesGenerationStage = {
- orig = it
- }
- pagesTransformationStage = {
- it.let { root ->
- root.name.assertEqual("root2", "Root name: ")
- orig?.let {
- root.assertTransform(it) { node -> node.modified(name = node.name + "2") }
- }
- }
- }
- }
- }
-
- @Test
- fun structureTransformerTest() {
- val configuration = dokkaConfiguration {
- passes {
- pass {
- sourceRoots = listOf("src/main/kotlin/transformerBuilder/Test.kt")
- }
- }
- }
-
- testInline(
- """
- |/src/main/kotlin/transformerBuilder/Test.kt
- |package transformerBuilder
- |
- |object Test {
- | fun test2(str: String): Unit {println(str)}
- |}
- """.trimMargin(),
- configuration,
- pluginOverrides = listOf(ProxyPlugin(pageStructureTransformer {
- val ch = children.first()
- modified(
- children = listOf(
- ch,
- RendererSpecificResourcePage("test", emptyList(), RenderingStrategy.DoNothing)
- )
- )
- }))
- ) {
- pagesTransformationStage = { root ->
- root.children.assertCount(2, "Root children: ")
- root.children.first().name.assertEqual("transformerBuilder")
- root.children[1].name.assertEqual("test")
- }
- }
- }
-
- private fun <T> Collection<T>.assertCount(n: Int, prefix: String = "") =
- assert(count() == n) { "${prefix}Expected $n, got ${count()}" }
-
- private fun <T> T.assertEqual(expected: T, prefix: String = "") = assert(this == expected) {
- "${prefix}Expected $expected, got $this"
- }
-
- private fun PageNode.assertTransform(expected: PageNode, block: (PageNode) -> PageNode = { it }): Unit = this.let {
- it.name.assertEqual(block(expected).name)
- it.children.zip(expected.children).forEach { (g, e) ->
- g.name.assertEqual(block(e).name)
- g.assertTransform(e, block)
- }
- }
-}