mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
for merge
This commit is contained in:
parent
86f23e5452
commit
e863e122c5
@ -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())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
@ -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 = """
|
||||
|
Loading…
Reference in New Issue
Block a user