Sorting default jvm props and basic implementations

This commit is contained in:
Ilya Chernikov
2018-07-23 13:42:39 +02:00
parent fe2a11142e
commit 70ec004aaa
19 changed files with 110 additions and 133 deletions
@@ -22,6 +22,8 @@ class PropertiesBuilderDelegate<T: PropertiesBuilder>(val kclass: KClass<T>) {
inline fun <reified T : PropertiesBuilder> propertiesBuilder() = PropertiesBuilderDelegate(T::class)
fun buildScriptingProperties(body: ScriptingProperties.() -> Unit): ChainedPropertyBag =
ScriptingProperties(body).build()
open class ScriptingProperties(body: ScriptingProperties.() -> Unit = {}) {
@@ -31,12 +33,13 @@ open class ScriptingProperties(body: ScriptingProperties.() -> Unit = {}) {
init {
body()
setup() // TODO: does it work?
}
open fun setup() {}
internal fun makePropertyBag(): ChainedPropertyBag =
ChainedPropertyBag.createOptimized(parentPropertiesBag ?: parentPropertiesBuilder?.makePropertyBag(), data)
fun build(): ChainedPropertyBag =
ChainedPropertyBag.createOptimized(parentPropertiesBag ?: parentPropertiesBuilder?.build(), data)
// --------------------------
// DSL:
@@ -75,6 +78,7 @@ open class ScriptingProperties(body: ScriptingProperties.() -> Unit = {}) {
// inclusion:
fun include(props: ScriptingProperties) {
props.setup()
data.putAll(props.data)
}
@@ -26,6 +26,7 @@ open class ChainedPropertyBag internal constructor(private val parent: ChainedPr
constructor(vararg pairs: Pair<TypedKey<*>, Any?>) : this(null, pairs.asIterable())
fun cloneWithNewParent(newParent: ChainedPropertyBag?): ChainedPropertyBag = when {
this == newParent -> this
newParent == null -> this
parent == null -> createOptimized(newParent, data)
else -> createOptimized(parent.cloneWithNewParent(newParent), data)