diff options
author | Paweł Marks <pmarks@virtuslab.com> | 2020-02-20 16:43:59 +0100 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-02-27 10:51:51 +0100 |
commit | 34abab607145c8dc1405e40001cb7dec554a8d54 (patch) | |
tree | 27b80ae04b88dbe1283795df8448b58013af0a56 | |
parent | c7dc9db1dabfa2847df5c15862889b2c17e9d58d (diff) | |
download | dokka-34abab607145c8dc1405e40001cb7dec554a8d54.tar.gz dokka-34abab607145c8dc1405e40001cb7dec554a8d54.tar.bz2 dokka-34abab607145c8dc1405e40001cb7dec554a8d54.zip |
Sketch of property container
-rw-r--r-- | core/src/main/kotlin/model/properties/PropertyContainer.kt | 17 | ||||
-rw-r--r-- | core/src/main/kotlin/model/properties/properties.kt | 6 |
2 files changed, 23 insertions, 0 deletions
diff --git a/core/src/main/kotlin/model/properties/PropertyContainer.kt b/core/src/main/kotlin/model/properties/PropertyContainer.kt new file mode 100644 index 00000000..1b854518 --- /dev/null +++ b/core/src/main/kotlin/model/properties/PropertyContainer.kt @@ -0,0 +1,17 @@ +package org.jetbrains.dokka.model.properties + +class PropertyContainer<C : Any> private constructor( + @PublishedApi internal val map: Map<Property.Key<C, *>, Property<C>> +) { + operator fun <D : C> plus(prop: Property<D>): PropertyContainer<D> = + PropertyContainer(map + (prop.key to prop)) + + inline operator fun <reified T: Any> get(key: Property.Key<C, T>): T? = when (val prop = map[key]) { + is T? -> prop + else -> throw ClassCastException("Property for $key stored under not matching key type.") + } + + companion object { + val empty: PropertyContainer<Any> = PropertyContainer(emptyMap()) + } +}
\ No newline at end of file diff --git a/core/src/main/kotlin/model/properties/properties.kt b/core/src/main/kotlin/model/properties/properties.kt new file mode 100644 index 00000000..b8965abc --- /dev/null +++ b/core/src/main/kotlin/model/properties/properties.kt @@ -0,0 +1,6 @@ +package org.jetbrains.dokka.model.properties + +interface Property<in C : Any> { + interface Key<in C: Any, T: Any> + val key: Key<C, *> +} |