41
41
import org .eclipse .jdt .core .dom .Modifier ;
42
42
import org .eclipse .jdt .core .dom .Name ;
43
43
import org .eclipse .jdt .core .dom .NullLiteral ;
44
+ import org .eclipse .jdt .core .dom .ParenthesizedExpression ;
44
45
import org .eclipse .jdt .core .dom .PrimitiveType ;
45
46
import org .eclipse .jdt .core .dom .QualifiedName ;
46
47
import org .eclipse .jdt .core .dom .ReturnStatement ;
@@ -447,12 +448,29 @@ public boolean visit(CastExpression node) {
447
448
|| pType .getPrimitiveTypeCode () == PrimitiveType .LONG ) {
448
449
if ("char" .equals (name )) {
449
450
buffer .append ("(" );
450
- expression .accept (this );
451
+ if (expression instanceof ParenthesizedExpression ) {
452
+ ParenthesizedExpression pe = (ParenthesizedExpression ) expression ;
453
+ pe .getExpression ().accept (this );
454
+ } else {
455
+ expression .accept (this );
456
+ }
451
457
buffer .append (").charCodeAt (0)" );
452
458
return false ;
453
459
} else if ("float" .equals (name ) || "double" .equals (name )) {
454
- buffer .append ("Math.round (" );
455
- expression .accept (this );
460
+ //buffer.append("Math.round (");
461
+ buffer .append ("Clazz." );
462
+ buffer .append (name );
463
+ buffer .append ("To" );
464
+ String targetType = pType .getPrimitiveTypeCode ().toString ();
465
+ buffer .append (targetType .substring (0 , 1 ).toUpperCase ());
466
+ buffer .append (targetType .substring (1 ));
467
+ buffer .append (" (" );
468
+ if (expression instanceof ParenthesizedExpression ) {
469
+ ParenthesizedExpression pe = (ParenthesizedExpression ) expression ;
470
+ pe .getExpression ().accept (this );
471
+ } else {
472
+ expression .accept (this );
473
+ }
456
474
buffer .append (")" );
457
475
return false ;
458
476
}
@@ -465,10 +483,18 @@ public boolean visit(CastExpression node) {
465
483
// return false;
466
484
} else if ("float" .equals (name ) || "double" .equals (name )) {
467
485
// TODO:
468
- buffer .append ("String.fromCharCode (" );
469
- buffer .append ("Math.round (" );
470
- expression .accept (this );
471
- buffer .append (")" );
486
+ buffer .append ("Clazz." );
487
+ buffer .append (name );
488
+ buffer .append ("ToChar (" );
489
+ // buffer.append("String.fromCharCode (");
490
+ // buffer.append("Math.round (");
491
+ if (expression instanceof ParenthesizedExpression ) {
492
+ ParenthesizedExpression pe = (ParenthesizedExpression ) expression ;
493
+ pe .getExpression ().accept (this );
494
+ } else {
495
+ expression .accept (this );
496
+ }
497
+ // buffer.append (")");
472
498
buffer .append (")" );
473
499
return false ;
474
500
} else if ("int" .equals (name ) || "byte" .equals (name )
@@ -499,7 +525,12 @@ public boolean visit(CastExpression node) {
499
525
}
500
526
}
501
527
buffer .append ("String.fromCharCode (" );
502
- expression .accept (this );
528
+ if (expression instanceof ParenthesizedExpression ) {
529
+ ParenthesizedExpression pe = (ParenthesizedExpression ) expression ;
530
+ pe .getExpression ().accept (this );
531
+ } else {
532
+ expression .accept (this );
533
+ }
503
534
buffer .append (")" );
504
535
return false ;
505
536
}
@@ -615,7 +646,9 @@ public boolean visit(ClassInstanceCreation node) {
615
646
currentBlockForVisit = blockLevel ;
616
647
visitedVars = variableVisitor .visitedVars = new ArrayList ();
617
648
variableVisitor .normalVars = new ArrayList ();
649
+ methodDeclareStack .push (binding .getKey ());
618
650
anonDeclare .accept (this );
651
+ methodDeclareStack .pop ();
619
652
buffer .append (", " );
620
653
621
654
buffer .append ("Clazz.innerTypeInstance (" );
@@ -1429,7 +1462,9 @@ public boolean visit(InfixExpression node) {
1429
1462
StringBuffer tmpBuffer = buffer ;
1430
1463
buffer = new StringBuffer ();
1431
1464
1432
- buffer .append ("Math.floor (" );
1465
+ //buffer.append("Math.floor (");
1466
+ // TODO
1467
+ buffer .append ("Clazz.doubleToInt (" );
1433
1468
charVisit (left , beCare );
1434
1469
buffer .append (' ' );
1435
1470
buffer .append (operator );
@@ -1445,7 +1480,8 @@ public boolean visit(InfixExpression node) {
1445
1480
Expression exp = (Expression ) element ;
1446
1481
ITypeBinding expBinding = exp .resolveTypeBinding ();
1447
1482
if (isIntegerType (expBinding .getName ())) {
1448
- buffer .insert (0 , "Math.floor (" );
1483
+ //buffer.insert(0, "Math.floor (");
1484
+ buffer .insert (0 , "Clazz.doubleToInt (" );
1449
1485
is2Floor = true ;
1450
1486
}
1451
1487
}
0 commit comments