for merge

This commit is contained in:
jiahua.liu 2020-06-18 23:01:58 +08:00
parent 86f23e5452
commit e863e122c5
2 changed files with 82 additions and 1 deletions

View File

@ -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())
}
}
})
}

View File

@ -46,7 +46,7 @@ private val PACKAGE = """
package net.mamoe.mirai.console.setting package net.mamoe.mirai.console.setting
""".trimIndent() """.trimIndent()
private val FILE_SUPPRESS = """ internal val FILE_SUPPRESS = """
@file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "unused") @file:Suppress("INVISIBLE_REFERENCE", "INVISIBLE_MEMBER", "unused")
""".trimIndent() """.trimIndent()
private val IMPORTS = """ private val IMPORTS = """