@@ -201,7 +201,7 @@ public boolean visit(ArrayCreation node) {
201
201
} else {
202
202
List dim = node .dimensions ();
203
203
ITypeBinding elementType = node .getType ().getElementType ().resolveBinding ();
204
- if (elementType != null ){
204
+ if (elementType != null ){
205
205
if (elementType .isPrimitive ()) {
206
206
String typeCode = elementType .getName ();
207
207
if ("int" .equals (typeCode )
@@ -258,10 +258,58 @@ public boolean visit(ArrayInitializer node) {
258
258
/*
259
259
* TODO: should be tested
260
260
*/
261
- buffer .append ("[" );
262
- List list = node .expressions ();
263
- visitList (list , ", " );
264
- buffer .append ("]" );
261
+ List expressions = node .expressions ();
262
+ ITypeBinding arrType = node .resolveTypeBinding ();
263
+ ITypeBinding elementType = null ;
264
+ if (arrType != null ) {
265
+ elementType = arrType .getComponentType ();
266
+ }
267
+ if (elementType == null ) {
268
+ buffer .append ("[" );
269
+ visitList (expressions , ", " );
270
+ buffer .append ("]" );
271
+ return false ;
272
+ }
273
+ if (elementType .isPrimitive ()) {
274
+ String typeCode = elementType .getName ();
275
+ if ("int" .equals (typeCode )
276
+ || "float" .equals (typeCode )
277
+ || "double" .equals (typeCode )
278
+ || "byte" .equals (typeCode )
279
+ || "long" .equals (typeCode )
280
+ || "short" .equals (typeCode )) {
281
+ //buffer.append(" Clazz.newArray (");
282
+ buffer .append (" Clazz.new" );
283
+ buffer .append (typeCode .substring (0 , 1 ).toUpperCase ());
284
+ buffer .append (typeCode .substring (1 ));
285
+ buffer .append ("Array (-1, " );
286
+ buffer .append ("[" );
287
+ visitList (expressions , ", " );
288
+ buffer .append ("])" );
289
+ } else if ("char" .equals (typeCode )) {
290
+ //buffer.append(" Clazz.newArray (");
291
+ buffer .append (" Clazz.newCharArray (-1, " );
292
+ buffer .append ("[" );
293
+ visitList (expressions , ", " );
294
+ buffer .append ("])" );
295
+ } else if ("boolean" .equals (typeCode )) {
296
+ //buffer.append(" Clazz.newArray (");
297
+ buffer .append (" Clazz.newBooleanArray (-1, " );
298
+ buffer .append ("[" );
299
+ visitList (expressions , ", " );
300
+ buffer .append ("])" );
301
+ } else {
302
+ buffer .append (" Clazz.newArray (-1, " );
303
+ buffer .append ("[" );
304
+ visitList (expressions , ", " );
305
+ buffer .append ("])" );
306
+ }
307
+ } else {
308
+ buffer .append (" Clazz.newArray (-1, " );
309
+ buffer .append ("[" );
310
+ visitList (expressions , ", " );
311
+ buffer .append ("])" );
312
+ }
265
313
return false ;
266
314
}
267
315
@@ -1340,11 +1388,30 @@ public boolean visit(ReturnStatement node) {
1340
1388
Expression expression = node .getExpression ();
1341
1389
if (expression != null ) {
1342
1390
buffer .append (' ' );
1343
- ITypeBinding tBinding = expression .resolveTypeBinding ();
1344
- if (tBinding != null && !("char" .equals (tBinding .getName ()))) {
1345
- buffer .append ("String.fromCharCode (" );
1346
- expression .accept (this );
1347
- buffer .append (")" );
1391
+ boolean needCharWrapping = false ;
1392
+ ASTNode parent = node .getParent ();
1393
+ while (parent != null && !(parent instanceof MethodDeclaration )) {
1394
+ parent = parent .getParent ();
1395
+ }
1396
+ if (parent != null ) {
1397
+ MethodDeclaration m = (MethodDeclaration ) parent ;
1398
+ IMethodBinding binding = m .resolveBinding ();
1399
+ if (binding != null ) {
1400
+ ITypeBinding returnType = binding .getReturnType ();
1401
+ if (returnType != null && "char" .equals (returnType .getName ())) {
1402
+ needCharWrapping = true ;
1403
+ }
1404
+ }
1405
+ }
1406
+ if (needCharWrapping ) {
1407
+ ITypeBinding tBinding = expression .resolveTypeBinding ();
1408
+ if (tBinding != null && !("char" .equals (tBinding .getName ()))) {
1409
+ buffer .append ("String.fromCharCode (" );
1410
+ expression .accept (this );
1411
+ buffer .append (")" );
1412
+ } else {
1413
+ expression .accept (this );
1414
+ }
1348
1415
} else {
1349
1416
expression .accept (this );
1350
1417
}
0 commit comments