Override toString function in stdlib delegates
Co-authored-by: ilya-g <ilya.gorbunov@jetbrains.com>
This commit is contained in:
committed by
Space Team
parent
cfa06dbf74
commit
fb80c0cb0d
@@ -23,4 +23,7 @@ private class ThreadLocalDelegate<T>(private val initializer: () -> T) : ReadWri
|
||||
override operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
|
||||
map[Thread.currentThread()] = value
|
||||
}
|
||||
|
||||
override fun toString(): String =
|
||||
"ThreadLocalDelegate(${map.entries.joinToString { "#${it.key.id}=>${it.value}" }})"
|
||||
}
|
||||
@@ -16,6 +16,8 @@ public abstract class ObservableProperty<V> : kotlin.properties.ReadWritePropert
|
||||
public open override operator fun getValue(thisRef: kotlin.Any?, property: kotlin.reflect.KProperty<*>): V
|
||||
|
||||
public open override operator fun setValue(thisRef: kotlin.Any?, property: kotlin.reflect.KProperty<*>, value: V): kotlin.Unit
|
||||
|
||||
public open override fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
@kotlin.SinceKotlin(version = "1.4")
|
||||
|
||||
@@ -16,6 +16,8 @@ public abstract class ObservableProperty<V> : kotlin.properties.ReadWritePropert
|
||||
public open override operator fun getValue(thisRef: kotlin.Any?, property: kotlin.reflect.KProperty<*>): V
|
||||
|
||||
public open override operator fun setValue(thisRef: kotlin.Any?, property: kotlin.reflect.KProperty<*>, value: V): kotlin.Unit
|
||||
|
||||
public open override fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
@kotlin.SinceKotlin(version = "1.4")
|
||||
|
||||
@@ -65,5 +65,8 @@ private class NotNullVar<T : Any>() : ReadWriteProperty<Any?, T> {
|
||||
public override fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
|
||||
this.value = value
|
||||
}
|
||||
|
||||
public override fun toString(): String =
|
||||
"NotNullProperty(${if (value != null) "value=$value" else "value not initialized yet"})"
|
||||
}
|
||||
|
||||
|
||||
@@ -40,4 +40,6 @@ public abstract class ObservableProperty<V>(initialValue: V) : ReadWriteProperty
|
||||
this.value = value
|
||||
afterChange(property, oldValue, value)
|
||||
}
|
||||
|
||||
override fun toString(): String = "ObservableProperty(value=$value)"
|
||||
}
|
||||
@@ -16,30 +16,36 @@ class NotNullVarTest() {
|
||||
|
||||
private class NotNullVarTestGeneric<T : Any>(val a1: String, val b1: T) {
|
||||
var a: String by Delegates.notNull()
|
||||
var b by Delegates.notNull<T>()
|
||||
val bDelegate = Delegates.notNull<T>()
|
||||
var b by bDelegate
|
||||
|
||||
public fun doTest() {
|
||||
assertEquals("NotNullProperty(value not initialized yet)", bDelegate.toString())
|
||||
a = a1
|
||||
b = b1
|
||||
assertTrue(a == "a", "fail: a should be a, but was $a")
|
||||
assertTrue(b == "b", "fail: b should be b, but was $b")
|
||||
assertEquals("NotNullProperty(value=$b)", bDelegate.toString())
|
||||
}
|
||||
}
|
||||
|
||||
class ObservablePropertyTest {
|
||||
var result = false
|
||||
|
||||
var b: Int by Delegates.observable(1, { property, old, new ->
|
||||
val bDelegate = Delegates.observable(1) { property, old, new ->
|
||||
assertEquals("b", property.name)
|
||||
if (!result) assertEquals(1, old)
|
||||
result = true
|
||||
assertEquals(new, b, "New value has already been set")
|
||||
})
|
||||
}
|
||||
|
||||
var b: Int by bDelegate
|
||||
|
||||
@Test fun doTest() {
|
||||
b = 4
|
||||
assertTrue(b == 4, "fail: b != 4")
|
||||
assertTrue(result, "fail: result should be true")
|
||||
assertEquals("ObservableProperty(value=$b)", bDelegate.toString())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -4426,6 +4426,7 @@ public abstract class kotlin/properties/ObservableProperty : kotlin/properties/R
|
||||
protected fun beforeChange (Lkotlin/reflect/KProperty;Ljava/lang/Object;Ljava/lang/Object;)Z
|
||||
public fun getValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;)Ljava/lang/Object;
|
||||
public fun setValue (Ljava/lang/Object;Lkotlin/reflect/KProperty;Ljava/lang/Object;)V
|
||||
public fun toString ()Ljava/lang/String;
|
||||
}
|
||||
|
||||
public abstract interface class kotlin/properties/PropertyDelegateProvider {
|
||||
|
||||
Reference in New Issue
Block a user