Skip to content

Commit 7a0a031

Browse files
committed
Switch in visit(MethodInvocation); Java 1.7
1 parent 6ae574b commit 7a0a031

File tree

2 files changed

+84
-47
lines changed

2 files changed

+84
-47
lines changed
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
eclipse.preferences.version=1
2-
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3-
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
5-
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6-
org.eclipse.jdt.core.compiler.compliance=1.5
7-
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8-
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9-
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10-
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11-
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12-
org.eclipse.jdt.core.compiler.source=1.5
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
5+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6+
org.eclipse.jdt.core.compiler.compliance=1.7
7+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.source=1.7

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/ASTScriptVisitor.java

Lines changed: 72 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -468,19 +468,19 @@ public boolean visit(AnonymousClassDeclaration node) {
468468
methodBuffer = buffer;
469469
methodBuffer.append(methods);
470470
buffer = tmpBuffer;
471-
//SwingJS 6/14/17- Imported from master branch
472-
// ITypeBinding declareClass = binding;
473-
// boolean prefixed = false;
474-
// while (declareClass != null) {
475-
// if (!declareClass.isAnonymous()) {
476-
// buffer.append(declareClass.getQualifiedName());
477-
// prefixed = true;
478-
// }
479-
// break;
480-
// declareClass = declareClass.getDeclaringClass();
481-
// }
482-
// if (!prefixed) {
483-
String packageName = ((ASTPackageVisitor) getAdaptable(ASTPackageVisitor.class)).getPackageName();
471+
//SwingJS 6/14/17- Imported from master branch
472+
// ITypeBinding declareClass = binding;
473+
// boolean prefixed = false;
474+
// while (declareClass != null) {
475+
// if (!declareClass.isAnonymous()) {
476+
// buffer.append(declareClass.getQualifiedName());
477+
// prefixed = true;
478+
// }
479+
// break;
480+
// declareClass = declareClass.getDeclaringClass();
481+
// }
482+
// if (!prefixed) {
483+
String packageName = ((ASTPackageVisitor) getAdaptable(ASTPackageVisitor.class)).getPackageName();
484484
buffer.append(packageName);
485485
buffer.append(".");
486486
idx = className.indexOf('$');
@@ -489,7 +489,7 @@ public boolean visit(AnonymousClassDeclaration node) {
489489
} else {
490490
buffer.append(className);
491491
}
492-
// }
492+
// }
493493
buffer.append(".$");
494494
buffer.append(shortClassName);
495495
buffer.append("$ ()");
@@ -1022,7 +1022,7 @@ protected void visitMethodParameterList(List arguments, IMethodBinding methodDec
10221022

10231023

10241024

1025-
1025+
10261026
boolean alreadyPrefixed = false;
10271027
String clazzName = null;
10281028
ITypeBinding[] parameterTypes = methodDeclaration.getParameterTypes();
@@ -1458,19 +1458,19 @@ public void endVisit(EnumDeclaration node) {
14581458
}
14591459
//int anonCount = ((ASTTypeVisitor) getAdaptable(ASTTypeVisitor.class)).getAnonymousCount() + 1;
14601460

1461-
StringBuffer tmpBuffer = buffer;
1462-
StringBuffer tmpMethodBuffer = methodBuffer;
1463-
buffer = new StringBuffer();
1464-
methodBuffer = new StringBuffer();
1461+
StringBuffer tmpBuffer = buffer;
1462+
StringBuffer tmpMethodBuffer = methodBuffer;
1463+
buffer = new StringBuffer();
1464+
methodBuffer = new StringBuffer();
14651465
anonDeclare.accept(this);
14661466

1467-
tmpBuffer.append(methodBuffer);
1468-
1469-
tmpBuffer.append(buffer);
1470-
tmpBuffer.append(";\r\n");
1471-
1472-
buffer = tmpBuffer;
1473-
methodBuffer = tmpMethodBuffer;
1467+
tmpBuffer.append(methodBuffer);
1468+
1469+
tmpBuffer.append(buffer);
1470+
tmpBuffer.append(";\r\n");
1471+
1472+
buffer = tmpBuffer;
1473+
methodBuffer = tmpMethodBuffer;
14741474

14751475

14761476
buffer.append("Clazz.defineEnumConstant (");
@@ -2482,15 +2482,51 @@ private boolean containsOnlySuperCall(Block body) {
24822482
}
24832483

24842484
public boolean visit(MethodInvocation node) {
2485-
ITypeBinding nodeTypeBinding = null;
2485+
ITypeBinding nodeTypeBinding = null;
24862486
Expression expression = node.getExpression();
2487+
2488+
buffer.append("\n\n//SwingJS BH methodInvocation:" + node.resolveMethodBinding().getKey() + "\n\n");
2489+
2490+
ITypeBinding[] paramTypes = node.resolveMethodBinding().getParameterTypes();
2491+
StringBuffer sbParams = new StringBuffer();
2492+
// TODO don't want to do this with java, javax, or sun
2493+
for (int i = 0; i < paramTypes.length; i++) {
2494+
String name = paramTypes[i].getQualifiedName();
2495+
String arrays = null;
2496+
int pt = name.indexOf("[");
2497+
if (pt >= 0) {
2498+
arrays = name.substring(pt);
2499+
name = name.substring(0, pt);
2500+
}
2501+
switch (name) {
2502+
case "boolean":
2503+
name = "B";
2504+
break;
2505+
case "int":
2506+
name = "I";
2507+
break;
2508+
case "float":
2509+
name = "F";
2510+
break;
2511+
case "LJava/lang/String":
2512+
name = "S";
2513+
break;
2514+
default:
2515+
name = name.replace('/','_');
2516+
break;
2517+
}
2518+
sbParams.append("$").append(name);
2519+
if (arrays != null)
2520+
sbParams.append(arrays.replaceAll("\\[\\]", "A"));
2521+
}
2522+
24872523
if (expression != null) {
24882524
/*
24892525
* Here?
24902526
*/
24912527
expression.accept(this);
24922528
buffer.append(".");
2493-
nodeTypeBinding = node.getExpression().resolveTypeBinding();
2529+
nodeTypeBinding = node.getExpression().resolveTypeBinding();
24942530
}
24952531

24962532
String methodName = node.getName().getIdentifier();
@@ -2519,6 +2555,7 @@ public boolean visit(MethodInvocation node) {
25192555
if (!isSpecialMethod) {
25202556
node.getName().accept(this);
25212557
}
2558+
buffer.append(sbParams);
25222559
buffer.append(" (");
25232560
IMethodBinding methodDeclaration = node.resolveMethodBinding();
25242561
visitMethodParameterList(node.arguments(), methodDeclaration, false, null, null);
@@ -2773,14 +2810,14 @@ private void appendFieldName(ASTNode parent, ITypeBinding declaringClass) {
27732810
String name = declaringClass.getQualifiedName();
27742811
boolean isThis = false;
27752812
int superLevel = 0;
2776-
ITypeBinding originalType = null;
2813+
ITypeBinding originalType = null;
27772814
while (parent != null) {
27782815
if (parent instanceof AbstractTypeDeclaration) {
27792816
AbstractTypeDeclaration type = (AbstractTypeDeclaration) parent;
27802817
ITypeBinding typeBinding = type.resolveBinding();
2781-
if (typeBinding != null && originalType == null) {
2782-
originalType = typeBinding;
2783-
}
2818+
if (typeBinding != null && originalType == null) {
2819+
originalType = typeBinding;
2820+
}
27842821
superLevel++;
27852822
if (Bindings.isSuperType(declaringClass, typeBinding)) {
27862823
if (superLevel == 1) {
@@ -2794,9 +2831,9 @@ private void appendFieldName(ASTNode parent, ITypeBinding declaringClass) {
27942831
} else if (parent instanceof AnonymousClassDeclaration) {
27952832
AnonymousClassDeclaration type = (AnonymousClassDeclaration) parent;
27962833
ITypeBinding typeBinding = type.resolveBinding();
2797-
if (typeBinding != null && originalType == null) {
2798-
originalType = typeBinding;
2799-
}
2834+
if (typeBinding != null && originalType == null) {
2835+
originalType = typeBinding;
2836+
}
28002837
superLevel++;
28012838
if (Bindings.isSuperType(declaringClass, typeBinding)) {
28022839
if (superLevel == 1) {

0 commit comments

Comments
 (0)