nbcp.myoql.code.generator.tool.Enum4JsGenerator.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ktmyoql-code-generator Show documentation
Show all versions of ktmyoql-code-generator Show documentation
kotlin orm -- mysql,mongo , just like ktorm
The newest version!
package nbcp.myoql.code.generator.tool
import nbcp.base.extend.GetEnumJsonValueValue
import nbcp.base.extend.GetEnumList
import nbcp.base.extend.GetEnumStringField
import nbcp.base.utils.ClassUtil
import nbcp.base.utils.ReflectUtil
/**
* 枚举Js的生成器
*/
object Enum4JsGenerator {
/**
* 入口
*/
@JvmStatic
fun generateEnum(basePackage: String): List {
var ret = mutableListOf()
val fileList = ClassUtil.findClasses(basePackage, false, Enum::class.java)
fileList.forEach {
ret.add(generateEnum(it as Class>))
}
return ret;
}
@JvmStatic
fun > generateEnum(jsonEnumClass: Class): String {
if (jsonEnumClass.isEnum == false) {
return "";
}
var jsonList = jsonEnumClass.GetEnumList()
var ret = "";
if (jsonList.size > 0) {
var strField = jsonEnumClass.GetEnumStringField();
ret = """jv.defEnum("${jsonEnumClass.simpleName}",{""" +
jsonList.map {
it.GetEnumJsonValueValue() + ":\"" +
(if (strField != null) ReflectUtil.getPrivatePropertyValue(
it,
strField
) else it.toString()) + "\""
}.joinToString(",") + "});"
println(ret);
}
return ret;
}
}