Improve generated value impl

This commit is contained in:
Him188 2020-05-25 18:37:08 +08:00
parent 240253cf21
commit 65cbf6e780
2 changed files with 79 additions and 76 deletions

View File

@ -110,7 +110,7 @@ fun genAllValueImpl(): String = buildString {
): Mutable${number}${collectionName}Value { ): Mutable${number}${collectionName}Value {
var internalValue: Mutable${collectionName}<${number}> = default var internalValue: Mutable${collectionName}<${number}> = default
val delegt = dynamicMutable${collectionName}{ internalValue } val delegt = dynamicMutable${collectionName} { internalValue }
return object : Mutable${number}${collectionName}Value(), Mutable${collectionName}<${number}> by delegt { return object : Mutable${number}${collectionName}Value(), Mutable${collectionName}<${number}> by delegt {
override var value: Mutable${collectionName}<${number}> override var value: Mutable${collectionName}<${number}>
get() = internalValue get() = internalValue

View File

@ -9,7 +9,10 @@
package net.mamoe.mirai.console.setting.internal package net.mamoe.mirai.console.setting.internal
import kotlinx.serialization.* import kotlinx.serialization.Decoder
import kotlinx.serialization.Encoder
import kotlinx.serialization.KSerializer
import kotlinx.serialization.SerialDescriptor
import kotlinx.serialization.builtins.* import kotlinx.serialization.builtins.*
import net.mamoe.mirai.console.setting.* import net.mamoe.mirai.console.setting.*
@ -705,7 +708,7 @@ internal fun Setting.valueImpl(
): MutableIntListValue { ): MutableIntListValue {
var internalValue: MutableList<Int> = default var internalValue: MutableList<Int> = default
val delegt = dynamicMutableList{ internalValue } val delegt = dynamicMutableList { internalValue }
return object : MutableIntListValue(), MutableList<Int> by delegt { return object : MutableIntListValue(), MutableList<Int> by delegt {
override var value: MutableList<Int> override var value: MutableList<Int>
get() = internalValue get() = internalValue
@ -741,7 +744,7 @@ internal fun Setting.valueImpl(
): MutableShortListValue { ): MutableShortListValue {
var internalValue: MutableList<Short> = default var internalValue: MutableList<Short> = default
val delegt = dynamicMutableList{ internalValue } val delegt = dynamicMutableList { internalValue }
return object : MutableShortListValue(), MutableList<Short> by delegt { return object : MutableShortListValue(), MutableList<Short> by delegt {
override var value: MutableList<Short> override var value: MutableList<Short>
get() = internalValue get() = internalValue
@ -777,7 +780,7 @@ internal fun Setting.valueImpl(
): MutableByteListValue { ): MutableByteListValue {
var internalValue: MutableList<Byte> = default var internalValue: MutableList<Byte> = default
val delegt = dynamicMutableList{ internalValue } val delegt = dynamicMutableList { internalValue }
return object : MutableByteListValue(), MutableList<Byte> by delegt { return object : MutableByteListValue(), MutableList<Byte> by delegt {
override var value: MutableList<Byte> override var value: MutableList<Byte>
get() = internalValue get() = internalValue
@ -813,7 +816,7 @@ internal fun Setting.valueImpl(
): MutableLongListValue { ): MutableLongListValue {
var internalValue: MutableList<Long> = default var internalValue: MutableList<Long> = default
val delegt = dynamicMutableList{ internalValue } val delegt = dynamicMutableList { internalValue }
return object : MutableLongListValue(), MutableList<Long> by delegt { return object : MutableLongListValue(), MutableList<Long> by delegt {
override var value: MutableList<Long> override var value: MutableList<Long>
get() = internalValue get() = internalValue
@ -849,7 +852,7 @@ internal fun Setting.valueImpl(
): MutableFloatListValue { ): MutableFloatListValue {
var internalValue: MutableList<Float> = default var internalValue: MutableList<Float> = default
val delegt = dynamicMutableList{ internalValue } val delegt = dynamicMutableList { internalValue }
return object : MutableFloatListValue(), MutableList<Float> by delegt { return object : MutableFloatListValue(), MutableList<Float> by delegt {
override var value: MutableList<Float> override var value: MutableList<Float>
get() = internalValue get() = internalValue
@ -885,7 +888,7 @@ internal fun Setting.valueImpl(
): MutableDoubleListValue { ): MutableDoubleListValue {
var internalValue: MutableList<Double> = default var internalValue: MutableList<Double> = default
val delegt = dynamicMutableList{ internalValue } val delegt = dynamicMutableList { internalValue }
return object : MutableDoubleListValue(), MutableList<Double> by delegt { return object : MutableDoubleListValue(), MutableList<Double> by delegt {
override var value: MutableList<Double> override var value: MutableList<Double>
get() = internalValue get() = internalValue
@ -921,7 +924,7 @@ internal fun Setting.valueImpl(
): MutableBooleanListValue { ): MutableBooleanListValue {
var internalValue: MutableList<Boolean> = default var internalValue: MutableList<Boolean> = default
val delegt = dynamicMutableList{ internalValue } val delegt = dynamicMutableList { internalValue }
return object : MutableBooleanListValue(), MutableList<Boolean> by delegt { return object : MutableBooleanListValue(), MutableList<Boolean> by delegt {
override var value: MutableList<Boolean> override var value: MutableList<Boolean>
get() = internalValue get() = internalValue
@ -957,7 +960,7 @@ internal fun Setting.valueImpl(
): MutableCharListValue { ): MutableCharListValue {
var internalValue: MutableList<Char> = default var internalValue: MutableList<Char> = default
val delegt = dynamicMutableList{ internalValue } val delegt = dynamicMutableList { internalValue }
return object : MutableCharListValue(), MutableList<Char> by delegt { return object : MutableCharListValue(), MutableList<Char> by delegt {
override var value: MutableList<Char> override var value: MutableList<Char>
get() = internalValue get() = internalValue
@ -993,7 +996,7 @@ internal fun Setting.valueImpl(
): MutableStringListValue { ): MutableStringListValue {
var internalValue: MutableList<String> = default var internalValue: MutableList<String> = default
val delegt = dynamicMutableList{ internalValue } val delegt = dynamicMutableList { internalValue }
return object : MutableStringListValue(), MutableList<String> by delegt { return object : MutableStringListValue(), MutableList<String> by delegt {
override var value: MutableList<String> override var value: MutableList<String>
get() = internalValue get() = internalValue
@ -1029,7 +1032,7 @@ internal fun Setting.valueImpl(
): MutableIntSetValue { ): MutableIntSetValue {
var internalValue: MutableSet<Int> = default var internalValue: MutableSet<Int> = default
val delegt = dynamicMutableSet{ internalValue } val delegt = dynamicMutableSet { internalValue }
return object : MutableIntSetValue(), MutableSet<Int> by delegt { return object : MutableIntSetValue(), MutableSet<Int> by delegt {
override var value: MutableSet<Int> override var value: MutableSet<Int>
get() = internalValue get() = internalValue
@ -1065,7 +1068,7 @@ internal fun Setting.valueImpl(
): MutableShortSetValue { ): MutableShortSetValue {
var internalValue: MutableSet<Short> = default var internalValue: MutableSet<Short> = default
val delegt = dynamicMutableSet{ internalValue } val delegt = dynamicMutableSet { internalValue }
return object : MutableShortSetValue(), MutableSet<Short> by delegt { return object : MutableShortSetValue(), MutableSet<Short> by delegt {
override var value: MutableSet<Short> override var value: MutableSet<Short>
get() = internalValue get() = internalValue
@ -1101,7 +1104,7 @@ internal fun Setting.valueImpl(
): MutableByteSetValue { ): MutableByteSetValue {
var internalValue: MutableSet<Byte> = default var internalValue: MutableSet<Byte> = default
val delegt = dynamicMutableSet{ internalValue } val delegt = dynamicMutableSet { internalValue }
return object : MutableByteSetValue(), MutableSet<Byte> by delegt { return object : MutableByteSetValue(), MutableSet<Byte> by delegt {
override var value: MutableSet<Byte> override var value: MutableSet<Byte>
get() = internalValue get() = internalValue
@ -1137,7 +1140,7 @@ internal fun Setting.valueImpl(
): MutableLongSetValue { ): MutableLongSetValue {
var internalValue: MutableSet<Long> = default var internalValue: MutableSet<Long> = default
val delegt = dynamicMutableSet{ internalValue } val delegt = dynamicMutableSet { internalValue }
return object : MutableLongSetValue(), MutableSet<Long> by delegt { return object : MutableLongSetValue(), MutableSet<Long> by delegt {
override var value: MutableSet<Long> override var value: MutableSet<Long>
get() = internalValue get() = internalValue
@ -1173,7 +1176,7 @@ internal fun Setting.valueImpl(
): MutableFloatSetValue { ): MutableFloatSetValue {
var internalValue: MutableSet<Float> = default var internalValue: MutableSet<Float> = default
val delegt = dynamicMutableSet{ internalValue } val delegt = dynamicMutableSet { internalValue }
return object : MutableFloatSetValue(), MutableSet<Float> by delegt { return object : MutableFloatSetValue(), MutableSet<Float> by delegt {
override var value: MutableSet<Float> override var value: MutableSet<Float>
get() = internalValue get() = internalValue
@ -1209,7 +1212,7 @@ internal fun Setting.valueImpl(
): MutableDoubleSetValue { ): MutableDoubleSetValue {
var internalValue: MutableSet<Double> = default var internalValue: MutableSet<Double> = default
val delegt = dynamicMutableSet{ internalValue } val delegt = dynamicMutableSet { internalValue }
return object : MutableDoubleSetValue(), MutableSet<Double> by delegt { return object : MutableDoubleSetValue(), MutableSet<Double> by delegt {
override var value: MutableSet<Double> override var value: MutableSet<Double>
get() = internalValue get() = internalValue
@ -1245,7 +1248,7 @@ internal fun Setting.valueImpl(
): MutableBooleanSetValue { ): MutableBooleanSetValue {
var internalValue: MutableSet<Boolean> = default var internalValue: MutableSet<Boolean> = default
val delegt = dynamicMutableSet{ internalValue } val delegt = dynamicMutableSet { internalValue }
return object : MutableBooleanSetValue(), MutableSet<Boolean> by delegt { return object : MutableBooleanSetValue(), MutableSet<Boolean> by delegt {
override var value: MutableSet<Boolean> override var value: MutableSet<Boolean>
get() = internalValue get() = internalValue
@ -1281,7 +1284,7 @@ internal fun Setting.valueImpl(
): MutableCharSetValue { ): MutableCharSetValue {
var internalValue: MutableSet<Char> = default var internalValue: MutableSet<Char> = default
val delegt = dynamicMutableSet{ internalValue } val delegt = dynamicMutableSet { internalValue }
return object : MutableCharSetValue(), MutableSet<Char> by delegt { return object : MutableCharSetValue(), MutableSet<Char> by delegt {
override var value: MutableSet<Char> override var value: MutableSet<Char>
get() = internalValue get() = internalValue
@ -1317,7 +1320,7 @@ internal fun Setting.valueImpl(
): MutableStringSetValue { ): MutableStringSetValue {
var internalValue: MutableSet<String> = default var internalValue: MutableSet<String> = default
val delegt = dynamicMutableSet{ internalValue } val delegt = dynamicMutableSet { internalValue }
return object : MutableStringSetValue(), MutableSet<String> by delegt { return object : MutableStringSetValue(), MutableSet<String> by delegt {
override var value: MutableSet<String> override var value: MutableSet<String>
get() = internalValue get() = internalValue
@ -1359,7 +1362,7 @@ internal fun <T : Setting> Setting.valueImpl(default: T): Value<T> {
onElementChanged(this) onElementChanged(this)
} }
} }
override val serializer = object : KSerializer<T>{ override val serializer = object : KSerializer<T> {
override val descriptor: SerialDescriptor override val descriptor: SerialDescriptor
get() = internalValue.updaterSerializer.descriptor get() = internalValue.updaterSerializer.descriptor