From 58914cdf33be43ddb74fb330c673d0ae96f2ac75 Mon Sep 17 00:00:00 2001 From: Maxim Shafirov Date: Thu, 30 May 2013 17:54:27 +0400 Subject: [PATCH] Delegate properties stdlib, take 2. --- .../src/kotlin/properties/Delegation.kt | 175 ++++++++++++++++++ .../src/kotlin/properties/Properties.kt | 5 +- .../properties/delegation/Delegation.kt | 118 ------------ .../properties/delegation/lazy/LazyValues.kt | 75 -------- .../properties/delegation/DelegationTest.kt | 8 +- .../delegation/MapDelegationTest.kt | 91 ++++----- .../delegation/lazy/LazyValuesTest.kt | 20 +- 7 files changed, 236 insertions(+), 256 deletions(-) create mode 100644 libraries/stdlib/src/kotlin/properties/Delegation.kt delete mode 100644 libraries/stdlib/src/kotlin/properties/delegation/Delegation.kt delete mode 100644 libraries/stdlib/src/kotlin/properties/delegation/lazy/LazyValues.kt diff --git a/libraries/stdlib/src/kotlin/properties/Delegation.kt b/libraries/stdlib/src/kotlin/properties/Delegation.kt new file mode 100644 index 00000000000..a56b98b2a78 --- /dev/null +++ b/libraries/stdlib/src/kotlin/properties/Delegation.kt @@ -0,0 +1,175 @@ +package kotlin.properties + +public trait ReadOnlyProperty { + public fun get(thisRef: R, desc: PropertyMetadata): T +} + +public trait ReadWriteProperty { + public fun get(thisRef: R, desc: PropertyMetadata): T + public fun set(thisRef: R, desc: PropertyMetadata, value: T) +} + +public object Delegates { + public fun notNull(): ReadWriteProperty = NotNullVar() + + public fun lazy(initializer: () -> T): ReadOnlyProperty = LazyVal(initializer) + public fun blockingLazy(lock: Any? = null, initializer: () -> T): ReadOnlyProperty = BlockingLazyVal(lock, initializer) + + public fun observable(initial: T, onChange: (desc: PropertyMetadata, oldValue: T, newValue: T) -> Unit): ReadWriteProperty { + return ObservableProperty(initial) { (desc, old, new) -> + onChange(desc, old, new) + true + } + } + + public fun vetoable(initial: T, onChange: (desc: PropertyMetadata, oldValue: T, newValue: T) -> Boolean): ReadWriteProperty { + return ObservableProperty(initial, onChange) + } + + public fun mapVar(map: MutableMap, + default: (thisRef: Any?, desc: String) -> T = defaultValueProvider): ReadWriteProperty { + return FixedMapVar(map, defaultKeyProvider, default) + } + + public fun mapVal(map: Map, + default: (thisRef: Any?, desc: String) -> T = defaultValueProvider): ReadOnlyProperty { + return FixedMapVal(map, defaultKeyProvider, default) + } +} + + +private class NotNullVar() : ReadWriteProperty { + private var value: T? = null + + public override fun get(thisRef: Any?, desc: PropertyMetadata): T { + return value ?: throw IllegalStateException("Property ${desc.name} should be initialized before get") + } + + public override fun set(thisRef: Any?, desc: PropertyMetadata, value: T) { + this.value = value + } +} + +class ObservableProperty(initialValue: T, val onChange: (name: jet.PropertyMetadata, oldValue: T, newValue: T) -> Boolean): ReadWriteProperty { + private var value = initialValue + + public override fun get(thisRef: Any?, desc: PropertyMetadata): T { + return value + } + + public override fun set(thisRef: Any?, desc: PropertyMetadata, value: T) { + if (onChange(desc, this.value, value)) { + this.value = value + } + } +} + +private val NULL_VALUE: Any = Any() + +private fun escape(value: Any?): Any { + return value ?: NULL_VALUE +} + +private fun unescape(value: Any?): Any? { + return if (value == NULL_VALUE) null else value +} + +private class LazyVal(private val initializer: () -> T) : ReadOnlyProperty { + private var value: Any? = null + + public override fun get(thisRef: Any?, desc: PropertyMetadata): T { + if (value == null) { + value = escape(initializer()) + } + return unescape(value) as T + } +} + +private class BlockingLazyVal(lock: Any?, private val initializer: () -> T) : ReadOnlyProperty { + private val lock = lock ?: this + private volatile var value: Any? = null + + public override fun get(thisRef: Any?, desc: PropertyMetadata): T { + val _v1 = value + if (_v1 != null) { + return unescape(_v1) as T + } + + return synchronized(lock) { + val _v2 = value + if (_v2 != null) { + unescape(_v2) as T + } + else { + val typedValue = initializer() + value = escape(typedValue) + typedValue + } + } + } +} + +public class KeyMissingException(message: String): RuntimeException(message) + +public abstract class MapVal() : ReadOnlyProperty { + protected abstract fun map(ref: T): Map + protected abstract fun key(desc: PropertyMetadata): K + + protected open fun default(ref: T, desc: PropertyMetadata): V { + throw KeyMissingException("Key $desc is missing in $ref") + } + + public override fun get(thisRef: T, desc: PropertyMetadata) : V { + val map = map(thisRef) + val key = key(desc) + if (!map.containsKey(key)) { + return default(thisRef, desc) + } + + return map[key] as V + } +} + +public abstract class MapVar() : MapVal(), ReadWriteProperty { + protected abstract override fun map(ref: T): MutableMap + + public override fun set(thisRef: T, desc: PropertyMetadata, value: V) { + val map = map(thisRef) + map.put(key(desc), value) + } +} + +private val defaultKeyProvider:(PropertyMetadata) -> String = {it.name} +private val defaultValueProvider:(Any?, Any?) -> Nothing = {(thisRef, key) -> throw KeyMissingException("$key is missing from $thisRef")} + +public open class FixedMapVal(private val map: Map, + private val key: (PropertyMetadata) -> K, + private val default: (ref: T, key: K) -> V = defaultValueProvider) : MapVal() { + protected override fun map(ref: T): Map { + return map + } + + protected override fun key(desc: PropertyMetadata): K { + return (key)(desc) + } + + protected override fun default(ref: T, desc: PropertyMetadata): V { + return (default)(ref, key(desc)) + } +} + +public open class FixedMapVar(private val map: MutableMap, + private val key: (PropertyMetadata) -> K, + private val default: (ref: T, key: K) -> V = defaultValueProvider) : MapVar() { + protected override fun map(ref: T): MutableMap { + return map + } + + protected override fun key(desc: PropertyMetadata): K { + return (key)(desc) + } + + protected override fun default(ref: T, desc: PropertyMetadata): V { + return (default)(ref, key(desc)) + } +} diff --git a/libraries/stdlib/src/kotlin/properties/Properties.kt b/libraries/stdlib/src/kotlin/properties/Properties.kt index e045c5993c6..78dc550e692 100644 --- a/libraries/stdlib/src/kotlin/properties/Properties.kt +++ b/libraries/stdlib/src/kotlin/properties/Properties.kt @@ -2,7 +2,6 @@ package kotlin.properties import java.util.HashMap import java.util.ArrayList -import kotlin.properties.delegation.ObservableProperty public class ChangeEvent(val source: Any, val name: String, val oldValue: Any?, val newValue: Any?) { var propogationId: Any? = null @@ -65,8 +64,8 @@ public abstract class ChangeSupport { } } - protected fun property(init: T): ObservableProperty { - return ObservableProperty(init) { name, oldValue, newValue -> changeProperty(name, oldValue, newValue) } + protected fun property(init: T): ReadWriteProperty { + return Delegates.observable(init) { desc, oldValue, newValue -> changeProperty(desc.name, oldValue, newValue) } } public fun onPropertyChange(fn: (ChangeEvent) -> Unit) { diff --git a/libraries/stdlib/src/kotlin/properties/delegation/Delegation.kt b/libraries/stdlib/src/kotlin/properties/delegation/Delegation.kt deleted file mode 100644 index fe4dbb05a6d..00000000000 --- a/libraries/stdlib/src/kotlin/properties/delegation/Delegation.kt +++ /dev/null @@ -1,118 +0,0 @@ -package kotlin.properties.delegation - -import kotlin.properties.ChangeSupport - -public class NotNullVar { - private var value: T? = null - - public fun get(thisRef: Any?, desc: PropertyMetadata): T { - return value ?: throw IllegalStateException("Property ${desc.name} should be initialized before get") - } - - public fun set(thisRef: Any?, desc: PropertyMetadata, value: T) { - this.value = value - } -} - -public class SynchronizedVar(private val initValue: T, private val lock: Any) { - private var value: T = initValue - - public fun get(thisRef: Any?, desc: PropertyMetadata): T { - return synchronized(lock) { value } - } - - public fun set(thisRef: Any?, desc: PropertyMetadata, newValue: T) { - synchronized(lock) { - value = newValue - } - } -} - -class ObservableProperty(initialValue: T, val changeSupport: (name: String, oldValue: T, newValue: T) -> Unit) { - private var value = initialValue - - public fun get(thisRef: Any?, desc: PropertyMetadata): T { - return value - } - - public fun set(thisRef: Any?, desc: PropertyMetadata, newValue: T) { - changeSupport(desc.name, value, newValue) - value = newValue - } -} - -public class KeyMissingException(message: String): RuntimeException(message) - -public abstract class MapVal { - public abstract fun getMap(thisRef: T): Map<*, *> - public abstract fun getKey(desc: PropertyMetadata): Any? - - public open fun getDefaultValue(desc: PropertyMetadata, key: Any?): V { - throw KeyMissingException("Key $key is missing") - } - - public fun get(thisRef: T, desc: PropertyMetadata): V { - val key = getKey(desc) - val map = getMap(thisRef) - if (!map.containsKey(key)) { - return getDefaultValue(desc, key) - } - return map[key] as V - } -} - -public abstract class MapVar: MapVal() { - - public fun set(thisRef: T, desc: PropertyMetadata, newValue: V) { - val map = getMap(thisRef) as MutableMap - map[getKey(desc)] = newValue - } -} - -public fun Map.readOnlyProperty(default: (() -> V)? = null): MapVal { - return object: MapVal() { - override fun getMap(thisRef: Any?) = this@readOnlyProperty - override fun getKey(desc: PropertyMetadata) = desc.name - override fun getDefaultValue(desc: PropertyMetadata, key: Any?) = if (default == null) super.getDefaultValue(desc, key) else default() - } -} - -public fun Map<*, *>.readOnlyProperty(default: (() -> V)? = null, key: Any?): MapVal { - return object: MapVal() { - override fun getMap(thisRef: Any?) = this@readOnlyProperty - override fun getKey(desc: PropertyMetadata) = key - override fun getDefaultValue(desc: PropertyMetadata, key: Any?) = if (default == null) super.getDefaultValue(desc, key) else default() - } -} - -public fun Map<*, *>.readOnlyProperty(default: (() -> V)? = null, key: (desc: PropertyMetadata) -> Any?): MapVal { - return object: MapVal() { - override fun getMap(thisRef: Any?) = this@readOnlyProperty - override fun getKey(desc: PropertyMetadata) = key(desc) - override fun getDefaultValue(desc: PropertyMetadata, key: Any?) = if (default == null) super.getDefaultValue(desc, key) else default() - } -} - -public fun MutableMap.property(default: (() -> V)? = null): MapVar { - return object: MapVar() { - override fun getMap(thisRef: Any?) = this@property - override fun getKey(desc: PropertyMetadata) = desc.name - override fun getDefaultValue(desc: PropertyMetadata, key: Any?) = if (default == null) super.getDefaultValue(desc, key) else default() - } -} - -public fun MutableMap<*, *>.property(default: (() -> V)? = null, key: Any?): MapVar { - return object: MapVar() { - override fun getMap(thisRef: Any?) = this@property - override fun getKey(desc: PropertyMetadata) = key - override fun getDefaultValue(desc: PropertyMetadata, key: Any?) = if (default == null) super.getDefaultValue(desc, key) else default() - } -} - -public fun MutableMap<*, *>.property(default: (() -> V)? = null, key: (desc: PropertyMetadata) -> Any?): MapVar { - return object: MapVar() { - override fun getMap(thisRef: Any?) = this@property - override fun getKey(desc: PropertyMetadata) = key(desc) - override fun getDefaultValue(desc: PropertyMetadata, key: Any?) = if (default == null) super.getDefaultValue(desc, key) else default() - } -} \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/properties/delegation/lazy/LazyValues.kt b/libraries/stdlib/src/kotlin/properties/delegation/lazy/LazyValues.kt deleted file mode 100644 index 2d0767446d3..00000000000 --- a/libraries/stdlib/src/kotlin/properties/delegation/lazy/LazyValues.kt +++ /dev/null @@ -1,75 +0,0 @@ -package kotlin.properties.delegation.lazy - -private val NULL_VALUE: Any = Any() - -private fun escape(value: T): Any { - return if (value == null) NULL_VALUE else value -} - -private fun unescape(value: Any): T? { - return if (value == NULL_VALUE) null else value as T -} - -public open class LazyVal(initializer: () -> T): NullableLazyVal(initializer) { - override fun get(thisRef: Any?, desc: PropertyMetadata): T { - return super.get(thisRef, desc)!! - } -} - -public open class NullableLazyVal(private val initializer: () -> T?) { - private var value: Any? = null - - public open fun get(thisRef: Any?, desc: PropertyMetadata): T? { - if (value == null) { - value = escape(initializer()) - } - return unescape(value!!) - } -} - -public open class VolatileLazyVal(initializer: () -> T): VolatileNullableLazyVal(initializer) { - override fun get(thisRef: Any?, desc: PropertyMetadata): T { - return super.get(thisRef, desc)!! - } -} - -public open class VolatileNullableLazyVal(private val initializer: () -> T?) { - private volatile var value: Any? = null - - public open fun get(thisRef: Any?, desc: PropertyMetadata): T? { - if (value == null) { - value = escape(initializer()) - } - return unescape(value!!) - } -} - -public open class AtomicLazyVal(lock: Any? = null, initializer: () -> T): AtomicNullableLazyVal(lock, initializer) { - override fun get(thisRef: Any?, desc: PropertyMetadata): T { - return super.get(thisRef, desc)!! - } -} - -public open class AtomicNullableLazyVal(lock: Any? = null, private val initializer: () -> T?) { - private val lock = lock ?: this - private volatile var value: Any? = null - - public open fun get(thisRef: Any?, desc: PropertyMetadata): T? { - val _v1 = value - if (_v1 != null) { - return unescape(_v1) - } - - return synchronized(lock) { - val _v2 = value - if (_v2 != null) { - unescape(_v2) - } - else { - val typedValue = initializer() - value = escape(typedValue) - typedValue - } - } - } -} \ No newline at end of file diff --git a/libraries/stdlib/test/properties/delegation/DelegationTest.kt b/libraries/stdlib/test/properties/delegation/DelegationTest.kt index cceeeaf6af1..4098956d993 100644 --- a/libraries/stdlib/test/properties/delegation/DelegationTest.kt +++ b/libraries/stdlib/test/properties/delegation/DelegationTest.kt @@ -3,8 +3,6 @@ package test.properties.delegation import junit.framework.TestCase import kotlin.test.* import kotlin.properties.* -import kotlin.properties.delegation.* -import kotlin.properties.delegation.lazy.* trait WithBox { fun box(): String @@ -27,8 +25,8 @@ class DelegationTest(): DelegationTestBase() { } public class TestNotNullVar(val a1: String, val b1: T): WithBox { - var a: String by NotNullVar() - var b by NotNullVar() + var a: String by Delegates.notNull() + var b by Delegates.notNull() override fun box(): String { a = a1 @@ -61,4 +59,4 @@ class TestObservableProperty: WithBox, ChangeSupport() { if (!result) return "fail: result should be true" return "OK" } -} \ No newline at end of file +} diff --git a/libraries/stdlib/test/properties/delegation/MapDelegationTest.kt b/libraries/stdlib/test/properties/delegation/MapDelegationTest.kt index 9bc21c81c20..b6df3fc21fb 100644 --- a/libraries/stdlib/test/properties/delegation/MapDelegationTest.kt +++ b/libraries/stdlib/test/properties/delegation/MapDelegationTest.kt @@ -1,7 +1,7 @@ package test.properties.delegation import java.util.HashMap -import kotlin.properties.delegation.* +import kotlin.properties.* class MapDelegationTest(): DelegationTestBase() { @@ -48,10 +48,10 @@ class MapDelegationTest(): DelegationTestBase() { class TestMapValWithDifferentTypes(): WithBox { val map = hashMapOf("a" to "a", "b" to 1, "c" to A(1), "d" to null) - val a by map.readOnlyProperty() - val b by map.readOnlyProperty() - val c by map.readOnlyProperty() - val d by map.readOnlyProperty() + val a by Delegates.mapVal(map) + val b by Delegates.mapVal(map) + val c by Delegates.mapVal(map) + val d by Delegates.mapVal(map) override fun box(): String { if (a != "a") return "fail at 'a'" @@ -66,10 +66,10 @@ class TestMapValWithDifferentTypes(): WithBox { class TestMapVarWithDifferentTypes(): WithBox { val map: HashMap = hashMapOf("a" to "a", "b" to 1, "c" to A(1), "d" to "d") - var a by map.property() - var b by map.property() - var c by map.property() - var d by map.property() + var a by Delegates.mapVar(map) + var b by Delegates.mapVar(map) + var c by Delegates.mapVar(map) + var d by Delegates.mapVar(map) override fun box(): String { a = "aa" @@ -87,8 +87,8 @@ class TestMapVarWithDifferentTypes(): WithBox { } class TestNullableKey: WithBox { - val map = hashMapOf(null to "null") - var a by map.property { desc -> null } + val map = hashMapOf(null:Any? to "null": Any?) + var a by FixedMapVar(map, key = { desc -> null }, default = {ref, desc -> null}) override fun box(): String { if (a != "null") return "fail at 'a'" @@ -99,10 +99,10 @@ class TestNullableKey: WithBox { } class TestMapPropertyString(): WithBox { - val map = hashMapOf("a" to "a", "b" to "b", "c" to "c") - val a by map.readOnlyProperty() - var b by map.property() - val c by map.property() + val map = hashMapOf("a" to "a", "b" to "b", "c" to "c":Any?) + val a by Delegates.mapVal(map) + var b by Delegates.mapVar(map) + val c by Delegates.mapVal(map) override fun box(): String { b = "newB" @@ -115,9 +115,9 @@ class TestMapPropertyString(): WithBox { class TestMapValWithDefault(): WithBox { val map = hashMapOf() - val a by map.readOnlyProperty(default = { "aDefault" }) - val b by map.readOnlyProperty(default = { "bDefault" }, key = "b") - val c by map.readOnlyProperty(default = { "cDefault" }, key = { desc -> desc.name }) + val a by Delegates.mapVal(map, default = { ref, desc -> "aDefault" }) + val b by FixedMapVal(map, default = { ref, desc -> "bDefault" }, key = {"b"}) + val c by FixedMapVal(map, default = { ref, desc -> "cDefault" }, key = { desc -> desc.name }) override fun box(): String { if (a != "aDefault") return "fail at 'a'" @@ -128,10 +128,10 @@ class TestMapValWithDefault(): WithBox { } class TestMapVarWithDefault(): WithBox { - val map = hashMapOf() - var a by map.property(default = { "aDefault" }) - var b by map.property(default = { "bDefault" }, key = "b") - var c by map.property(default = { "cDefault" }, key = { desc -> desc.name }) + val map = hashMapOf() + var a: String by Delegates.mapVar(map, default = {ref, desc -> "aDefault" }) + var b: String by FixedMapVar(map, default = {ref, desc -> "bDefault" }, key = {"b"}) + var c: String by FixedMapVar(map, default = {ref, desc -> "cDefault" }, key = { desc -> desc.name }) override fun box(): String { if (a != "aDefault") return "fail at 'a'" @@ -148,9 +148,9 @@ class TestMapVarWithDefault(): WithBox { } class TestMapPropertyKey(): WithBox { - val map = hashMapOf("a" to "a", "b" to "b") - val a by map.readOnlyProperty(key = "a") - var b by map.property(key = "b") + val map = hashMapOf("a" to "a", "b" to "b" : Any?) + val a by FixedMapVal(map, key = {"a"}) + var b by FixedMapVar(map, key = {"b"}) override fun box(): String { b = "c" @@ -161,9 +161,9 @@ class TestMapPropertyKey(): WithBox { } class TestMapPropertyFunction(): WithBox { - val map = hashMapOf("aDesc" to "a", "bDesc" to "b") - val a by map.readOnlyProperty { desc -> "${desc.name}Desc" } - var b by map.property { desc -> "${desc.name}Desc" } + val map = hashMapOf("aDesc" to "a", "bDesc" to "b": Any?) + val a by FixedMapVal(map, { desc -> "${desc.name}Desc" }) + var b by FixedMapVar(map, { desc -> "${desc.name}Desc" }) override fun box(): String { b = "c" @@ -173,17 +173,18 @@ class TestMapPropertyFunction(): WithBox { } } -val mapVal = object : MapVal() { - override fun getMap(thisRef: TestMapPropertyCustom) = thisRef.map - override fun getKey(desc: PropertyMetadata) = "${desc.name}Desc" +val mapVal = object: MapVal() { + override fun map(ref: TestMapPropertyCustom) = ref.map + override fun key(desc: PropertyMetadata) = "${desc.name}Desc" } -val mapVar = object : MapVar() { - override fun getMap(thisRef: TestMapPropertyCustom) = thisRef.map - override fun getKey(desc: PropertyMetadata) = "${desc.name}Desc" + +val mapVar = object : MapVar() { + override fun map(ref: TestMapPropertyCustom) = ref.map + override fun key(desc: PropertyMetadata) = "${desc.name}Desc" } class TestMapPropertyCustom(): WithBox { - val map = hashMapOf("aDesc" to "a", "bDesc" to "b") + val map = hashMapOf("aDesc" to "a", "bDesc" to "b":Any?) val a by mapVal var b by mapVar @@ -195,22 +196,22 @@ class TestMapPropertyCustom(): WithBox { } } -val mapValWithDefault = object : MapVal() { - override fun getMap(thisRef: TestMapPropertyCustomWithDefault) = thisRef.map - override fun getKey(desc: PropertyMetadata) = desc.name +val mapValWithDefault = object : MapVal() { + override fun map(ref: TestMapPropertyCustomWithDefault) = ref.map + override fun key(desc: PropertyMetadata) = desc.name - override fun getDefaultValue(desc: PropertyMetadata, key: Any?) = "default" + override fun default(ref: TestMapPropertyCustomWithDefault, key: PropertyMetadata) = "default" } -val mapVarWithDefault = object : MapVar() { - override fun getMap(thisRef: TestMapPropertyCustomWithDefault) = thisRef.map - override fun getKey(desc: PropertyMetadata) = desc.name +val mapVarWithDefault = object : MapVar() { + override fun map(ref: TestMapPropertyCustomWithDefault) = ref.map + override fun key(desc: PropertyMetadata) = desc.name - override fun getDefaultValue(desc: PropertyMetadata, key: Any?) = "default" + override fun default(ref: TestMapPropertyCustomWithDefault, key: PropertyMetadata) = "default" } class TestMapPropertyCustomWithDefault(): WithBox { - val map = hashMapOf() + val map = hashMapOf() val a by mapValWithDefault var b by mapVarWithDefault @@ -221,4 +222,4 @@ class TestMapPropertyCustomWithDefault(): WithBox { if (b != "c") return "fail at 'b' after set" return "OK" } -} \ No newline at end of file +} diff --git a/libraries/stdlib/test/properties/delegation/lazy/LazyValuesTest.kt b/libraries/stdlib/test/properties/delegation/lazy/LazyValuesTest.kt index 6a3a4cac847..31fe609bf2d 100644 --- a/libraries/stdlib/test/properties/delegation/lazy/LazyValuesTest.kt +++ b/libraries/stdlib/test/properties/delegation/lazy/LazyValuesTest.kt @@ -1,8 +1,8 @@ package test.properties.delegation.lazy -import kotlin.properties.delegation.lazy.* import test.properties.delegation.WithBox import test.properties.delegation.DelegationTestBase +import kotlin.properties.* class LazyValuesTest(): DelegationTestBase() { @@ -33,7 +33,7 @@ class LazyValuesTest(): DelegationTestBase() { class TestLazyVal: WithBox { var result = 0 - val a by LazyVal { + val a by Delegates.lazy { ++result } @@ -48,8 +48,8 @@ class TestNullableLazyVal: WithBox { var resultA = 0 var resultB = 0 - val a: Int? by NullableLazyVal { resultA++; null} - val b by NullableLazyVal { foo() } + val a: Int? by Delegates.lazy { resultA++; null} + val b by Delegates.lazy { foo() } override fun box(): String { a @@ -70,7 +70,7 @@ class TestNullableLazyVal: WithBox { class TestAtomicLazyVal: WithBox { var result = 0 - val a by AtomicLazyVal { + val a by Delegates.blockingLazy { ++result } @@ -85,8 +85,8 @@ class TestVolatileNullableLazyVal: WithBox { var resultA = 0 var resultB = 0 - val a: Int? by VolatileNullableLazyVal { resultA++; null} - val b by VolatileNullableLazyVal { foo() } + val a: Int? by Delegates.blockingLazy { resultA++; null} + val b by Delegates.blockingLazy { foo() } override fun box(): String { a @@ -107,7 +107,7 @@ class TestVolatileNullableLazyVal: WithBox { class TestVolatileLazyVal: WithBox { var result = 0 - val a by VolatileLazyVal { + val a by Delegates.blockingLazy { ++result } @@ -122,8 +122,8 @@ class TestAtomicNullableLazyVal: WithBox { var resultA = 0 var resultB = 0 - val a: Int? by AtomicNullableLazyVal { resultA++; null} - val b by AtomicNullableLazyVal { foo() } + val a: Int? by Delegates.blockingLazy { resultA++; null} + val b by Delegates.blockingLazy { foo() } override fun box(): String { a