Refactor: rename PropertyMetadata parameter from 'desc' to 'property'.

Correct test data after parameter has been renamed.
This commit is contained in:
Ilya Gorbunov
2015-06-10 22:31:27 +03:00
parent 6b747cf6f8
commit f2788d53c0
4 changed files with 29 additions and 29 deletions
@@ -1,5 +1,5 @@
// "Create class 'Foo'" "true" // "Create class 'Foo'" "true"
// ERROR: <html>Class 'Foo' must be declared abstract or implement abstract member<br/><b>public</b> <b>abstract</b> <b>fun</b> get(thisRef: A&lt;T&gt;, desc: kotlin.PropertyMetadata): B <i>defined in</i> kotlin.properties.ReadOnlyProperty</html> // ERROR: <html>Class 'Foo' must be declared abstract or implement abstract member<br/><b>public</b> <b>abstract</b> <b>fun</b> get(thisRef: A&lt;T&gt;, property: kotlin.PropertyMetadata): B <i>defined in</i> kotlin.properties.ReadOnlyProperty</html>
open class B open class B
@@ -1,7 +1,7 @@
import kotlin.properties.ReadOnlyProperty import kotlin.properties.ReadOnlyProperty
// "Create class 'Foo'" "true" // "Create class 'Foo'" "true"
// ERROR: <html>Class 'Foo' must be declared abstract or implement abstract member<br/><b>public</b> <b>abstract</b> <b>fun</b> get(thisRef: A&lt;T&gt;, desc: kotlin.PropertyMetadata): B <i>defined in</i> kotlin.properties.ReadOnlyProperty</html> // ERROR: <html>Class 'Foo' must be declared abstract or implement abstract member<br/><b>public</b> <b>abstract</b> <b>fun</b> get(thisRef: A&lt;T&gt;, property: kotlin.PropertyMetadata): B <i>defined in</i> kotlin.properties.ReadOnlyProperty</html>
open class B open class B
@@ -79,11 +79,11 @@ public object Delegates {
private class NotNullVar<T: Any>() : ReadWriteProperty<Any?, T> { private class NotNullVar<T: Any>() : ReadWriteProperty<Any?, T> {
private var value: T? = null private var value: T? = null
public override fun get(thisRef: Any?, desc: PropertyMetadata): T { public override fun get(thisRef: Any?, property: PropertyMetadata): T {
return value ?: throw IllegalStateException("Property ${desc.name} should be initialized before get") return value ?: throw IllegalStateException("Property ${property.name} should be initialized before get.")
} }
public override fun set(thisRef: Any?, desc: PropertyMetadata, value: T) { public override fun set(thisRef: Any?, property: PropertyMetadata, value: T) {
this.value = value this.value = value
} }
} }
@@ -99,12 +99,12 @@ public class ObservableProperty<T>(
) : ReadWriteProperty<Any?, T> { ) : ReadWriteProperty<Any?, T> {
private var value = initialValue private var value = initialValue
public override fun get(thisRef: Any?, desc: PropertyMetadata): T { public override fun get(thisRef: Any?, property: PropertyMetadata): T {
return value return value
} }
public override fun set(thisRef: Any?, desc: PropertyMetadata, value: T) { public override fun set(thisRef: Any?, property: PropertyMetadata, value: T) {
if (onChange(desc, this.value, value)) { if (onChange(property, this.value, value)) {
this.value = value this.value = value
} }
} }
@@ -123,7 +123,7 @@ private fun unescape(value: Any?): Any? {
private class LazyVal<T>(private val initializer: () -> T) : ReadOnlyProperty<Any?, T> { private class LazyVal<T>(private val initializer: () -> T) : ReadOnlyProperty<Any?, T> {
private var value: Any? = null private var value: Any? = null
public override fun get(thisRef: Any?, desc: PropertyMetadata): T { public override fun get(thisRef: Any?, property: PropertyMetadata): T {
if (value == null) { if (value == null) {
value = escape(initializer()) value = escape(initializer())
} }
@@ -135,7 +135,7 @@ private class BlockingLazyVal<T>(lock: Any?, private val initializer: () -> T) :
private val lock = lock ?: this private val lock = lock ?: this
private volatile var value: Any? = null private volatile var value: Any? = null
public override fun get(thisRef: Any?, desc: PropertyMetadata): T { public override fun get(thisRef: Any?, property: PropertyMetadata): T {
val _v1 = value val _v1 = value
if (_v1 != null) { if (_v1 != null) {
return unescape(_v1) as T return unescape(_v1) as T
@@ -183,17 +183,17 @@ public abstract class MapVal<T, K, out V>() : ReadOnlyProperty<T, V> {
/** /**
* Returns the property value to be used when the map does not contain the corresponding key. * Returns the property value to be used when the map does not contain the corresponding key.
* @param ref the object instance for which the value was requested. * @param ref the object instance for which the value was requested.
* @param desc the property for which the value was requested. * @param property the property for which the value was requested.
*/ */
protected open fun default(ref: T, desc: PropertyMetadata): V { protected open fun default(ref: T, property: PropertyMetadata): V {
throw KeyMissingException("Key $desc is missing in $ref") throw KeyMissingException("The value for property ${property.name} is missing in $ref.")
} }
public override fun get(thisRef: T, desc: PropertyMetadata) : V { public override fun get(thisRef: T, property: PropertyMetadata) : V {
val map = map(thisRef) val map = map(thisRef)
val key = key(desc) val key = key(property)
if (!map.containsKey(key)) { if (!map.containsKey(key)) {
return default(thisRef, desc) return default(thisRef, property)
} }
return map[key] as V return map[key] as V
@@ -209,14 +209,14 @@ public abstract class MapVal<T, K, out V>() : ReadOnlyProperty<T, V> {
public abstract class MapVar<T, K, V>() : MapVal<T, K, V>(), ReadWriteProperty<T, V> { public abstract class MapVar<T, K, V>() : MapVal<T, K, V>(), ReadWriteProperty<T, V> {
protected abstract override fun map(ref: T): MutableMap<in K, Any?> protected abstract override fun map(ref: T): MutableMap<in K, Any?>
public override fun set(thisRef: T, desc: PropertyMetadata, value: V) { public override fun set(thisRef: T, property: PropertyMetadata, value: V) {
val map = map(thisRef) val map = map(thisRef)
map.put(key(desc), value) map.put(key(property), value)
} }
} }
private val defaultKeyProvider:(PropertyMetadata) -> String = {it.name} private val defaultKeyProvider:(PropertyMetadata) -> String = {it.name}
private val defaultValueProvider:(Any?, Any?) -> Nothing = {thisRef, key -> throw KeyMissingException("$key is missing from $thisRef")} private val defaultValueProvider:(Any?, Any?) -> Nothing = {thisRef, key -> throw KeyMissingException("The value for key $key is missing from $thisRef.")}
/** /**
* Implements a read-only property delegate that stores the property values in a given map instance and uses the given * Implements a read-only property delegate that stores the property values in a given map instance and uses the given
@@ -236,8 +236,8 @@ public open class FixedMapVal<T, K, out V>(private val map: Map<in K, Any?>,
return (key)(desc) return (key)(desc)
} }
protected override fun default(ref: T, desc: PropertyMetadata): V { protected override fun default(ref: T, property: PropertyMetadata): V {
return (default)(ref, key(desc)) return (default)(ref, key(property))
} }
} }
@@ -259,7 +259,7 @@ public open class FixedMapVar<T, K, V>(private val map: MutableMap<in K, Any?>,
return (key)(desc) return (key)(desc)
} }
protected override fun default(ref: T, desc: PropertyMetadata): V { protected override fun default(ref: T, property: PropertyMetadata): V {
return (default)(ref, key(desc)) return (default)(ref, key(property))
} }
} }
@@ -14,10 +14,10 @@ public interface ReadOnlyProperty<in R, out T> {
/** /**
* Returns the value of the property for the given object. * Returns the value of the property for the given object.
* @param thisRef the object for which the value is requested. * @param thisRef the object for which the value is requested.
* @param desc the metadata for the property. * @param property the metadata for the property.
* @return the property value. * @return the property value.
*/ */
public fun get(thisRef: R, desc: PropertyMetadata): T public fun get(thisRef: R, property: PropertyMetadata): T
} }
/** /**
@@ -33,16 +33,16 @@ public interface ReadWriteProperty<in R, T> {
/** /**
* Returns the value of the property for the given object. * Returns the value of the property for the given object.
* @param thisRef the object for which the value is requested. * @param thisRef the object for which the value is requested.
* @param desc the metadata for the property. * @param property the metadata for the property.
* @return the property value. * @return the property value.
*/ */
public fun get(thisRef: R, desc: PropertyMetadata): T public fun get(thisRef: R, property: PropertyMetadata): T
/** /**
* Sets the value of the property for the given object. * Sets the value of the property for the given object.
* @param thisRef the object for which the value is requested. * @param thisRef the object for which the value is requested.
* @param desc the metadata for the property. * @param property the metadata for the property.
* @param value the value to set. * @param value the value to set.
*/ */
public fun set(thisRef: R, desc: PropertyMetadata, value: T) public fun set(thisRef: R, property: PropertyMetadata, value: T)
} }