aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-02-24 12:09:17 +0100
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-02-27 10:51:51 +0100
commitd92f286903efda12acec74cc1b5e99687e5447aa (patch)
tree2f8c64f7364bf4ffb07262b4b41fa81c867f0c98 /core/src/main/kotlin
parent34abab607145c8dc1405e40001cb7dec554a8d54 (diff)
downloaddokka-d92f286903efda12acec74cc1b5e99687e5447aa.tar.gz
dokka-d92f286903efda12acec74cc1b5e99687e5447aa.tar.bz2
dokka-d92f286903efda12acec74cc1b5e99687e5447aa.zip
Adds calculated properties
Diffstat (limited to 'core/src/main/kotlin')
-rw-r--r--core/src/main/kotlin/model/properties/PropertyContainer.kt1
-rw-r--r--core/src/main/kotlin/model/properties/properties.kt4
2 files changed, 5 insertions, 0 deletions
diff --git a/core/src/main/kotlin/model/properties/PropertyContainer.kt b/core/src/main/kotlin/model/properties/PropertyContainer.kt
index 1b854518..da351569 100644
--- a/core/src/main/kotlin/model/properties/PropertyContainer.kt
+++ b/core/src/main/kotlin/model/properties/PropertyContainer.kt
@@ -6,6 +6,7 @@ class PropertyContainer<C : Any> private constructor(
operator fun <D : C> plus(prop: Property<D>): PropertyContainer<D> =
PropertyContainer(map + (prop.key to prop))
+ // TODO: Add logic for caching calculated properties
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.")
diff --git a/core/src/main/kotlin/model/properties/properties.kt b/core/src/main/kotlin/model/properties/properties.kt
index b8965abc..5ff1305a 100644
--- a/core/src/main/kotlin/model/properties/properties.kt
+++ b/core/src/main/kotlin/model/properties/properties.kt
@@ -4,3 +4,7 @@ interface Property<in C : Any> {
interface Key<in C: Any, T: Any>
val key: Key<C, *>
}
+
+interface CalculatedProperty<in C: Any, T: Any>: Property.Key<C, T> {
+ fun calculate(subject: C): T
+} \ No newline at end of file