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,
|
||||
private val key: String? = null,
|
||||
private val converter: (Meta) -> T
|
||||
) :
|
||||
ReadWriteProperty<Any?, T> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
||||
return converter(meta[key ?: property.name]?.node ?: EmptyMeta)
|
||||
) : ReadWriteProperty<Any?, T?> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T? {
|
||||
return meta[key ?: property.name]?.node?.let(converter)
|
||||
}
|
||||
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
|
||||
meta[key ?: property.name] = value.config
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T?) {
|
||||
if (value == null) {
|
||||
meta.remove(key ?: property.name)
|
||||
} else {
|
||||
meta[key ?: property.name] = value.config
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,3 +117,6 @@ fun Name.withIndex(index: String): Name {
|
||||
tokens.add(last)
|
||||
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