Codegen for Setting_value_primitives

This commit is contained in:
Him188 2020-06-24 03:53:13 +08:00
parent 927943322a
commit 1425378e19
2 changed files with 29 additions and 5 deletions

View File

@ -136,6 +136,22 @@ internal fun Setting.${ktType.lowerCaseName}ValueImpl(): SerializerAwareValue<${
}
}
object Setting_value_primitivesCodegen : RegionCodegen("Setting.kt"), DefaultInvoke {
@JvmStatic
fun main(args: Array<String>) = super.startIndependent()
override val defaultInvokeArgs: List<KtType> = 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
*/

View File

@ -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<Byte> = valueImpl(default)
fun Setting.value(default: Short): SerializerAwareValue<Short> = valueImpl(default)
fun Setting.value(default: Int): SerializerAwareValue<Int> = valueImpl(default)
fun Setting.value(default: Long): SerializerAwareValue<Long> = valueImpl(default)
fun Setting.value(default: Float): SerializerAwareValue<Float> = valueImpl(default)
fun Setting.value(default: Double): SerializerAwareValue<Double> = valueImpl(default)
fun Setting.value(default: Char): SerializerAwareValue<Char> = valueImpl(default)
fun Setting.value(default: Boolean): SerializerAwareValue<Boolean> = valueImpl(default)
fun Setting.value(default: String): SerializerAwareValue<String> = valueImpl(default)
//// endregion Setting.value primitives CODEGEN ////
//// endregion Setting_value_primitives CODEGEN ////
/**
@ -170,4 +176,6 @@ inline fun <reified T> Setting.valueReified(default: T): SerializerAwareValue<T>
valueFromKTypeImpl(typeOf<T>()).cast()
@MiraiExperimentalAPI
fun <T> Setting.valueFromKType(type: KType): SerializerAwareValue<T> = valueFromKTypeImpl(type).cast()
fun <T> Setting.valueFromKType(type: KType): SerializerAwareValue<T> = valueFromKTypeImpl(type).cast()
// TODO: 2020/6/24 Introduce class TypeToken for compound types for Java.