diff --git a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/ValueSettingCodegen.kt b/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/ValueSettingCodegen.kt index 7382bd31b..04727142c 100644 --- a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/ValueSettingCodegen.kt +++ b/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/ValueSettingCodegen.kt @@ -136,6 +136,22 @@ internal fun Setting.${ktType.lowerCaseName}ValueImpl(): SerializerAwareValue<${ } } + object Setting_value_primitivesCodegen : RegionCodegen("Setting.kt"), DefaultInvoke { + @JvmStatic + fun main(args: Array) = super.startIndependent() + override val defaultInvokeArgs: List = KtPrimitives + KtString + + override fun StringBuilder.apply(ktType: KtType) { + @Suppress("unused") + appendKCode( + """ + fun Setting.value(default: ${ktType.standardName}): SerializerAwareValue<${ktType.standardName}> = valueImpl(default) + """ + ) + } + + } + /** * 运行本 object 中所有嵌套 object Codegen */ 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 24bc314e4..4f0d43d5e 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 @@ -146,13 +146,19 @@ internal abstract class SettingImpl { } -//// region Setting.value primitives CODEGEN //// - -// TODO: 2020/6/19 CODEGEN +//// region Setting_value_primitives CODEGEN //// +fun Setting.value(default: Byte): SerializerAwareValue = valueImpl(default) +fun Setting.value(default: Short): SerializerAwareValue = valueImpl(default) fun Setting.value(default: Int): SerializerAwareValue = valueImpl(default) +fun Setting.value(default: Long): SerializerAwareValue = valueImpl(default) +fun Setting.value(default: Float): SerializerAwareValue = valueImpl(default) +fun Setting.value(default: Double): SerializerAwareValue = valueImpl(default) +fun Setting.value(default: Char): SerializerAwareValue = valueImpl(default) +fun Setting.value(default: Boolean): SerializerAwareValue = valueImpl(default) +fun Setting.value(default: String): SerializerAwareValue = valueImpl(default) -//// endregion Setting.value primitives CODEGEN //// +//// endregion Setting_value_primitives CODEGEN //// /** @@ -170,4 +176,6 @@ inline fun Setting.valueReified(default: T): SerializerAwareValue valueFromKTypeImpl(typeOf()).cast() @MiraiExperimentalAPI -fun Setting.valueFromKType(type: KType): SerializerAwareValue = valueFromKTypeImpl(type).cast() \ No newline at end of file +fun Setting.valueFromKType(type: KType): SerializerAwareValue = valueFromKTypeImpl(type).cast() + +// TODO: 2020/6/24 Introduce class TypeToken for compound types for Java. \ No newline at end of file