@@ -474,7 +474,13 @@ public boolean visit(ClassInstanceCreation node) {
474474 }
475475 }
476476 buffer .append (" (" );
477- visitList (node .arguments (), ", " );
477+ IMethodBinding methodDeclaration = null ;
478+ IMethodBinding constructorBinding = node .resolveConstructorBinding ();
479+ if (constructorBinding != null ) {
480+ methodDeclaration = constructorBinding .getMethodDeclaration ();
481+ }
482+ visitMethodParameterList (node .arguments (), methodDeclaration );
483+ //visitList(node.arguments(), ", ");
478484 buffer .append (")" );
479485 } else {
480486 int anonCount = ((ASTTypeVisitor ) getAdaptable (ASTTypeVisitor .class )).getAnonymousCount () + 1 ;
@@ -530,7 +536,14 @@ public boolean visit(ClassInstanceCreation node) {
530536 if (argSize > 0 ) {
531537 buffer .append (", " );
532538 }
533- visitList (arguments , ", " );
539+ IMethodBinding methodDeclaration = null ;
540+ IMethodBinding constructorBinding = node .resolveConstructorBinding ();
541+ if (constructorBinding != null ) {
542+ methodDeclaration = constructorBinding .getMethodDeclaration ();
543+ }
544+ visitMethodParameterList (node .arguments (), methodDeclaration );
545+
546+ //visitList(arguments, ", ");
534547 buffer .append (", " );
535548 String scope = null ;
536549 if (methodDeclareStack .size () != 0 ) {
@@ -561,9 +574,113 @@ public boolean visit(ClassInstanceCreation node) {
561574 return false ;
562575 }
563576
577+ protected void visitMethodParameterList (List arguments ,
578+ IMethodBinding methodDeclaration , int begin , int end ) {
579+ ITypeBinding [] parameterTypes = null ;
580+ String clazzName = null ;
581+ String methodName = null ;
582+ /*
583+ Object[] ignores = new Object[] {
584+ "java.lang.String", "indexOf", new int[] { 0 },
585+ "java.lang.String", "lastIndexOf", new int[] { 0 },
586+ "java.lang.StringBuffer", "append", new int[] { 0 },
587+ "java.lang.StringBuilder", "append", new int[] { 0 }
588+ };
589+ */
590+ if (methodDeclaration != null ) {
591+ parameterTypes = methodDeclaration .getParameterTypes ();
592+ ITypeBinding declaringClass = methodDeclaration .getDeclaringClass ();
593+ if (declaringClass != null ) {
594+ clazzName = declaringClass .getQualifiedName ();
595+ }
596+ methodName = methodDeclaration .getName ();
597+ }
598+ for (int i = begin ; i < end ; i ++) {
599+ ASTNode element = (ASTNode ) arguments .get (i );
600+ String typeStr = null ;
601+ if (element instanceof CastExpression ) {
602+ CastExpression castExp = (CastExpression ) element ;
603+ Expression exp = castExp .getExpression ();
604+ if (exp instanceof NullLiteral ) {
605+ ITypeBinding nullTypeBinding = castExp .resolveTypeBinding ();
606+ if (nullTypeBinding != null ) {
607+ if (nullTypeBinding .isArray ()) {
608+ typeStr = "Array" ;
609+ } else if (nullTypeBinding .isPrimitive ()) {
610+ Code code = PrimitiveType .toCode (nullTypeBinding .getName ());
611+ if (code == PrimitiveType .BOOLEAN ) {
612+ typeStr = "Boolean" ;
613+ } else {
614+ typeStr = "Number" ;
615+ }
616+ } else if (!nullTypeBinding .isTypeVariable ()) {
617+ typeStr = assureQualifiedName (shortenQualifiedName (nullTypeBinding .getQualifiedName ()));
618+ }
619+ }
620+ }
621+ }
622+ if (typeStr != null ) {
623+ buffer .append ("Clazz.castNullAs (\" " );
624+ buffer .append (typeStr );
625+ buffer .append ("\" )" );
626+ } else {
627+ boxingNode (element );
628+ Expression exp = (Expression ) element ;
629+ ITypeBinding typeBinding = exp .resolveTypeBinding ();
630+ String typeName = typeBinding .getName ();
631+ String parameterTypeName = null ;
632+ if (parameterTypes != null ) {
633+ parameterTypeName = parameterTypes [i ].getName ();
634+ }
635+ if ("char" .equals (typeName ) && "int" .equals (parameterTypeName )) {
636+ boolean ignored = false ;
637+ /*
638+ for (int j = 0; j < ignores.length / 3; j++) {
639+ int[] indexes = (int[]) ignores[i + i + i + 2];
640+ boolean existed = false;
641+ for (int k = 0; k < indexes.length; k++) {
642+ if (indexes[k] == i) {
643+ existed = true;
644+ break;
645+ }
646+ }
647+ if (existed) {
648+ if (ignores[0].equals(Bindings.removeBrackets(clazzName)) && ignores[1].equals(methodName)) {
649+ ignored = true;
650+ break;
651+ }
652+ }
653+ }
654+ */
655+ // Keep String#indexOf(int) and String#lastIndexOf(int)'s first char argument
656+ ignored = (i == 0
657+ && (/*"append".equals(methodName) || */ "indexOf" .equals (methodName ) || "lastIndexOf" .equals (methodName ))
658+ && ("java.lang.String" .equals (Bindings .removeBrackets (clazzName ))));
659+ if (!ignored ) {
660+ buffer .append (".charCodeAt (0)" );
661+ }
662+ }
663+ }
664+ if (i < end - 1 ) {
665+ buffer .append (", " );
666+ }
667+ }
668+ }
669+
670+ protected void visitMethodParameterList (List arguments ,
671+ IMethodBinding methodDeclaration ) {
672+ visitMethodParameterList (arguments , methodDeclaration , 0 , arguments .size ());
673+ }
674+
564675 public boolean visit (ConstructorInvocation node ) {
565676 buffer .append ("this.construct (" );
566- visitList (node .arguments (), ", " );
677+ IMethodBinding methodDeclaration = null ;
678+ IMethodBinding constructorBinding = node .resolveConstructorBinding ();
679+ if (constructorBinding != null ) {
680+ methodDeclaration = constructorBinding .getMethodDeclaration ();
681+ }
682+ visitMethodParameterList (node .arguments (), methodDeclaration );
683+ //visitList(node.arguments(), ", ");
567684 buffer .append (");\r \n " );
568685 return false ;
569686 }
@@ -1586,8 +1703,8 @@ public boolean visit(MethodInvocation node) {
15861703 buffer .append (" (" );
15871704
15881705 IMethodBinding methodBinding = node .resolveMethodBinding ();
1706+ ITypeBinding [] paramTypes = methodBinding .getParameterTypes ();
15891707 if (methodBinding != null && methodBinding .isVarargs ()) {
1590- ITypeBinding [] paramTypes = methodBinding .getParameterTypes ();
15911708 visitList (args , ", " , 0 , paramTypes .length - 1 );
15921709 if (paramTypes .length - 1 > 0 ) {
15931710 buffer .append (", " );
@@ -1601,44 +1718,13 @@ public boolean visit(MethodInvocation node) {
16011718 }
16021719 //}
16031720 if (needBrackets ) buffer .append ("[" );
1721+ //IMethodBinding methodDeclaration = node.resolveMethodBinding();
1722+ //visitMethodParameterList(node.arguments(), methodDeclaration, paramTypes.length - 1, size);
16041723 visitList (args , ", " , paramTypes .length - 1 , size );
16051724 if (needBrackets ) buffer .append ("]" );
16061725 } else {
1607- for (Iterator iter = args .iterator (); iter .hasNext ();) {
1608- ASTNode element = (ASTNode ) iter .next ();
1609- String typeStr = null ;
1610- if (element instanceof CastExpression ) {
1611- CastExpression castExp = (CastExpression ) element ;
1612- Expression exp = castExp .getExpression ();
1613- if (exp instanceof NullLiteral ) {
1614- ITypeBinding nullTypeBinding = castExp .resolveTypeBinding ();
1615- if (nullTypeBinding != null ) {
1616- if (nullTypeBinding .isArray ()) {
1617- typeStr = "Array" ;
1618- } else if (nullTypeBinding .isPrimitive ()) {
1619- Code code = PrimitiveType .toCode (nullTypeBinding .getName ());
1620- if (code == PrimitiveType .BOOLEAN ) {
1621- typeStr = "Boolean" ;
1622- } else {
1623- typeStr = "Number" ;
1624- }
1625- } else if (!nullTypeBinding .isTypeVariable ()) {
1626- typeStr = assureQualifiedName (shortenQualifiedName (nullTypeBinding .getQualifiedName ()));
1627- }
1628- }
1629- }
1630- }
1631- if (typeStr != null ) {
1632- buffer .append ("Clazz.castNullAs (\" " );
1633- buffer .append (typeStr );
1634- buffer .append ("\" )" );
1635- } else {
1636- boxingNode (element );
1637- }
1638- if (iter .hasNext ()) {
1639- buffer .append (", " );
1640- }
1641- }
1726+ IMethodBinding methodDeclaration = node .resolveMethodBinding ();
1727+ visitMethodParameterList (node .arguments (), methodDeclaration );
16421728 //visitList(args, ", ");
16431729 }
16441730 buffer .append (")" );
@@ -2020,7 +2106,12 @@ public boolean visit(SuperConstructorInvocation node) {
20202106 List arguments = node .arguments ();
20212107 if (arguments .size () > 0 ) {
20222108 buffer .append (", [" );
2023- visitList (arguments , ", " );
2109+ IMethodBinding methodDeclaration = null ;
2110+ if (constructorBinding != null ) {
2111+ methodDeclaration = constructorBinding .getMethodDeclaration ();
2112+ }
2113+ visitMethodParameterList (arguments , methodDeclaration );
2114+ //visitList(arguments, ", ");
20242115 buffer .append ("]" );
20252116 }
20262117 buffer .append (");\r \n " );
@@ -2078,7 +2169,9 @@ public boolean visit(SuperMethodInvocation node) {
20782169 String name = getJ2SName (node .getName ());
20792170 buffer .append (name );
20802171 buffer .append ("\" , [" );
2081- visitList (node .arguments (), ", " );
2172+ IMethodBinding methodDeclaration = node .resolveMethodBinding ();
2173+ visitMethodParameterList (node .arguments (), methodDeclaration );
2174+ //visitList(node.arguments(), ", ");
20822175 buffer .append ("])" );
20832176 return false ;
20842177 }
0 commit comments