Cleaup context building API

This commit is contained in:
Alexander Nozik 2021-04-07 18:47:24 +03:00
parent 874a253292
commit 53393e7958
4 changed files with 12 additions and 7 deletions

View File

@ -38,7 +38,8 @@ public final class space/kscience/dataforge/context/ClassLoaderPluginKt {
public class space/kscience/dataforge/context/Context : kotlinx/coroutines/CoroutineScope, space/kscience/dataforge/meta/MetaRepr, space/kscience/dataforge/misc/Named, space/kscience/dataforge/provider/Provider { public class space/kscience/dataforge/context/Context : kotlinx/coroutines/CoroutineScope, space/kscience/dataforge/meta/MetaRepr, space/kscience/dataforge/misc/Named, space/kscience/dataforge/provider/Provider {
public static final field Companion Lspace/kscience/dataforge/context/Context$Companion; public static final field Companion Lspace/kscience/dataforge/context/Context$Companion;
public static final field PROPERTY_TARGET Ljava/lang/String; public static final field PROPERTY_TARGET Ljava/lang/String;
public final fun buildContext (Lkotlin/jvm/functions/Function1;)Lspace/kscience/dataforge/context/Context; public final fun buildContext (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lspace/kscience/dataforge/context/Context;
public static synthetic fun buildContext$default (Lspace/kscience/dataforge/context/Context;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/dataforge/context/Context;
public fun close ()V public fun close ()V
public fun content (Ljava/lang/String;)Ljava/util/Map; public fun content (Ljava/lang/String;)Ljava/util/Map;
public final fun content (Ljava/lang/String;Z)Ljava/util/Map; public final fun content (Ljava/lang/String;Z)Ljava/util/Map;
@ -102,8 +103,8 @@ public final class space/kscience/dataforge/context/Factory$DefaultImpls {
} }
public final class space/kscience/dataforge/context/GlobalKt { public final class space/kscience/dataforge/context/GlobalKt {
public static final fun Context (Lkotlin/jvm/functions/Function1;)Lspace/kscience/dataforge/context/Context; public static final fun Context (Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Lspace/kscience/dataforge/context/Context;
public static synthetic fun Context$default (Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/dataforge/context/Context; public static synthetic fun Context$default (Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lspace/kscience/dataforge/context/Context;
public static final fun getGlobal ()Lspace/kscience/dataforge/context/Context; public static final fun getGlobal ()Lspace/kscience/dataforge/context/Context;
} }

View File

@ -76,8 +76,11 @@ public open class Context internal constructor(
* Build and register a child context * Build and register a child context
*/ */
@Synchronized @Synchronized
public fun buildContext(block: ContextBuilder.() -> Unit): Context{ public fun buildContext(name: String? = null, block: ContextBuilder.() -> Unit): Context {
val newContext = ContextBuilder(this).apply(block).build() val newContext = ContextBuilder(this)
.apply { name?.let { name(it) } }
.apply(block)
.build()
childrenContexts[newContext.name] = newContext childrenContexts[newContext.name] = newContext
return newContext return newContext
} }

View File

@ -19,4 +19,5 @@ private object GlobalContext : Context("GLOBAL".asName(), null, Meta.EMPTY) {
public val Global: Context get() = GlobalContext public val Global: Context get() = GlobalContext
public fun Context(block: ContextBuilder.() -> Unit = {}): Context = Global.buildContext(block) public fun Context(name: String? = null, block: ContextBuilder.() -> Unit = {}): Context =
Global.buildContext(name, block)

View File

@ -51,7 +51,7 @@ public class WorkspaceBuilder(private val parentContext: Context = Global) : Tas
* Define a context for the workspace * Define a context for the workspace
*/ */
public fun context(block: ContextBuilder.() -> Unit = {}) { public fun context(block: ContextBuilder.() -> Unit = {}) {
this.context = parentContext.buildContext(block) this.context = parentContext.buildContext("workspace", block)
} }
/** /**