aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/kotlin/model/properties/PropertyContainer.kt17
-rw-r--r--core/src/main/kotlin/model/properties/properties.kt6
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, *>
+}