@@ -68,7 +68,11 @@ package struct JavaIdentifierFactory {
6868 case . setter, . subscriptSetter: decl. javaSetterName
6969 case . function, . initializer, . enumCase: decl. name
7070 }
71- return baseName + paramsSuffix( decl, baseName: baseName)
71+ var methodName = baseName + paramsSuffix( decl, baseName: baseName)
72+ if Self . javaKeywords. contains ( methodName) {
73+ methodName += " _ "
74+ }
75+ return methodName
7276 }
7377
7478 private func paramsSuffix( _ decl: ImportedFunc , baseName: String ) -> String {
@@ -86,4 +90,22 @@ package struct JavaIdentifierFactory {
8690 return labels. map { $0. prefix ( 1 ) . uppercased ( ) + $0. dropFirst ( ) } . joined ( )
8791 }
8892 }
93+
94+ static let javaKeywords : Set < String > = [
95+ /// https://docs.oracle.com/javase/specs/jls/se25/html/jls-3.html#jls-3.9
96+ " abstract " , " continue " , " for " , " new " , " switch " ,
97+ " assert " , " default " , " if " , " package " , " synchronized " ,
98+ " boolean " , " do " , " goto " , " private " , " this " ,
99+ " break " , " double " , " implements " , " protected " , " throw " ,
100+ " byte " , " else " , " import " , " public " , " throws " ,
101+ " case " , " enum " , " instanceof " , " return " , " transient " ,
102+ " catch " , " extends " , " int " , " short " , " try " ,
103+ " char " , " final " , " interface " , " static " , " void " ,
104+ " class " , " finally " , " long " , " strictfp " , " volatile " ,
105+ " const " , " float " , " native " , " super " , " while " ,
106+ " _ " ,
107+
108+ /// literals
109+ " true " , " false " , " null " ,
110+ ]
89111}
0 commit comments