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
@@ -79,11 +79,11 @@ public object Delegates {
private class NotNullVar<T: Any>() : ReadWriteProperty<Any?, T> {
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 get(thisRef: Any?, property: PropertyMetadata): T {
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
}
}
@@ -99,12 +99,12 @@ public class ObservableProperty<T>(
) : ReadWriteProperty<Any?, T> {
private var value = initialValue
public override fun get(thisRef: Any?, desc: PropertyMetadata): T {
public override fun get(thisRef: Any?, property: PropertyMetadata): T {
return value
}
public override fun set(thisRef: Any?, desc: PropertyMetadata, value: T) {
if (onChange(desc, this.value, value)) {
public override fun set(thisRef: Any?, property: PropertyMetadata, value: T) {
if (onChange(property, 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 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) {
value = escape(initializer())
}
@@ -135,7 +135,7 @@ private class BlockingLazyVal<T>(lock: Any?, private val initializer: () -> T) :
private val lock = lock ?: this
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
if (_v1 != null) {
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.
* @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 {
throw KeyMissingException("Key $desc is missing in $ref")
protected open fun default(ref: T, property: PropertyMetadata): V {
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 key = key(desc)
val key = key(property)
if (!map.containsKey(key)) {
return default(thisRef, desc)
return default(thisRef, property)
}
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> {
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)
map.put(key(desc), value)
map.put(key(property), value)
}
}
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
@@ -236,8 +236,8 @@ public open class FixedMapVal<T, K, out V>(private val map: Map<in K, Any?>,
return (key)(desc)
}
protected override fun default(ref: T, desc: PropertyMetadata): V {
return (default)(ref, key(desc))
protected override fun default(ref: T, property: PropertyMetadata): V {
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)
}
protected override fun default(ref: T, desc: PropertyMetadata): V {
return (default)(ref, key(desc))
protected override fun default(ref: T, property: PropertyMetadata): V {
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.
* @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.
*/
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.
* @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.
*/
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.
* @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.
*/
public fun set(thisRef: R, desc: PropertyMetadata, value: T)
public fun set(thisRef: R, property: PropertyMetadata, value: T)
}