From 34abab607145c8dc1405e40001cb7dec554a8d54 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Thu, 20 Feb 2020 16:43:59 +0100 Subject: Sketch of property container --- .../main/kotlin/model/properties/PropertyContainer.kt | 17 +++++++++++++++++ core/src/main/kotlin/model/properties/properties.kt | 6 ++++++ 2 files changed, 23 insertions(+) create mode 100644 core/src/main/kotlin/model/properties/PropertyContainer.kt create mode 100644 core/src/main/kotlin/model/properties/properties.kt (limited to 'core') 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 private constructor( + @PublishedApi internal val map: Map, Property> +) { + operator fun plus(prop: Property): PropertyContainer = + PropertyContainer(map + (prop.key to prop)) + + inline operator fun get(key: Property.Key): 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 = 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 { + interface Key + val key: Key +} -- cgit