Convenience functions
This commit is contained in:
parent
9355eefb65
commit
04c430d9ce
@ -344,16 +344,19 @@ 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) {
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: T?) {
|
||||
if (value == null) {
|
||||
meta.remove(key ?: property.name)
|
||||
} else {
|
||||
meta[key ?: property.name] = value.config
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ReadWriteDelegateWrapper<T, R>(
|
||||
val delegate: ReadWriteProperty<Any?, T>,
|
||||
|
@ -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