@@ -474,7 +474,13 @@ public boolean visit(ClassInstanceCreation node) {
474
474
}
475
475
}
476
476
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(), ", ");
478
484
buffer .append (")" );
479
485
} else {
480
486
int anonCount = ((ASTTypeVisitor ) getAdaptable (ASTTypeVisitor .class )).getAnonymousCount () + 1 ;
@@ -530,7 +536,14 @@ public boolean visit(ClassInstanceCreation node) {
530
536
if (argSize > 0 ) {
531
537
buffer .append (", " );
532
538
}
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, ", ");
534
547
buffer .append (", " );
535
548
String scope = null ;
536
549
if (methodDeclareStack .size () != 0 ) {
@@ -561,9 +574,113 @@ public boolean visit(ClassInstanceCreation node) {
561
574
return false ;
562
575
}
563
576
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
+
564
675
public boolean visit (ConstructorInvocation node ) {
565
676
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(), ", ");
567
684
buffer .append (");\r \n " );
568
685
return false ;
569
686
}
@@ -1586,8 +1703,8 @@ public boolean visit(MethodInvocation node) {
1586
1703
buffer .append (" (" );
1587
1704
1588
1705
IMethodBinding methodBinding = node .resolveMethodBinding ();
1706
+ ITypeBinding [] paramTypes = methodBinding .getParameterTypes ();
1589
1707
if (methodBinding != null && methodBinding .isVarargs ()) {
1590
- ITypeBinding [] paramTypes = methodBinding .getParameterTypes ();
1591
1708
visitList (args , ", " , 0 , paramTypes .length - 1 );
1592
1709
if (paramTypes .length - 1 > 0 ) {
1593
1710
buffer .append (", " );
@@ -1601,44 +1718,13 @@ public boolean visit(MethodInvocation node) {
1601
1718
}
1602
1719
//}
1603
1720
if (needBrackets ) buffer .append ("[" );
1721
+ //IMethodBinding methodDeclaration = node.resolveMethodBinding();
1722
+ //visitMethodParameterList(node.arguments(), methodDeclaration, paramTypes.length - 1, size);
1604
1723
visitList (args , ", " , paramTypes .length - 1 , size );
1605
1724
if (needBrackets ) buffer .append ("]" );
1606
1725
} 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 );
1642
1728
//visitList(args, ", ");
1643
1729
}
1644
1730
buffer .append (")" );
@@ -2020,7 +2106,12 @@ public boolean visit(SuperConstructorInvocation node) {
2020
2106
List arguments = node .arguments ();
2021
2107
if (arguments .size () > 0 ) {
2022
2108
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, ", ");
2024
2115
buffer .append ("]" );
2025
2116
}
2026
2117
buffer .append (");\r \n " );
@@ -2078,7 +2169,9 @@ public boolean visit(SuperMethodInvocation node) {
2078
2169
String name = getJ2SName (node .getName ());
2079
2170
buffer .append (name );
2080
2171
buffer .append ("\" , [" );
2081
- visitList (node .arguments (), ", " );
2172
+ IMethodBinding methodDeclaration = node .resolveMethodBinding ();
2173
+ visitMethodParameterList (node .arguments (), methodDeclaration );
2174
+ //visitList(node.arguments(), ", ");
2082
2175
buffer .append ("])" );
2083
2176
return false ;
2084
2177
}
0 commit comments