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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,4 +116,7 @@ fun Name.withIndex(index: String): Name {
|
||||
tokens.removeAt(tokens.size - 1)
|
||||
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