This commit is contained in:
Him188 2020-05-22 20:04:23 +08:00
parent f82d01e606
commit c87e8b07df
2 changed files with 17 additions and 0 deletions

View File

@ -21,6 +21,7 @@ kotlin {
languageSettings.useExperimentalAnnotation("kotlin.OptIn")
languageSettings.progressiveMode = true
languageSettings.useExperimentalAnnotation("net.mamoe.mirai.utils.MiraiInternalAPI")
languageSettings.useExperimentalAnnotation("net.mamoe.mirai.utils.MiraiExperimentalAPI")
languageSettings.useExperimentalAnnotation("kotlin.ExperimentalUnsignedTypes")
languageSettings.useExperimentalAnnotation("kotlin.experimental.ExperimentalTypeInference")
languageSettings.useExperimentalAnnotation("kotlin.contracts.ExperimentalContracts")

View File

@ -12,23 +12,39 @@
package net.mamoe.mirai.console.setting
import kotlinx.serialization.KSerializer
import net.mamoe.mirai.utils.MiraiExperimentalAPI
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty
import kotlin.reflect.full.findAnnotation
/**
* 在配置文件和图像界面中保存的名称.
*/
typealias SerialName = kotlinx.serialization.SerialName
/**
* 在配置文件和图像界面中显示的说明.
*/
typealias Comment = net.mamoe.yamlkt.Comment
/**
* 配置的基类. 所有配置必须拥有一个无参构造器, 以用于在 [MutableList] [MutableMap] 中动态识别类型
*/
@Suppress("EXPOSED_SUPER_CLASS")
abstract class Setting : SettingImpl() {
/**
* 这个配置的名称, 仅对于顶层配置有效.
*/
@MiraiExperimentalAPI
open val serialName: String
get() = this::class.findAnnotation<SerialName>()?.value
?: this::class.qualifiedName
?: error("Names should be assigned to anonymous classes manually by overriding serialName")
/**
* 提供属性委托, 并添加这个对象的自动保存跟踪.
*/
@JvmSynthetic
operator fun <T : Any> Value<T>.provideDelegate(
thisRef: Setting,