From e863e122c56d5d8d42de61a28290054f5daacd52 Mon Sep 17 00:00:00 2001 From: "jiahua.liu" Date: Thu, 18 Jun 2020 23:01:58 +0800 Subject: [PATCH] for merge --- .../mirai/console/codegen/JSettingCodegen.kt | 81 +++++++++++++++++++ .../codegen/SettingValueUseSiteCodegen.kt | 2 +- 2 files changed, 82 insertions(+), 1 deletion(-) create mode 100644 backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/JSettingCodegen.kt diff --git a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/JSettingCodegen.kt b/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/JSettingCodegen.kt new file mode 100644 index 000000000..fff3f18ae --- /dev/null +++ b/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/JSettingCodegen.kt @@ -0,0 +1,81 @@ +package net.mamoe.mirai.console.codegen + +/** + * used to generate Java Setting + */ + + + + +open class JClazz(val primitiveName:String,val packageName:String){ + open val funName:String = "value" +} + +class JListClazz(val item:JClazz):JClazz("List<${item.packageName}>","List<${item.packageName}>"){ + override val funName = item.primitiveName.toLowerCase() + "List" +} + +class JArrayClazz(item:JClazz):JClazz(item.primitiveName + "[]",item.primitiveName + "[]") + +class JMapClazz(key:JClazz,value:JClazz):JClazz("Map<${key.packageName},${value.packageName}>","Map<${key.packageName},${value.packageName}>") + + + +internal val J_NUMBERS = listOf( + JClazz("int","Integer"), + JClazz("short","Short"), + JClazz("byte","Byte"), + JClazz("long","Long"), + JClazz("float","Float"), + JClazz("double","Double") +) + +internal val J_EXTRA = listOf( + JClazz("String","String"), + JClazz("boolean","Boolean"), + JClazz("char","Char") +) + + +fun JClazz.getTemplate():String = """ + @NotNull default Value<${this.packageName}> $funName(${this.primitiveName} defaultValue){ + return _SettingKt.value(this,defaultValue); + } + """ + + +fun main(){ + println(buildString { + appendln(COPYRIGHT) + appendln() + appendln(FILE_SUPPRESS) + appendln() + appendln("/**\n" + + " * !!! This file is auto-generated by backend/codegen/src/kotlin/net.mamoe.mirai.console.codegen.JSettingCodegen.kt\n" + + " * !!! DO NOT MODIFY THIS FILE MANUALLY\n" + + " */\n" + + "\"\"\"") + appendln() + appendln() + + + //do simplest + (J_EXTRA + J_NUMBERS).forEach { + appendln(it.getTemplate()) + } + + (J_EXTRA + J_NUMBERS).forEach { + appendln(JListClazz(it).getTemplate()) + } + + (J_EXTRA + J_NUMBERS).forEach { + appendln(JArrayClazz(it).getTemplate()) + } + + (J_EXTRA + J_NUMBERS).forEach {key -> + (J_EXTRA + J_NUMBERS).forEach { value -> + appendln(JMapClazz(key, value).getTemplate()) + } + } + }) +} \ No newline at end of file diff --git a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/SettingValueUseSiteCodegen.kt b/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/SettingValueUseSiteCodegen.kt index 3906cf4d1..36af092a4 100644 --- a/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/SettingValueUseSiteCodegen.kt +++ b/backend/codegen/src/main/kotlin/net/mamoe/mirai/console/codegen/SettingValueUseSiteCodegen.kt @@ -46,7 +46,7 @@ private val PACKAGE = """ package net.mamoe.mirai.console.setting """.trimIndent() -private val FILE_SUPPRESS = """ +internal val FILE_SUPPRESS = """ @file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "unused") """.trimIndent() private val IMPORTS = """