Java keywords cannot be used as package/class name

This commit is contained in:
残页 2021-12-28 21:34:26 +08:00 committed by John Wu
parent 19182ffddf
commit 31fe3a1cd8

View File

@ -194,7 +194,23 @@ fun genStubManifest(srcDir: File, outDir: File): String {
val pkgNames = names.distinctBy { it.toLowerCase(Locale.ROOT) }
var idx = 0
fun genCmpName() = "${pkgNames[idx++]}.${names.random(kRANDOM)}"
fun isJavaKeyword(name: String) = when (name) {
"do", "if", "for", "int", "new", "try" -> true
else -> false
}
fun genCmpName() : String {
var pkgName : String
do {
pkgName = pkgNames[idx++]
} while (isJavaKeyword(pkgName))
var clzName : String
do {
clzName = names.random(kRANDOM)
} while (isJavaKeyword(clzName))
return "${pkgName}.${clzName}"
}
fun genClass(clzName: String, type: String) {
val (pkg, name) = clzName.split('.')