diff options
author | Szymon Świstun <sswistun@virtuslab.com> | 2020-03-16 13:08:29 +0100 |
---|---|---|
committer | Kamil Doległo <kamilok1965@users.noreply.github.com> | 2020-03-18 14:40:29 +0100 |
commit | 3de1182033ca5a5db374e16a6ab3555627faa79b (patch) | |
tree | 192580f4a08340466fd293a7199f110e34fe1dbf /core/src/main/kotlin/model | |
parent | 03329b0eb98b309d208839344052633028e00984 (diff) | |
download | dokka-3de1182033ca5a5db374e16a6ab3555627faa79b.tar.gz dokka-3de1182033ca5a5db374e16a6ab3555627faa79b.tar.bz2 dokka-3de1182033ca5a5db374e16a6ab3555627faa79b.zip |
Add default values for parameters
Diffstat (limited to 'core/src/main/kotlin/model')
-rw-r--r-- | core/src/main/kotlin/model/defaultValues.kt | 18 | ||||
-rw-r--r-- | core/src/main/kotlin/model/properties/PropertyContainer.kt | 5 |
2 files changed, 21 insertions, 2 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) } } |