This commit is contained in:
Him188 2020-06-24 04:31:30 +08:00
parent 1186083f09
commit 0dd274fc4e
5 changed files with 19 additions and 9 deletions

View File

@ -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 <T> SerializerAwareValue<T>.provideDelegate(

View File

@ -117,6 +117,8 @@ internal fun <K, V> Setting.createCompositeMapValueImpl(
}
}
// TODO: 2020/6/24 在一个 Value 被删除后停止追踪其更新.
internal abstract class CompositeMapValueImpl<K, V>(
kToValue: (K) -> Value<K>, // should override onChanged
vToValue: (V) -> Value<V> // should override onChanged

View File

@ -147,7 +147,14 @@ internal inline fun <R, T> 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<Any?> {
fun serializerByKTypeImpl(type: KType): KSerializer<Any> {

View File

@ -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<SerialN
* - Reflection on Kotlin properties and Java fields
* - Auto-saving
*/
// TODO move to internal package.
internal abstract class SettingImpl {
internal fun findNodeInstance(name: String): Node<*>? = 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)

View File

@ -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<MutableMap<String, String>>()
val map2 by value<MutableMap<String, MutableMap<String, String>>>()
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, """