aboutsummaryrefslogtreecommitdiff
path: root/core/src/main
diff options
context:
space:
mode:
authorSzymon Świstun <sswistun@virtuslab.com>2020-03-16 13:08:29 +0100
committerKamil Doległo <kamilok1965@users.noreply.github.com>2020-03-18 14:40:29 +0100
commit3de1182033ca5a5db374e16a6ab3555627faa79b (patch)
tree192580f4a08340466fd293a7199f110e34fe1dbf /core/src/main
parent03329b0eb98b309d208839344052633028e00984 (diff)
downloaddokka-3de1182033ca5a5db374e16a6ab3555627faa79b.tar.gz
dokka-3de1182033ca5a5db374e16a6ab3555627faa79b.tar.bz2
dokka-3de1182033ca5a5db374e16a6ab3555627faa79b.zip
Add default values for parameters
Diffstat (limited to 'core/src/main')
-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
3 files changed, 24 insertions, 5 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)
}