diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/Setting.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/Setting.kt index a765c9623..c79a836b6 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/Setting.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/Setting.kt @@ -17,7 +17,6 @@ import kotlin.internal.LowPriorityInOverloadResolution import kotlin.reflect.KProperty import kotlin.reflect.KType -// TODO: 2020/6/21 move to JvmPlugin to inherit SettingStorage and CoroutineScope for saving // Shows public APIs such as deciding when to auto-save. abstract class Setting : SettingImpl() { operator fun SerializerAwareValue.provideDelegate( diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/CompositeValueImpl.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/CompositeValueImpl.kt index a3e666b92..5b908f218 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/CompositeValueImpl.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/CompositeValueImpl.kt @@ -117,6 +117,8 @@ internal fun Setting.createCompositeMapValueImpl( } } +// TODO: 2020/6/24 在一个 Value 被删除后停止追踪其更新. + internal abstract class CompositeMapValueImpl( kToValue: (K) -> Value, // should override onChanged vToValue: (V) -> Value // should override onChanged diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/Setting.value composite impl.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/Setting.value composite impl.kt index 12b26af65..c70db9e71 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/Setting.value composite impl.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/Setting.value composite impl.kt @@ -147,7 +147,14 @@ internal inline fun T.cast(): R = this as R * Copied from kotlinx.serialization, modifications are marked with "/* mamoe modify */" * Copyright 2017-2020 JetBrains s.r.o. */ -@Suppress("UNCHECKED_CAST", "NO_REFLECTION_IN_CLASS_PATH", "UNSUPPORTED", "INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@Suppress( + "UNCHECKED_CAST", + "NO_REFLECTION_IN_CLASS_PATH", + "UNSUPPORTED", + "INVISIBLE_MEMBER", + "INVISIBLE_REFERENCE", + "IMPLICIT_CAST_TO_ANY" +) @OptIn(ImplicitReflectionSerializer::class) internal fun serializerMirai(type: KType): KSerializer { fun serializerByKTypeImpl(type: KType): KSerializer { diff --git a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/SettingImpl.kt b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/SettingImpl.kt index d71c7d590..8569ec27e 100644 --- a/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/SettingImpl.kt +++ b/backend/mirai-console/src/main/kotlin/net/mamoe/mirai/console/setting/internal/SettingImpl.kt @@ -14,6 +14,7 @@ package net.mamoe.mirai.console.setting.internal import kotlinx.serialization.* import kotlinx.serialization.builtins.MapSerializer import kotlinx.serialization.builtins.serializer +import net.mamoe.mirai.console.setting.Setting import net.mamoe.mirai.console.setting.Value import net.mamoe.yamlkt.YamlNullableDynamicSerializer import kotlin.reflect.KProperty @@ -26,7 +27,6 @@ internal val KProperty<*>.serialName: String get() = this.findAnnotation? = valueNodes.firstOrNull { it.serialName == name } @@ -110,9 +110,7 @@ internal abstract class SettingImpl { /** * flatten */ - internal fun onValueChanged(value: Value<*>) { - // TODO: 2020/6/22 - } + abstract fun onValueChanged(value: Value<*>) companion object { private val settingUpdaterSerializerTypeArguments = arrayOf(String.serializer(), YamlNullableDynamicSerializer) diff --git a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/setting/SettingTest.kt b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/setting/SettingTest.kt index 6fce8dbb5..b3b2e51ed 100644 --- a/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/setting/SettingTest.kt +++ b/backend/mirai-console/src/test/kotlin/net/mamoe/mirai/console/setting/SettingTest.kt @@ -20,8 +20,12 @@ internal class SettingTest { class MySetting : Setting() { var int by value(1) - val map by value(mapOf("" to "")) - val map2 by value(mutableMapOf("" to mutableMapOf("" to ""))) + val map by value>() + val map2 by value>>() + + override fun onValueChanged(value: Value<*>) { + + } } @OptIn(UnstableDefault::class) @@ -65,7 +69,7 @@ internal class SettingTest { val refBefore = setting.map fun reference() = refBefore - assertEquals(mapOf(), delegation()) // delegation + assertEquals(mutableMapOf(), delegation()) // delegation json.parse( setting.updaterSerializer, """