Skip to content

Commit

Permalink
Java keywords cannot be used as package/class name
Browse files Browse the repository at this point in the history
  • Loading branch information
canyie authored and topjohnwu committed Dec 29, 2021
1 parent 19182ff commit 31fe3a1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion buildSrc/src/main/java/Codegen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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('.')
Expand Down

0 comments on commit 31fe3a1

Please sign in to comment.