Improve codegen

This commit is contained in:
Him188 2020-05-17 15:47:41 +08:00
parent e1f2b2e947
commit 3c36bb7660
4 changed files with 110 additions and 72 deletions

View File

@ -57,11 +57,13 @@ fun genAllValueImpl(): String = buildString {
// PRIMITIVE // PRIMITIVE
for (number in NUMBERS + OTHER_PRIMITIVES) { for (number in NUMBERS + OTHER_PRIMITIVES) {
appendln(genValueImpl(number, number, "$number.serializer()", false)) appendln(genValueImpl(number, number, "$number.serializer()", false))
appendln()
} }
// PRIMITIVE ARRAYS // PRIMITIVE ARRAYS
for (number in NUMBERS + OTHER_PRIMITIVES.filterNot { it == "String" }) { for (number in NUMBERS + OTHER_PRIMITIVES.filterNot { it == "String" }) {
appendln(genValueImpl("${number}Array", "${number}Array", "${number}ArraySerializer()", true)) appendln(genValueImpl("${number}Array", "${number}Array", "${number}ArraySerializer()", true))
appendln()
} }
// TYPED ARRAYS // TYPED ARRAYS
@ -74,6 +76,7 @@ fun genAllValueImpl(): String = buildString {
true true
) )
) )
appendln()
} }
// PRIMITIVE LISTS / SETS // PRIMITIVE LISTS / SETS
@ -87,6 +90,7 @@ fun genAllValueImpl(): String = buildString {
false false
) )
) )
appendln()
} }
} }
@ -137,6 +141,40 @@ fun genAllValueImpl(): String = buildString {
appendln() appendln()
} }
} }
appendln()
appendln(
"""
internal fun <T : Setting> Setting.valueImpl(default: T): Value<T> {
return object : SettingValue<T>() {
private var internalValue: T = default
override var value: T
get() = internalValue
set(new) {
if (new != internalValue) {
internalValue = new
onElementChanged(this)
}
}
override val serializer = object : KSerializer<T>{
override val descriptor: SerialDescriptor
get() = internalValue.updaterSerializer.descriptor
override fun deserialize(decoder: Decoder): T {
internalValue.updaterSerializer.deserialize(decoder)
return internalValue
}
override fun serialize(encoder: Encoder, value: T) {
internalValue.updaterSerializer.serialize(encoder, SettingSerializerMark)
}
}
}
}
"""
)
} }
fun genValueImpl(kotlinTypeName: String, miraiValueName: String, serializer: String, isArray: Boolean): String = fun genValueImpl(kotlinTypeName: String, miraiValueName: String, serializer: String, isArray: Boolean): String =

View File

@ -65,10 +65,7 @@ fun genPublicApi() = buildString {
""" """
package net.mamoe.mirai.console.setting package net.mamoe.mirai.console.setting
import kotlinx.serialization.Decoder
import kotlinx.serialization.Encoder
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialDescriptor
import kotlin.properties.ReadWriteProperty import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
""" """
@ -221,42 +218,11 @@ sealed class Value<T : Any> : ReadWriteProperty<Setting, T> {
appendln() appendln()
} }
// FOR COMPLEX TYPES // SETTING VALUE
appendln( appendln(
""" """
abstract class SettingValue<T : Setting> internal constructor() : Value<T>() abstract class SettingValue<T : Setting> internal constructor() : Value<T>()
internal fun <T : Setting> Setting.valueImpl(default: T): Value<T> {
return object : SettingValue<T>() {
private var internalValue: T = default
override var value: T
get() = internalValue
set(new) {
if (new != internalValue) {
internalValue = new
onElementChanged(this)
}
}
override val serializer = object : KSerializer<T>{
override val descriptor: SerialDescriptor
get() = internalValue.updaterSerializer.descriptor
override fun deserialize(decoder: Decoder): T {
internalValue.updaterSerializer.deserialize(decoder)
return internalValue
}
override fun serialize(encoder: Encoder, value: T) {
internalValue.updaterSerializer.serialize(encoder, SettingSerializerMark)
}
}.bind(
getter = { internalValue },
setter = { internalValue = it }
)
}
}
""" """
) )

View File

@ -9,10 +9,7 @@
package net.mamoe.mirai.console.setting package net.mamoe.mirai.console.setting
import kotlinx.serialization.Decoder
import kotlinx.serialization.Encoder
import kotlinx.serialization.KSerializer import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialDescriptor
import kotlin.properties.ReadWriteProperty import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty import kotlin.reflect.KProperty
@ -65,24 +62,31 @@ sealed class PrimitiveArrayValue<T : Any> : ArrayValue<T>()
abstract class IntArrayValue internal constructor() : PrimitiveArrayValue<IntArray>(), Iterable<Int> { abstract class IntArrayValue internal constructor() : PrimitiveArrayValue<IntArray>(), Iterable<Int> {
override fun iterator(): Iterator<Int> = this.value.iterator() override fun iterator(): Iterator<Int> = this.value.iterator()
} }
abstract class ShortArrayValue internal constructor() : PrimitiveArrayValue<ShortArray>(), Iterable<Short> { abstract class ShortArrayValue internal constructor() : PrimitiveArrayValue<ShortArray>(), Iterable<Short> {
override fun iterator(): Iterator<Short> = this.value.iterator() override fun iterator(): Iterator<Short> = this.value.iterator()
} }
abstract class ByteArrayValue internal constructor() : PrimitiveArrayValue<ByteArray>(), Iterable<Byte> { abstract class ByteArrayValue internal constructor() : PrimitiveArrayValue<ByteArray>(), Iterable<Byte> {
override fun iterator(): Iterator<Byte> = this.value.iterator() override fun iterator(): Iterator<Byte> = this.value.iterator()
} }
abstract class LongArrayValue internal constructor() : PrimitiveArrayValue<LongArray>(), Iterable<Long> { abstract class LongArrayValue internal constructor() : PrimitiveArrayValue<LongArray>(), Iterable<Long> {
override fun iterator(): Iterator<Long> = this.value.iterator() override fun iterator(): Iterator<Long> = this.value.iterator()
} }
abstract class FloatArrayValue internal constructor() : PrimitiveArrayValue<FloatArray>(), Iterable<Float> { abstract class FloatArrayValue internal constructor() : PrimitiveArrayValue<FloatArray>(), Iterable<Float> {
override fun iterator(): Iterator<Float> = this.value.iterator() override fun iterator(): Iterator<Float> = this.value.iterator()
} }
abstract class DoubleArrayValue internal constructor() : PrimitiveArrayValue<DoubleArray>(), Iterable<Double> { abstract class DoubleArrayValue internal constructor() : PrimitiveArrayValue<DoubleArray>(), Iterable<Double> {
override fun iterator(): Iterator<Double> = this.value.iterator() override fun iterator(): Iterator<Double> = this.value.iterator()
} }
abstract class BooleanArrayValue internal constructor() : PrimitiveArrayValue<BooleanArray>(), Iterable<Boolean> { abstract class BooleanArrayValue internal constructor() : PrimitiveArrayValue<BooleanArray>(), Iterable<Boolean> {
override fun iterator(): Iterator<Boolean> = this.value.iterator() override fun iterator(): Iterator<Boolean> = this.value.iterator()
} }
abstract class CharArrayValue internal constructor() : PrimitiveArrayValue<CharArray>(), Iterable<Char> { abstract class CharArrayValue internal constructor() : PrimitiveArrayValue<CharArray>(), Iterable<Char> {
override fun iterator(): Iterator<Char> = this.value.iterator() override fun iterator(): Iterator<Char> = this.value.iterator()
} }
@ -135,37 +139,6 @@ abstract class SettingSetValue<T : Setting> internal constructor() : Value<Set<T
abstract class SettingValue<T : Setting> internal constructor() : Value<T>() abstract class SettingValue<T : Setting> internal constructor() : Value<T>()
internal fun <T : Setting> Setting.valueImpl(default: T): Value<T> {
return object : SettingValue<T>() {
private var internalValue: T = default
override var value: T
get() = internalValue
set(new) {
if (new != internalValue) {
internalValue = new
onElementChanged(this)
}
}
override val serializer = object : KSerializer<T> {
override val descriptor: SerialDescriptor
get() = internalValue.updaterSerializer.descriptor
override fun deserialize(decoder: Decoder): T {
internalValue.updaterSerializer.deserialize(decoder)
return internalValue
}
override fun serialize(encoder: Encoder, value: T) {
internalValue.updaterSerializer.serialize(encoder, SettingSerializerMark)
}
}.bind(
getter = { internalValue },
setter = { internalValue = it }
)
}
}
abstract class MutableListValue<T : Any> internal constructor() : Value<MutableList<Value<T>>>(), MutableList<T> abstract class MutableListValue<T : Any> internal constructor() : Value<MutableList<Value<T>>>(), MutableList<T>
abstract class MutableIntListValue internal constructor() : Value<MutableList<Int>>(), MutableList<Int> abstract class MutableIntListValue internal constructor() : Value<MutableList<Int>>(), MutableList<Int>

View File

@ -1,4 +1,3 @@
/* /*
* Copyright 2020 Mamoe Technologies and contributors. * Copyright 2020 Mamoe Technologies and contributors.
* *
@ -38,6 +37,7 @@ internal fun Setting.valueImpl(default: Int): IntValue {
override val serializer = Int.serializer() override val serializer = Int.serializer()
} }
} }
internal fun Setting.valueImpl(default: Short): ShortValue { internal fun Setting.valueImpl(default: Short): ShortValue {
return object : ShortValue() { return object : ShortValue() {
private var internalValue: Short = default private var internalValue: Short = default
@ -52,6 +52,7 @@ internal fun Setting.valueImpl(default: Short): ShortValue {
override val serializer = Short.serializer() override val serializer = Short.serializer()
} }
} }
internal fun Setting.valueImpl(default: Byte): ByteValue { internal fun Setting.valueImpl(default: Byte): ByteValue {
return object : ByteValue() { return object : ByteValue() {
private var internalValue: Byte = default private var internalValue: Byte = default
@ -66,6 +67,7 @@ internal fun Setting.valueImpl(default: Byte): ByteValue {
override val serializer = Byte.serializer() override val serializer = Byte.serializer()
} }
} }
internal fun Setting.valueImpl(default: Long): LongValue { internal fun Setting.valueImpl(default: Long): LongValue {
return object : LongValue() { return object : LongValue() {
private var internalValue: Long = default private var internalValue: Long = default
@ -80,6 +82,7 @@ internal fun Setting.valueImpl(default: Long): LongValue {
override val serializer = Long.serializer() override val serializer = Long.serializer()
} }
} }
internal fun Setting.valueImpl(default: Float): FloatValue { internal fun Setting.valueImpl(default: Float): FloatValue {
return object : FloatValue() { return object : FloatValue() {
private var internalValue: Float = default private var internalValue: Float = default
@ -94,6 +97,7 @@ internal fun Setting.valueImpl(default: Float): FloatValue {
override val serializer = Float.serializer() override val serializer = Float.serializer()
} }
} }
internal fun Setting.valueImpl(default: Double): DoubleValue { internal fun Setting.valueImpl(default: Double): DoubleValue {
return object : DoubleValue() { return object : DoubleValue() {
private var internalValue: Double = default private var internalValue: Double = default
@ -108,6 +112,7 @@ internal fun Setting.valueImpl(default: Double): DoubleValue {
override val serializer = Double.serializer() override val serializer = Double.serializer()
} }
} }
internal fun Setting.valueImpl(default: Boolean): BooleanValue { internal fun Setting.valueImpl(default: Boolean): BooleanValue {
return object : BooleanValue() { return object : BooleanValue() {
private var internalValue: Boolean = default private var internalValue: Boolean = default
@ -122,6 +127,7 @@ internal fun Setting.valueImpl(default: Boolean): BooleanValue {
override val serializer = Boolean.serializer() override val serializer = Boolean.serializer()
} }
} }
internal fun Setting.valueImpl(default: Char): CharValue { internal fun Setting.valueImpl(default: Char): CharValue {
return object : CharValue() { return object : CharValue() {
private var internalValue: Char = default private var internalValue: Char = default
@ -136,6 +142,7 @@ internal fun Setting.valueImpl(default: Char): CharValue {
override val serializer = Char.serializer() override val serializer = Char.serializer()
} }
} }
internal fun Setting.valueImpl(default: String): StringValue { internal fun Setting.valueImpl(default: String): StringValue {
return object : StringValue() { return object : StringValue() {
private var internalValue: String = default private var internalValue: String = default
@ -150,6 +157,7 @@ internal fun Setting.valueImpl(default: String): StringValue {
override val serializer = String.serializer() override val serializer = String.serializer()
} }
} }
internal fun Setting.valueImpl(default: IntArray): IntArrayValue { internal fun Setting.valueImpl(default: IntArray): IntArrayValue {
return object : IntArrayValue() { return object : IntArrayValue() {
private var internalValue: IntArray = default private var internalValue: IntArray = default
@ -164,6 +172,7 @@ internal fun Setting.valueImpl(default: IntArray): IntArrayValue {
override val serializer = IntArraySerializer() override val serializer = IntArraySerializer()
} }
} }
internal fun Setting.valueImpl(default: ShortArray): ShortArrayValue { internal fun Setting.valueImpl(default: ShortArray): ShortArrayValue {
return object : ShortArrayValue() { return object : ShortArrayValue() {
private var internalValue: ShortArray = default private var internalValue: ShortArray = default
@ -178,6 +187,7 @@ internal fun Setting.valueImpl(default: ShortArray): ShortArrayValue {
override val serializer = ShortArraySerializer() override val serializer = ShortArraySerializer()
} }
} }
internal fun Setting.valueImpl(default: ByteArray): ByteArrayValue { internal fun Setting.valueImpl(default: ByteArray): ByteArrayValue {
return object : ByteArrayValue() { return object : ByteArrayValue() {
private var internalValue: ByteArray = default private var internalValue: ByteArray = default
@ -192,6 +202,7 @@ internal fun Setting.valueImpl(default: ByteArray): ByteArrayValue {
override val serializer = ByteArraySerializer() override val serializer = ByteArraySerializer()
} }
} }
internal fun Setting.valueImpl(default: LongArray): LongArrayValue { internal fun Setting.valueImpl(default: LongArray): LongArrayValue {
return object : LongArrayValue() { return object : LongArrayValue() {
private var internalValue: LongArray = default private var internalValue: LongArray = default
@ -206,6 +217,7 @@ internal fun Setting.valueImpl(default: LongArray): LongArrayValue {
override val serializer = LongArraySerializer() override val serializer = LongArraySerializer()
} }
} }
internal fun Setting.valueImpl(default: FloatArray): FloatArrayValue { internal fun Setting.valueImpl(default: FloatArray): FloatArrayValue {
return object : FloatArrayValue() { return object : FloatArrayValue() {
private var internalValue: FloatArray = default private var internalValue: FloatArray = default
@ -220,6 +232,7 @@ internal fun Setting.valueImpl(default: FloatArray): FloatArrayValue {
override val serializer = FloatArraySerializer() override val serializer = FloatArraySerializer()
} }
} }
internal fun Setting.valueImpl(default: DoubleArray): DoubleArrayValue { internal fun Setting.valueImpl(default: DoubleArray): DoubleArrayValue {
return object : DoubleArrayValue() { return object : DoubleArrayValue() {
private var internalValue: DoubleArray = default private var internalValue: DoubleArray = default
@ -234,6 +247,7 @@ internal fun Setting.valueImpl(default: DoubleArray): DoubleArrayValue {
override val serializer = DoubleArraySerializer() override val serializer = DoubleArraySerializer()
} }
} }
internal fun Setting.valueImpl(default: BooleanArray): BooleanArrayValue { internal fun Setting.valueImpl(default: BooleanArray): BooleanArrayValue {
return object : BooleanArrayValue() { return object : BooleanArrayValue() {
private var internalValue: BooleanArray = default private var internalValue: BooleanArray = default
@ -248,6 +262,7 @@ internal fun Setting.valueImpl(default: BooleanArray): BooleanArrayValue {
override val serializer = BooleanArraySerializer() override val serializer = BooleanArraySerializer()
} }
} }
internal fun Setting.valueImpl(default: CharArray): CharArrayValue { internal fun Setting.valueImpl(default: CharArray): CharArrayValue {
return object : CharArrayValue() { return object : CharArrayValue() {
private var internalValue: CharArray = default private var internalValue: CharArray = default
@ -262,6 +277,7 @@ internal fun Setting.valueImpl(default: CharArray): CharArrayValue {
override val serializer = CharArraySerializer() override val serializer = CharArraySerializer()
} }
} }
internal fun Setting.valueImpl(default: Array<Int>): TypedIntArrayValue { internal fun Setting.valueImpl(default: Array<Int>): TypedIntArrayValue {
return object : TypedIntArrayValue() { return object : TypedIntArrayValue() {
private var internalValue: Array<Int> = default private var internalValue: Array<Int> = default
@ -276,6 +292,7 @@ internal fun Setting.valueImpl(default: Array<Int>): TypedIntArrayValue {
override val serializer = ArraySerializer(Int.serializer()) override val serializer = ArraySerializer(Int.serializer())
} }
} }
internal fun Setting.valueImpl(default: Array<Short>): TypedShortArrayValue { internal fun Setting.valueImpl(default: Array<Short>): TypedShortArrayValue {
return object : TypedShortArrayValue() { return object : TypedShortArrayValue() {
private var internalValue: Array<Short> = default private var internalValue: Array<Short> = default
@ -290,6 +307,7 @@ internal fun Setting.valueImpl(default: Array<Short>): TypedShortArrayValue {
override val serializer = ArraySerializer(Short.serializer()) override val serializer = ArraySerializer(Short.serializer())
} }
} }
internal fun Setting.valueImpl(default: Array<Byte>): TypedByteArrayValue { internal fun Setting.valueImpl(default: Array<Byte>): TypedByteArrayValue {
return object : TypedByteArrayValue() { return object : TypedByteArrayValue() {
private var internalValue: Array<Byte> = default private var internalValue: Array<Byte> = default
@ -304,6 +322,7 @@ internal fun Setting.valueImpl(default: Array<Byte>): TypedByteArrayValue {
override val serializer = ArraySerializer(Byte.serializer()) override val serializer = ArraySerializer(Byte.serializer())
} }
} }
internal fun Setting.valueImpl(default: Array<Long>): TypedLongArrayValue { internal fun Setting.valueImpl(default: Array<Long>): TypedLongArrayValue {
return object : TypedLongArrayValue() { return object : TypedLongArrayValue() {
private var internalValue: Array<Long> = default private var internalValue: Array<Long> = default
@ -318,6 +337,7 @@ internal fun Setting.valueImpl(default: Array<Long>): TypedLongArrayValue {
override val serializer = ArraySerializer(Long.serializer()) override val serializer = ArraySerializer(Long.serializer())
} }
} }
internal fun Setting.valueImpl(default: Array<Float>): TypedFloatArrayValue { internal fun Setting.valueImpl(default: Array<Float>): TypedFloatArrayValue {
return object : TypedFloatArrayValue() { return object : TypedFloatArrayValue() {
private var internalValue: Array<Float> = default private var internalValue: Array<Float> = default
@ -332,6 +352,7 @@ internal fun Setting.valueImpl(default: Array<Float>): TypedFloatArrayValue {
override val serializer = ArraySerializer(Float.serializer()) override val serializer = ArraySerializer(Float.serializer())
} }
} }
internal fun Setting.valueImpl(default: Array<Double>): TypedDoubleArrayValue { internal fun Setting.valueImpl(default: Array<Double>): TypedDoubleArrayValue {
return object : TypedDoubleArrayValue() { return object : TypedDoubleArrayValue() {
private var internalValue: Array<Double> = default private var internalValue: Array<Double> = default
@ -346,6 +367,7 @@ internal fun Setting.valueImpl(default: Array<Double>): TypedDoubleArrayValue {
override val serializer = ArraySerializer(Double.serializer()) override val serializer = ArraySerializer(Double.serializer())
} }
} }
internal fun Setting.valueImpl(default: Array<Boolean>): TypedBooleanArrayValue { internal fun Setting.valueImpl(default: Array<Boolean>): TypedBooleanArrayValue {
return object : TypedBooleanArrayValue() { return object : TypedBooleanArrayValue() {
private var internalValue: Array<Boolean> = default private var internalValue: Array<Boolean> = default
@ -360,6 +382,7 @@ internal fun Setting.valueImpl(default: Array<Boolean>): TypedBooleanArrayValue
override val serializer = ArraySerializer(Boolean.serializer()) override val serializer = ArraySerializer(Boolean.serializer())
} }
} }
internal fun Setting.valueImpl(default: Array<Char>): TypedCharArrayValue { internal fun Setting.valueImpl(default: Array<Char>): TypedCharArrayValue {
return object : TypedCharArrayValue() { return object : TypedCharArrayValue() {
private var internalValue: Array<Char> = default private var internalValue: Array<Char> = default
@ -374,6 +397,7 @@ internal fun Setting.valueImpl(default: Array<Char>): TypedCharArrayValue {
override val serializer = ArraySerializer(Char.serializer()) override val serializer = ArraySerializer(Char.serializer())
} }
} }
internal fun Setting.valueImpl(default: Array<String>): TypedStringArrayValue { internal fun Setting.valueImpl(default: Array<String>): TypedStringArrayValue {
return object : TypedStringArrayValue() { return object : TypedStringArrayValue() {
private var internalValue: Array<String> = default private var internalValue: Array<String> = default
@ -388,6 +412,7 @@ internal fun Setting.valueImpl(default: Array<String>): TypedStringArrayValue {
override val serializer = ArraySerializer(String.serializer()) override val serializer = ArraySerializer(String.serializer())
} }
} }
internal fun Setting.valueImpl(default: List<Int>): IntListValue { internal fun Setting.valueImpl(default: List<Int>): IntListValue {
return object : IntListValue() { return object : IntListValue() {
private var internalValue: List<Int> = default private var internalValue: List<Int> = default
@ -402,6 +427,7 @@ internal fun Setting.valueImpl(default: List<Int>): IntListValue {
override val serializer = ListSerializer(Int.serializer()) override val serializer = ListSerializer(Int.serializer())
} }
} }
internal fun Setting.valueImpl(default: List<Short>): ShortListValue { internal fun Setting.valueImpl(default: List<Short>): ShortListValue {
return object : ShortListValue() { return object : ShortListValue() {
private var internalValue: List<Short> = default private var internalValue: List<Short> = default
@ -416,6 +442,7 @@ internal fun Setting.valueImpl(default: List<Short>): ShortListValue {
override val serializer = ListSerializer(Short.serializer()) override val serializer = ListSerializer(Short.serializer())
} }
} }
internal fun Setting.valueImpl(default: List<Byte>): ByteListValue { internal fun Setting.valueImpl(default: List<Byte>): ByteListValue {
return object : ByteListValue() { return object : ByteListValue() {
private var internalValue: List<Byte> = default private var internalValue: List<Byte> = default
@ -430,6 +457,7 @@ internal fun Setting.valueImpl(default: List<Byte>): ByteListValue {
override val serializer = ListSerializer(Byte.serializer()) override val serializer = ListSerializer(Byte.serializer())
} }
} }
internal fun Setting.valueImpl(default: List<Long>): LongListValue { internal fun Setting.valueImpl(default: List<Long>): LongListValue {
return object : LongListValue() { return object : LongListValue() {
private var internalValue: List<Long> = default private var internalValue: List<Long> = default
@ -444,6 +472,7 @@ internal fun Setting.valueImpl(default: List<Long>): LongListValue {
override val serializer = ListSerializer(Long.serializer()) override val serializer = ListSerializer(Long.serializer())
} }
} }
internal fun Setting.valueImpl(default: List<Float>): FloatListValue { internal fun Setting.valueImpl(default: List<Float>): FloatListValue {
return object : FloatListValue() { return object : FloatListValue() {
private var internalValue: List<Float> = default private var internalValue: List<Float> = default
@ -458,6 +487,7 @@ internal fun Setting.valueImpl(default: List<Float>): FloatListValue {
override val serializer = ListSerializer(Float.serializer()) override val serializer = ListSerializer(Float.serializer())
} }
} }
internal fun Setting.valueImpl(default: List<Double>): DoubleListValue { internal fun Setting.valueImpl(default: List<Double>): DoubleListValue {
return object : DoubleListValue() { return object : DoubleListValue() {
private var internalValue: List<Double> = default private var internalValue: List<Double> = default
@ -472,6 +502,7 @@ internal fun Setting.valueImpl(default: List<Double>): DoubleListValue {
override val serializer = ListSerializer(Double.serializer()) override val serializer = ListSerializer(Double.serializer())
} }
} }
internal fun Setting.valueImpl(default: List<Boolean>): BooleanListValue { internal fun Setting.valueImpl(default: List<Boolean>): BooleanListValue {
return object : BooleanListValue() { return object : BooleanListValue() {
private var internalValue: List<Boolean> = default private var internalValue: List<Boolean> = default
@ -486,6 +517,7 @@ internal fun Setting.valueImpl(default: List<Boolean>): BooleanListValue {
override val serializer = ListSerializer(Boolean.serializer()) override val serializer = ListSerializer(Boolean.serializer())
} }
} }
internal fun Setting.valueImpl(default: List<Char>): CharListValue { internal fun Setting.valueImpl(default: List<Char>): CharListValue {
return object : CharListValue() { return object : CharListValue() {
private var internalValue: List<Char> = default private var internalValue: List<Char> = default
@ -500,6 +532,7 @@ internal fun Setting.valueImpl(default: List<Char>): CharListValue {
override val serializer = ListSerializer(Char.serializer()) override val serializer = ListSerializer(Char.serializer())
} }
} }
internal fun Setting.valueImpl(default: List<String>): StringListValue { internal fun Setting.valueImpl(default: List<String>): StringListValue {
return object : StringListValue() { return object : StringListValue() {
private var internalValue: List<String> = default private var internalValue: List<String> = default
@ -650,6 +683,7 @@ internal fun Setting.valueImpl(default: Set<String>): StringSetValue {
} }
} }
@JvmName("valueImplMutableIntList") @JvmName("valueImplMutableIntList")
internal fun Setting.valueImpl( internal fun Setting.valueImpl(
default: MutableList<Int> default: MutableList<Int>
@ -1281,3 +1315,30 @@ internal fun Setting.valueImpl(
} }
internal fun <T : Setting> Setting.valueImpl(default: T): Value<T> {
return object : SettingValue<T>() {
private var internalValue: T = default
override var value: T
get() = internalValue
set(new) {
if (new != internalValue) {
internalValue = new
onElementChanged(this)
}
}
override val serializer = object : KSerializer<T> {
override val descriptor: SerialDescriptor
get() = internalValue.updaterSerializer.descriptor
override fun deserialize(decoder: Decoder): T {
internalValue.updaterSerializer.deserialize(decoder)
return internalValue
}
override fun serialize(encoder: Encoder, value: T) {
internalValue.updaterSerializer.serialize(encoder, SettingSerializerMark)
}
}
}
}