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 {
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 {
override var value: Mutable${collectionName}<${number}>
get() = internalValue

View File

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