Limit scheme property extension to MutableMeta to avoid override resolution ambiguity
This commit is contained in:
parent
3acbaffecb
commit
671d2b2493
CHANGELOG.mdbuild.gradle.kts
dataforge-io
dataforge-meta/src
commonMain/kotlin/space/kscience/dataforge/meta
commonTest/kotlin/space/kscience/dataforge/meta
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Incorrect work of `MetaWithDefault::getValue`
|
- Incorrect work of `MetaWithDefault::getValue`
|
||||||
|
- Incorrect work of scheme delegate
|
||||||
|
|
||||||
### Security
|
### Security
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ plugins {
|
|||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
group = "space.kscience"
|
group = "space.kscience"
|
||||||
version = "0.10.1-dev"
|
version = "0.10.1-dev-1"
|
||||||
}
|
}
|
||||||
|
|
||||||
subprojects {
|
subprojects {
|
||||||
|
@ -4,8 +4,6 @@ plugins {
|
|||||||
|
|
||||||
description = "IO module"
|
description = "IO module"
|
||||||
|
|
||||||
val ioVersion = "0.6.0"
|
|
||||||
|
|
||||||
kscience {
|
kscience {
|
||||||
jvm()
|
jvm()
|
||||||
js()
|
js()
|
||||||
@ -17,8 +15,8 @@ kscience {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
api(projects.dataforgeContext)
|
api(projects.dataforgeContext)
|
||||||
api("org.jetbrains.kotlinx:kotlinx-io-core:$ioVersion")
|
api(spclibs.kotlinx.io.core)
|
||||||
api("org.jetbrains.kotlinx:kotlinx-io-bytestring:$ioVersion")
|
api(spclibs.kotlinx.io.bytestring)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,15 +219,15 @@ public fun <T : Scheme> Configurable.updateWith(
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A delegate that uses a [MetaReader] to wrap a child of this provider
|
* A delegate that uses a [SchemeSpec] to wrap a child of this provider
|
||||||
*/
|
*/
|
||||||
public fun <T : Scheme> MutableMetaProvider.scheme(
|
public fun <T : Scheme> MutableMeta.scheme(
|
||||||
spec: SchemeSpec<T>,
|
spec: SchemeSpec<T>,
|
||||||
key: Name? = null,
|
key: Name? = null,
|
||||||
): ReadWriteProperty<Any?, T> = object : ReadWriteProperty<Any?, T> {
|
): ReadWriteProperty<Any?, T> = object : ReadWriteProperty<Any?, T> {
|
||||||
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
override fun getValue(thisRef: Any?, property: KProperty<*>): T {
|
||||||
val name = key ?: property.name.asName()
|
val name = key ?: property.name.asName()
|
||||||
val node = get(name) ?: MutableMeta().also { set(name, it) }
|
val node = getOrCreate(name)
|
||||||
return spec.write(node)
|
return spec.write(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +243,7 @@ public fun <T : Scheme> Scheme.scheme(
|
|||||||
): ReadWriteProperty<Any?, T> = meta.scheme(spec, key)
|
): ReadWriteProperty<Any?, T> = meta.scheme(spec, key)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A delegate that uses a [MetaReader] to wrap a child of this provider.
|
* A delegate that uses a [SchemeSpec] to wrap a child of this provider.
|
||||||
* Returns null if meta with given name does not exist.
|
* Returns null if meta with given name does not exist.
|
||||||
*/
|
*/
|
||||||
public fun <T : Scheme> MutableMeta.schemeOrNull(
|
public fun <T : Scheme> MutableMeta.schemeOrNull(
|
||||||
|
@ -26,18 +26,17 @@ internal class TestScheme : Scheme() {
|
|||||||
companion object : SchemeSpec<TestScheme>(::TestScheme)
|
companion object : SchemeSpec<TestScheme>(::TestScheme)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class SchemeWithInit: Scheme(){
|
private class SchemeWithInit : Scheme() {
|
||||||
init {
|
init {
|
||||||
set("initial", "initialValue")
|
set("initial", "initialValue")
|
||||||
}
|
}
|
||||||
|
|
||||||
var initial by string()
|
var initial by string()
|
||||||
|
|
||||||
companion object: SchemeSpec<SchemeWithInit>(::SchemeWithInit)
|
companion object : SchemeSpec<SchemeWithInit>(::SchemeWithInit)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SpecificationTest {
|
class SpecificationTest {
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
@ -126,11 +125,11 @@ class SpecificationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testListSubscription(){
|
fun testListSubscription() {
|
||||||
val scheme = TestScheme.empty()
|
val scheme = TestScheme.empty()
|
||||||
var value: Value? = null
|
var value: Value? = null
|
||||||
scheme.v = ListValue(0.0,0.0,0.0)
|
scheme.v = ListValue(0.0, 0.0, 0.0)
|
||||||
scheme.useProperty(TestScheme::v){
|
scheme.useProperty(TestScheme::v) {
|
||||||
value = it
|
value = it
|
||||||
}
|
}
|
||||||
scheme.v = ListValue(1.0, 2.0, 3.0)
|
scheme.v = ListValue(1.0, 2.0, 3.0)
|
||||||
@ -138,17 +137,17 @@ class SpecificationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testSubScheme(){
|
fun testSubScheme() {
|
||||||
val scheme = TestScheme.empty()
|
val scheme = TestScheme.empty()
|
||||||
|
|
||||||
scheme.sub.subValue = "aaa"
|
scheme.sub.subValue = "aaa"
|
||||||
|
|
||||||
assertEquals("aaa",scheme.sub.subValue)
|
assertEquals("aaa", scheme.sub.subValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testSchemeWithInit(){
|
fun testSchemeWithInit() {
|
||||||
val scheme = SchemeWithInit()
|
val scheme = SchemeWithInit()
|
||||||
assertEquals("initialValue", scheme.initial)
|
assertEquals("initialValue", scheme.initial)
|
||||||
scheme.initial = "none"
|
scheme.initial = "none"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user