mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-27 17:00:14 +08:00
Fix initialization of primitive values
This commit is contained in:
parent
e0f535e937
commit
71b1464e25
@ -74,10 +74,14 @@ internal abstract class ${ktType.standardName}ValueImpl : ${ktType.standardName}
|
|||||||
get() = _value ?: error("${ktType.standardName}Value.value should be initialized before get.")
|
get() = _value ?: error("${ktType.standardName}Value.value should be initialized before get.")
|
||||||
set(v) {
|
set(v) {
|
||||||
if (v != this._value) {
|
if (v != this._value) {
|
||||||
|
if (this._value == null) {
|
||||||
|
this._value = v
|
||||||
|
} else {
|
||||||
this._value = v
|
this._value = v
|
||||||
onChanged()
|
onChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun onChanged()
|
protected abstract fun onChanged()
|
||||||
|
|
||||||
|
@ -42,10 +42,14 @@ internal abstract class ByteValueImpl : ByteValue, SerializerAwareValue<Byte>, K
|
|||||||
get() = _value ?: error("ByteValue.value should be initialized before get.")
|
get() = _value ?: error("ByteValue.value should be initialized before get.")
|
||||||
set(v) {
|
set(v) {
|
||||||
if (v != this._value) {
|
if (v != this._value) {
|
||||||
|
if (this._value == null) {
|
||||||
|
this._value = v
|
||||||
|
} else {
|
||||||
this._value = v
|
this._value = v
|
||||||
onChanged()
|
onChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun onChanged()
|
protected abstract fun onChanged()
|
||||||
|
|
||||||
@ -77,10 +81,14 @@ internal abstract class ShortValueImpl : ShortValue, SerializerAwareValue<Short>
|
|||||||
get() = _value ?: error("ShortValue.value should be initialized before get.")
|
get() = _value ?: error("ShortValue.value should be initialized before get.")
|
||||||
set(v) {
|
set(v) {
|
||||||
if (v != this._value) {
|
if (v != this._value) {
|
||||||
|
if (this._value == null) {
|
||||||
|
this._value = v
|
||||||
|
} else {
|
||||||
this._value = v
|
this._value = v
|
||||||
onChanged()
|
onChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun onChanged()
|
protected abstract fun onChanged()
|
||||||
|
|
||||||
@ -110,10 +118,14 @@ internal abstract class IntValueImpl : IntValue, SerializerAwareValue<Int>, KSer
|
|||||||
get() = _value ?: error("IntValue.value should be initialized before get.")
|
get() = _value ?: error("IntValue.value should be initialized before get.")
|
||||||
set(v) {
|
set(v) {
|
||||||
if (v != this._value) {
|
if (v != this._value) {
|
||||||
|
if (this._value == null) {
|
||||||
|
this._value = v
|
||||||
|
} else {
|
||||||
this._value = v
|
this._value = v
|
||||||
onChanged()
|
onChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun onChanged()
|
protected abstract fun onChanged()
|
||||||
|
|
||||||
@ -145,10 +157,14 @@ internal abstract class LongValueImpl : LongValue, SerializerAwareValue<Long>, K
|
|||||||
get() = _value ?: error("LongValue.value should be initialized before get.")
|
get() = _value ?: error("LongValue.value should be initialized before get.")
|
||||||
set(v) {
|
set(v) {
|
||||||
if (v != this._value) {
|
if (v != this._value) {
|
||||||
|
if (this._value == null) {
|
||||||
|
this._value = v
|
||||||
|
} else {
|
||||||
this._value = v
|
this._value = v
|
||||||
onChanged()
|
onChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun onChanged()
|
protected abstract fun onChanged()
|
||||||
|
|
||||||
@ -180,10 +196,14 @@ internal abstract class FloatValueImpl : FloatValue, SerializerAwareValue<Float>
|
|||||||
get() = _value ?: error("FloatValue.value should be initialized before get.")
|
get() = _value ?: error("FloatValue.value should be initialized before get.")
|
||||||
set(v) {
|
set(v) {
|
||||||
if (v != this._value) {
|
if (v != this._value) {
|
||||||
|
if (this._value == null) {
|
||||||
|
this._value = v
|
||||||
|
} else {
|
||||||
this._value = v
|
this._value = v
|
||||||
onChanged()
|
onChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun onChanged()
|
protected abstract fun onChanged()
|
||||||
|
|
||||||
@ -215,10 +235,14 @@ internal abstract class DoubleValueImpl : DoubleValue, SerializerAwareValue<Doub
|
|||||||
get() = _value ?: error("DoubleValue.value should be initialized before get.")
|
get() = _value ?: error("DoubleValue.value should be initialized before get.")
|
||||||
set(v) {
|
set(v) {
|
||||||
if (v != this._value) {
|
if (v != this._value) {
|
||||||
|
if (this._value == null) {
|
||||||
|
this._value = v
|
||||||
|
} else {
|
||||||
this._value = v
|
this._value = v
|
||||||
onChanged()
|
onChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun onChanged()
|
protected abstract fun onChanged()
|
||||||
|
|
||||||
@ -250,10 +274,14 @@ internal abstract class CharValueImpl : CharValue, SerializerAwareValue<Char>, K
|
|||||||
get() = _value ?: error("CharValue.value should be initialized before get.")
|
get() = _value ?: error("CharValue.value should be initialized before get.")
|
||||||
set(v) {
|
set(v) {
|
||||||
if (v != this._value) {
|
if (v != this._value) {
|
||||||
|
if (this._value == null) {
|
||||||
|
this._value = v
|
||||||
|
} else {
|
||||||
this._value = v
|
this._value = v
|
||||||
onChanged()
|
onChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun onChanged()
|
protected abstract fun onChanged()
|
||||||
|
|
||||||
@ -285,10 +313,14 @@ internal abstract class BooleanValueImpl : BooleanValue, SerializerAwareValue<Bo
|
|||||||
get() = _value ?: error("BooleanValue.value should be initialized before get.")
|
get() = _value ?: error("BooleanValue.value should be initialized before get.")
|
||||||
set(v) {
|
set(v) {
|
||||||
if (v != this._value) {
|
if (v != this._value) {
|
||||||
|
if (this._value == null) {
|
||||||
|
this._value = v
|
||||||
|
} else {
|
||||||
this._value = v
|
this._value = v
|
||||||
onChanged()
|
onChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun onChanged()
|
protected abstract fun onChanged()
|
||||||
|
|
||||||
@ -320,10 +352,14 @@ internal abstract class StringValueImpl : StringValue, SerializerAwareValue<Stri
|
|||||||
get() = _value ?: error("StringValue.value should be initialized before get.")
|
get() = _value ?: error("StringValue.value should be initialized before get.")
|
||||||
set(v) {
|
set(v) {
|
||||||
if (v != this._value) {
|
if (v != this._value) {
|
||||||
|
if (this._value == null) {
|
||||||
|
this._value = v
|
||||||
|
} else {
|
||||||
this._value = v
|
this._value = v
|
||||||
onChanged()
|
onChanged()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected abstract fun onChanged()
|
protected abstract fun onChanged()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user