Basic design for external connectors
This commit is contained in:
parent
a2e8d4f018
commit
93c806c3bf
@ -62,7 +62,7 @@ class PluginManager(override val context: Context) : ContextAware, Iterable<Plug
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
operator fun <T : Any> get(type: KClass<T>, tag: PluginTag? = null, recursive: Boolean = true): T? =
|
operator fun <T : Any> get(type: KClass<out T>, tag: PluginTag? = null, recursive: Boolean = true): T? =
|
||||||
find(recursive) { type.isInstance(it) && (tag == null || tag.matches(it.tag)) } as T?
|
find(recursive) { type.isInstance(it) && (tag == null || tag.matches(it.tag)) } as T?
|
||||||
|
|
||||||
inline operator fun <reified T : Any> get(tag: PluginTag? = null, recursive: Boolean = true): T? =
|
inline operator fun <reified T : Any> get(tag: PluginTag? = null, recursive: Boolean = true): T? =
|
||||||
|
@ -15,6 +15,10 @@ class MetaBuilder : AbstractMutableMeta<MetaBuilder>() {
|
|||||||
override fun wrapNode(meta: Meta): MetaBuilder = if (meta is MetaBuilder) meta else meta.builder()
|
override fun wrapNode(meta: Meta): MetaBuilder = if (meta is MetaBuilder) meta else meta.builder()
|
||||||
override fun empty(): MetaBuilder = MetaBuilder()
|
override fun empty(): MetaBuilder = MetaBuilder()
|
||||||
|
|
||||||
|
infix fun String.put(item: MetaItem<*>?) {
|
||||||
|
set(this, item)
|
||||||
|
}
|
||||||
|
|
||||||
infix fun String.put(value: Value?) {
|
infix fun String.put(value: Value?) {
|
||||||
set(this, value)
|
set(this, value)
|
||||||
}
|
}
|
||||||
|
@ -49,9 +49,19 @@ fun <T, R> ReadWriteProperty<Any?, T>.map(reader: (T) -> R, writer: (R) -> T): R
|
|||||||
fun <R> ReadWriteProperty<Any?, MetaItem<*>?>.transform(reader: (MetaItem<*>?) -> R): ReadWriteProperty<Any?, R> =
|
fun <R> ReadWriteProperty<Any?, MetaItem<*>?>.transform(reader: (MetaItem<*>?) -> R): ReadWriteProperty<Any?, R> =
|
||||||
map(reader = reader, writer = { MetaItem.of(it) })
|
map(reader = reader, writer = { MetaItem.of(it) })
|
||||||
|
|
||||||
fun <R> ReadWriteProperty<Any?, Value?>.transform(reader: (Value?) -> R) =
|
fun <R> ReadWriteProperty<Any?, Value?>.transform(reader: (Value?) -> R): ReadWriteDelegateWrapper<Value?, R> =
|
||||||
map(reader = reader, writer = { Value.of(it) })
|
map(reader = reader, writer = { Value.of(it) })
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A delegate that throws
|
||||||
|
*/
|
||||||
|
fun <R : Any> ReadWriteProperty<Any?, R?>.notNull(default: () -> R): ReadWriteProperty<Any?, R> {
|
||||||
|
return ReadWriteDelegateWrapper(this,
|
||||||
|
reader = { it ?: default() },
|
||||||
|
writer = { it }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
fun <M : MutableMeta<M>> M.item(default: Any? = null, key: Name? = null): MutableMetaDelegate<M> =
|
fun <M : MutableMeta<M>> M.item(default: Any? = null, key: Name? = null): MutableMetaDelegate<M> =
|
||||||
MutableMetaDelegate(this, key, default?.let { MetaItem.of(it) })
|
MutableMetaDelegate(this, key, default?.let { MetaItem.of(it) })
|
||||||
|
@ -59,8 +59,7 @@ open class Scheme() : Configurable, Described, MetaRepr {
|
|||||||
/**
|
/**
|
||||||
* A specification for simplified generation of wrappers
|
* A specification for simplified generation of wrappers
|
||||||
*/
|
*/
|
||||||
open class SchemeSpec<T : Scheme>(val builder: () -> T) :
|
open class SchemeSpec<T : Scheme>(val builder: () -> T) : Specification<T> {
|
||||||
Specification<T> {
|
|
||||||
override fun wrap(config: Config, defaultProvider: (Name) -> MetaItem<*>?): T {
|
override fun wrap(config: Config, defaultProvider: (Name) -> MetaItem<*>?): T {
|
||||||
return builder().apply {
|
return builder().apply {
|
||||||
this.config = config
|
this.config = config
|
||||||
|
Loading…
Reference in New Issue
Block a user