File tree Expand file tree Collapse file tree
main/java/com/google/devtools/j2objc/translate
test/java/com/google/devtools/j2objc/gen Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -303,7 +303,8 @@ public boolean visit(VariableDeclarationFragment variableDeclaration) {
303303 }
304304
305305 private void handleVariable (VariableElement variable ) {
306- if (variable .getKind ().isField ()) {
306+ if (variable .getKind ().isField () || ElementUtil .isUnnamed (variable )) {
307+ // Do not rename fields or unnamed variables.
307308 return ;
308309 }
309310 Scope scope = scopes .peek ();
Original file line number Diff line number Diff line change @@ -2174,14 +2174,18 @@ public void testUnnamedVariableDeclaration() throws IOException {
21742174 " }" ,
21752175 " void test() {" ,
21762176 " Date _ = getCurrentDate();" ,
2177+ " Number _ = null;" ,
21772178 " System.out.println(\" field initialized: \" + (currentDate != null));" ,
21782179 " }" ,
21792180 "}" ),
21802181 "Test" ,
21812182 "Test.m" );
2182- // Verify that the local variable is named "_", as javac uses an empty strings.
2183- assertTranslation (
2184- translation , "JavaUtilDate *_ = JreRetainedLocalValue([self getCurrentDate]);" );
2183+ // Verify that unnamed local variable are named "_", as javac uses an empty strings. Also
2184+ // verify that if there are multiple unnamed variables, they are not renamed.
2185+ assertTranslatedLines (
2186+ translation ,
2187+ "JavaUtilDate *_ = JreRetainedLocalValue([self getCurrentDate]);" ,
2188+ "NSNumber *_ = nil;" );
21852189 });
21862190 }
21872191
You can’t perform that action at this time.
0 commit comments