4141import org .eclipse .jdt .core .dom .Modifier ;
4242import org .eclipse .jdt .core .dom .Name ;
4343import org .eclipse .jdt .core .dom .NullLiteral ;
44+ import org .eclipse .jdt .core .dom .ParenthesizedExpression ;
4445import org .eclipse .jdt .core .dom .PrimitiveType ;
4546import org .eclipse .jdt .core .dom .QualifiedName ;
4647import org .eclipse .jdt .core .dom .ReturnStatement ;
@@ -447,12 +448,29 @@ public boolean visit(CastExpression node) {
447448 || pType .getPrimitiveTypeCode () == PrimitiveType .LONG ) {
448449 if ("char" .equals (name )) {
449450 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+ }
451457 buffer .append (").charCodeAt (0)" );
452458 return false ;
453459 } 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+ }
456474 buffer .append (")" );
457475 return false ;
458476 }
@@ -465,10 +483,18 @@ public boolean visit(CastExpression node) {
465483// return false;
466484 } else if ("float" .equals (name ) || "double" .equals (name )) {
467485 // 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 (")");
472498 buffer .append (")" );
473499 return false ;
474500 } else if ("int" .equals (name ) || "byte" .equals (name )
@@ -499,7 +525,12 @@ public boolean visit(CastExpression node) {
499525 }
500526 }
501527 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+ }
503534 buffer .append (")" );
504535 return false ;
505536 }
@@ -615,7 +646,9 @@ public boolean visit(ClassInstanceCreation node) {
615646 currentBlockForVisit = blockLevel ;
616647 visitedVars = variableVisitor .visitedVars = new ArrayList ();
617648 variableVisitor .normalVars = new ArrayList ();
649+ methodDeclareStack .push (binding .getKey ());
618650 anonDeclare .accept (this );
651+ methodDeclareStack .pop ();
619652 buffer .append (", " );
620653
621654 buffer .append ("Clazz.innerTypeInstance (" );
@@ -774,14 +807,14 @@ private void visitArgumentItem(ASTNode element,
774807 buffer .append (typeStr .replaceFirst ("^\\ $wt." , "org.eclipse.swt." ));
775808 buffer .append ("\" )" );
776809 } else {
777- boxingNode (element );
778810 Expression exp = (Expression ) element ;
779811 ITypeBinding typeBinding = exp .resolveTypeBinding ();
780812 String typeName = null ;
781813 if (typeBinding != null ) {
782814 typeName = typeBinding .getName ();
783815 }
784- if ("char" .equals (typeName ) && "int" .equals (parameterTypeName )) {
816+ int idx1 = buffer .length ();
817+ if ("char" .equals (typeName ) && !"char" .equals (parameterTypeName )) {
785818 boolean ignored = false ;
786819 /*
787820 for (int j = 0; j < ignores.length / 3; j++) {
@@ -805,9 +838,38 @@ private void visitArgumentItem(ASTNode element,
805838 ignored = (position == 0
806839 && (/*"append".equals(methodName) || */ "indexOf" .equals (methodName ) || "lastIndexOf" .equals (methodName ))
807840 && ("java.lang.String" .equals (Bindings .removeBrackets (clazzName ))));
841+
842+ if (!ignored && exp instanceof CharacterLiteral ) {
843+ CharacterLiteral cl = (CharacterLiteral ) exp ;
844+ buffer .append (0 + cl .charValue ());
845+ ignored = true ;
846+ } else {
847+ boxingNode (element );
848+ }
808849 if (!ignored ) {
809- buffer .append (".charCodeAt (0)" );
850+ boolean appendingCode = true ;
851+ int length = buffer .length ();
852+ if (exp instanceof MethodInvocation ) {
853+ MethodInvocation m = (MethodInvocation ) exp ;
854+ if ("charAt" .equals (m .getName ().toString ())) {
855+ int idx2 = buffer .indexOf (".charAt " , idx1 );
856+ if (idx2 != -1 ) {
857+ StringBuffer newMethodBuffer = new StringBuffer ();
858+ newMethodBuffer .append (buffer .substring (idx1 , idx2 ));
859+ newMethodBuffer .append (".charCodeAt " );
860+ newMethodBuffer .append (buffer .substring (idx2 + 8 , length ));
861+ buffer .delete (idx1 , length );
862+ buffer .append (newMethodBuffer .toString ());
863+ appendingCode = false ;
864+ }
865+ }
866+ }
867+ if (appendingCode ) {
868+ buffer .append (".charCodeAt (0)" );
869+ }
810870 }
871+ } else {
872+ boxingNode (element );
811873 }
812874 }
813875 }
@@ -1272,6 +1334,8 @@ && checkSameName(typeBinding, fieldName)) {
12721334 PrimitiveType pType = (PrimitiveType ) node .getType ();
12731335 if (pType .getPrimitiveTypeCode () == PrimitiveType .BOOLEAN ) {
12741336 buffer .append ("false" );
1337+ } else if (pType .getPrimitiveTypeCode () == PrimitiveType .CHAR ) {
1338+ buffer .append ("'\\ 0'" );
12751339 } else {
12761340 buffer .append ("0" );
12771341 }
@@ -1319,7 +1383,8 @@ private void charVisit(ASTNode node, boolean beCare) {
13191383 boxingNode (node );
13201384 return ;
13211385 }
1322- ITypeBinding binding = ((Expression ) node ).resolveTypeBinding ();
1386+ Expression exp = (Expression ) node ;
1387+ ITypeBinding binding = exp .resolveTypeBinding ();
13231388 if (binding .isPrimitive () && "char" .equals (binding .getName ())) {
13241389 if (node instanceof CharacterLiteral ) {
13251390 CharacterLiteral cl = (CharacterLiteral ) node ;
@@ -1328,9 +1393,31 @@ private void charVisit(ASTNode node, boolean beCare) {
13281393 boxingNode (node );
13291394 buffer .append (".charCodeAt (0)" );
13301395 } else {
1396+ int idx1 = buffer .length ();
13311397 buffer .append ("(" );
13321398 boxingNode (node );
1333- buffer .append (").charCodeAt (0)" );
1399+ buffer .append (")" );
1400+
1401+ boolean appendingCode = true ;
1402+ int length = buffer .length ();
1403+ if (exp instanceof MethodInvocation ) {
1404+ MethodInvocation m = (MethodInvocation ) exp ;
1405+ if ("charAt" .equals (m .getName ().toString ())) {
1406+ int idx2 = buffer .indexOf (".charAt " , idx1 );
1407+ if (idx2 != -1 ) {
1408+ StringBuffer newMethodBuffer = new StringBuffer ();
1409+ newMethodBuffer .append (buffer .substring (idx1 + 1 , idx2 ));
1410+ newMethodBuffer .append (".charCodeAt " );
1411+ newMethodBuffer .append (buffer .substring (idx2 + 8 , length - 1 ));
1412+ buffer .delete (idx1 , length );
1413+ buffer .append (newMethodBuffer .toString ());
1414+ appendingCode = false ;
1415+ }
1416+ }
1417+ }
1418+ if (appendingCode ) {
1419+ buffer .append (".charCodeAt (0)" );
1420+ }
13341421 }
13351422 } else {
13361423 boxingNode (node );
@@ -1353,8 +1440,9 @@ public boolean visit(InfixExpression node) {
13531440 Expression right = node .getRightOperand ();
13541441 ITypeBinding typeBinding = left .resolveTypeBinding ();
13551442
1356- if ((left instanceof SimpleName || left instanceof CharacterLiteral ) && (right instanceof SimpleName || right instanceof CharacterLiteral )
1357- && (">" .equals (operator ) || "<" .equals (operator ) || ">=" .equals (operator ) || "<=" .equals (operator ))) {
1443+ if (/*(left instanceof SimpleName || left instanceof CharacterLiteral) && (right instanceof SimpleName || right instanceof CharacterLiteral)
1444+ && */ (">" .equals (operator ) || "<" .equals (operator ) || ">=" .equals (operator ) || "<=" .equals (operator )
1445+ || "==" .equals (operator ) || "!=" .equals (operator ))) {
13581446 ITypeBinding rightBinding = right .resolveTypeBinding ();
13591447 if (typeBinding .isPrimitive () && "char" .equals (typeBinding .getName ())
13601448 && rightBinding .isPrimitive () && "char" .equals (rightBinding .getName ())) {
@@ -1374,7 +1462,9 @@ public boolean visit(InfixExpression node) {
13741462 StringBuffer tmpBuffer = buffer ;
13751463 buffer = new StringBuffer ();
13761464
1377- buffer .append ("Math.floor (" );
1465+ //buffer.append("Math.floor (");
1466+ // TODO
1467+ buffer .append ("Clazz.doubleToInt (" );
13781468 charVisit (left , beCare );
13791469 buffer .append (' ' );
13801470 buffer .append (operator );
@@ -1390,7 +1480,8 @@ public boolean visit(InfixExpression node) {
13901480 Expression exp = (Expression ) element ;
13911481 ITypeBinding expBinding = exp .resolveTypeBinding ();
13921482 if (isIntegerType (expBinding .getName ())) {
1393- buffer .insert (0 , "Math.floor (" );
1483+ //buffer.insert(0, "Math.floor (");
1484+ buffer .insert (0 , "Clazz.doubleToInt (" );
13941485 is2Floor = true ;
13951486 }
13961487 }
@@ -1650,7 +1741,11 @@ public boolean visit(MethodDeclaration node) {
16501741 }
16511742
16521743 if (node .isConstructor ()) {
1653- buffer .append ("Clazz.makeConstructor (" );
1744+ if (getJ2STag (node , "@j2sOverride" ) != null ) {
1745+ buffer .append ("Clazz.overrideConstructor (" );
1746+ } else {
1747+ buffer .append ("Clazz.makeConstructor (" );
1748+ }
16541749 } else {
16551750 if ((node .getModifiers () & Modifier .STATIC ) != 0 ) {
16561751 /* replace full class name with short variable name */
@@ -3011,7 +3106,7 @@ private String prepareSimpleSerializable(TypeDeclaration node, List bodyDeclarat
30113106 if (isSimpleSerializable ) {
30123107 List fragments = fieldDeclaration .fragments ();
30133108 int modifiers = fieldDeclaration .getModifiers ();
3014- if ((Modifier .isPublic (modifiers ) || Modifier .isProtected (modifiers ))
3109+ if ((Modifier .isPublic (modifiers )/* || Modifier.isProtected(modifiers)*/ )
30153110 && !Modifier .isStatic (modifiers ) && !Modifier .isTransient (modifiers )) {
30163111 Type type = fieldDeclaration .getType ();
30173112 int dims = 0 ;
@@ -3044,6 +3139,22 @@ private String prepareSimpleSerializable(TypeDeclaration node, List bodyDeclarat
30443139 ITypeBinding resolveBinding = type .resolveBinding ();
30453140 if ("java.lang.String" .equals (resolveBinding .getQualifiedName ())) {
30463141 mark = "s" ;
3142+ } else {
3143+ ITypeBinding t = resolveBinding ;
3144+ do {
3145+ String typeName = t .getQualifiedName ();
3146+ if ("java.lang.Object" .equals (typeName )) {
3147+ break ;
3148+ }
3149+ if ("net.sf.j2s.ajax.SimpleSerializable" .equals (typeName )) {
3150+ mark = "O" ;
3151+ break ;
3152+ }
3153+ t = t .getSuperclass ();
3154+ if (t == null ) {
3155+ break ;
3156+ }
3157+ } while (true );
30473158 }
30483159 if (mark != null ) {
30493160 for (Iterator xiter = fragments .iterator (); xiter .hasNext ();) {
0 commit comments