diff --git a/backend/mirai-console/build.gradle.kts b/backend/mirai-console/build.gradle.kts index 1377bd738..57f14a79f 100644 --- a/backend/mirai-console/build.gradle.kts +++ b/backend/mirai-console/build.gradle.kts @@ -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") 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 f18fd1fcb..6282aa90b 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 @@ -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()?.value ?: this::class.qualifiedName ?: error("Names should be assigned to anonymous classes manually by overriding serialName") + /** + * 提供属性委托, 并添加这个对象的自动保存跟踪. + */ @JvmSynthetic operator fun Value.provideDelegate( thisRef: Setting,