All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nbcp.myoql.code.generator.tool.Enum4JsGenerator.kt Maven / Gradle / Ivy

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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy