Convenience functions
This commit is contained in:
parent
9355eefb65
commit
04c430d9ce
@ -344,14 +344,17 @@ class MutableMorphDelegate<M : MutableMetaNode<M>, T : Configurable>(
|
|||||||
val meta: M,
|
val meta: M,
|
||||||
private val key: String? = null,
|
private val key: String? = null,
|
||||||
private val converter: (Meta) -> T
|
private val converter: (Meta) -> T
|
||||||
) :
|
) : ReadWriteProperty<Any?, T?> {
|
||||||
ReadWriteProperty<Any?, T> {
|
override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
|
||||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
return meta[key ?: property.name]?.node?.let(converter)
|
||||||
return converter(meta[key ?: property.name]?.node ?: EmptyMeta)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
|
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T?) {
|
||||||
meta[key ?: property.name] = value.config
|
if (value == null) {
|
||||||
|
meta.remove(key ?: property.name)
|
||||||
|
} else {
|
||||||
|
meta[key ?: property.name] = value.config
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,4 +116,7 @@ fun Name.withIndex(index: String): Name {
|
|||||||
tokens.removeAt(tokens.size - 1)
|
tokens.removeAt(tokens.size - 1)
|
||||||
tokens.add(last)
|
tokens.add(last)
|
||||||
return Name(tokens)
|
return Name(tokens)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
operator fun <T> Map<Name, T>.get(name: String) = get(name.toName())
|
||||||
|
operator fun <T> MutableMap<Name, T>.set(name: String, value: T) = set(name.toName(), value)
|
Loading…
Reference in New Issue
Block a user