Skip to content

Commit 9551dfa

Browse files
author
zhourenjian
committed
1. Fixing bug that Hashtable's private method #nextKey is not kept
2. Fixing bug that @j2sNativeSrc's variable name is not correct 3. Remove all method invocations for jface's *.Assert classes 4. Fixing bug that @J2SNative does not support multiple lines of codes
1 parent 21e86cf commit 9551dfa

File tree

6 files changed

+130
-23
lines changed

6 files changed

+130
-23
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ boolean readSources(BodyDeclaration node, String tagName, String prefix, String
261261
buf.append(lines[j]);
262262
buf.append("\r\n");
263263
}
264+
} else if (value instanceof String) {
265+
buf.append(value);
266+
buf.append("\r\n");
264267
}
265268
}
266269
}

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ protected void visitMethodParameterList(List arguments,
629629
typeName = typeBinding.getName();
630630
}
631631
String parameterTypeName = null;
632-
if (parameterTypes != null) {
632+
if (parameterTypes != null && parameterTypes.length > i) { // parameterTypes.length <= i, incorrect method invocation
633633
parameterTypeName = parameterTypes[i].getName();
634634
}
635635
if ("char".equals(typeName) && "int".equals(parameterTypeName)) {
@@ -1257,6 +1257,7 @@ public void endVisit(MethodDeclaration node) {
12571257
"through",
12581258
"pipeMonitoring",
12591259
"pipeMonitoringInterval",
1260+
"pipeWaitClosingInterval",
12601261
"setPipeHelper"
12611262
};
12621263
for (int i = 0; i < pipeMethods.length; i++) {
@@ -1298,6 +1299,7 @@ public boolean visit(MethodDeclaration node) {
12981299
"through",
12991300
"pipeMonitoring",
13001301
"pipeMonitoringInterval",
1302+
"pipeWaitClosingInterval",
13011303
"setPipeHelper"
13021304
};
13031305
for (int i = 0; i < pipeMethods.length; i++) {
@@ -1508,15 +1510,15 @@ public boolean visit(MethodDeclaration node) {
15081510
if (!read) {
15091511
buffer.append("{\r\n");
15101512
visitNativeJavadoc(node.getJavadoc(), null, false);
1511-
List normalVars = ((ASTVariableVisitor) getAdaptable(ASTVariableVisitor.class)).normalVars;
1512-
for (int i = normalVars.size() - 1; i >= 0; i--) {
1513-
ASTFinalVariable var = (ASTFinalVariable) normalVars.get(i);
1514-
if (var.blockLevel >= blockLevel) {
1515-
normalVars.remove(i);
1516-
}
1517-
}
15181513
buffer.append("}");
15191514
}
1515+
List normalVars = ((ASTVariableVisitor) getAdaptable(ASTVariableVisitor.class)).normalVars;
1516+
for (int i = normalVars.size() - 1; i >= 0; i--) {
1517+
ASTFinalVariable var = (ASTFinalVariable) normalVars.get(i);
1518+
if (var.blockLevel >= blockLevel) {
1519+
normalVars.remove(i);
1520+
}
1521+
}
15201522
blockLevel--;
15211523
} else {
15221524
boolean read = checkJ2STags(node, true);
@@ -1667,7 +1669,16 @@ private boolean containsOnlySuperCall(Block body) {
16671669
boolean isFiltered = false;
16681670
IMethodBinding methodBinding = method.resolveMethodBinding();
16691671
for (int j = 0; j < filterMethods.length; j += 2) {
1670-
if (Bindings.isMethodInvoking(methodBinding, filterMethods[j], filterMethods[j + 1])) {
1672+
if ("*".equals(filterMethods[i + 1])) {
1673+
if (methodBinding == null) {
1674+
continue;
1675+
}
1676+
ITypeBinding type = methodBinding.getDeclaringClass();
1677+
if (type != null && filterMethods[i].equals(type.getQualifiedName())) {
1678+
isFiltered = true;
1679+
break;
1680+
}
1681+
} else if (Bindings.isMethodInvoking(methodBinding, filterMethods[j], filterMethods[j + 1])) {
16711682
isFiltered = true;
16721683
break;
16731684
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,7 @@ public boolean visit(MethodDeclaration node) {
10061006
"through",
10071007
"pipeMonitoring",
10081008
"pipeMonitoringInterval",
1009+
"pipeWaitClosingInterval",
10091010
"setPipeHelper"
10101011
};
10111012
for (int i = 0; i < pipeMethods.length; i++) {
@@ -1024,6 +1025,13 @@ public boolean visit(MethodDeclaration node) {
10241025
return false;
10251026
}
10261027

1028+
if (getJ2STag(node, "@j2sNative") != null) {
1029+
return false;
1030+
}
1031+
if (getJ2STag(node, "@j2sNativeSrc") != null) {
1032+
return false;
1033+
}
1034+
10271035
if (getJ2STag(node, "@j2sIgnore") != null) {
10281036
return false;
10291037
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public class MethodReferenceASTVisitor extends ASTVisitor {
4141

4242
private MethodReferenceASTVisitor(String methodSignature) {
4343
super();
44-
this.methodSignature = methodSignature.replaceAll("<[^>]+>", "");
44+
this.methodSignature = methodSignature.replaceAll("%?<[^>]+>", "");
4545
}
4646

4747
public static boolean checkReference(ASTNode node, String methodSignature) {
@@ -62,7 +62,7 @@ public boolean visit(ClassInstanceCreation node) {
6262
if (constructorBinding != null) {
6363
String key = constructorBinding.getKey();
6464
if (key != null) {
65-
key = key.replaceAll("<[^>]+>", "");
65+
key = key.replaceAll("%?<[^>]+>", "");
6666
}
6767
if (methodSignature.equals(key)) {
6868
isReferenced = true;
@@ -79,7 +79,7 @@ public boolean visit(ConstructorInvocation node) {
7979
IMethodBinding constructorBinding = node.resolveConstructorBinding();
8080
String key = constructorBinding.getKey();
8181
if (key != null) {
82-
key = key.replaceAll("<[^>]+>", "");
82+
key = key.replaceAll("%?<[^>]+>", "");
8383
}
8484
if (methodSignature.equals(key)) {
8585
isReferenced = true;
@@ -96,7 +96,7 @@ public boolean visit(MethodInvocation node) {
9696
if (methodBinding != null) {
9797
String key = methodBinding.getKey();
9898
if (key != null) {
99-
key = key.replaceAll("<[^>]+>", "");
99+
key = key.replaceAll("%?<[^>]+>", "");
100100
}
101101
if (methodSignature.equals(key)) {
102102
isReferenced = true;
@@ -115,7 +115,7 @@ public boolean visit(SuperMethodInvocation node) {
115115
if (methodBinding != null) {
116116
key = methodBinding.getKey();
117117
if (key != null) {
118-
key = key.replaceAll("<[^>]+>", "");
118+
key = key.replaceAll("%?<[^>]+>", "");
119119
}
120120
}
121121
if (methodSignature.equals(key)) {
@@ -180,6 +180,7 @@ public boolean visit(MethodDeclaration node) {
180180
"through",
181181
"pipeMonitoring",
182182
"pipeMonitoringInterval",
183+
"pipeWaitClosingInterval",
183184
"setPipeHelper"
184185
};
185186
for (int i = 0; i < pipeMethods.length; i++) {

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

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,74 @@ protected String[] getFilterMethods() {
3535
"org.eclipse.swt.widgets.Dialog", "checkSubclass",
3636
"org.eclipse.swt.widgets.Widget", "checkWidget",
3737
"org.eclipse.swt.widgets.Display", "checkDevice",
38-
"org.eclipse.swt.graphics.Device", "checkDevice"
38+
"org.eclipse.swt.graphics.Device", "checkDevice",
39+
"org.eclipse.jface.util.Assert", "*",
40+
"org.eclipse.core.internal.commands.util.Assert", "*",
41+
"org.eclipse.core.internal.runtime.Assert", "*"
3942
};
4043
}
4144

45+
/* (non-Javadoc)
46+
* @see net.sf.j2s.core.astvisitors.ASTScriptVisitor#visit(org.eclipse.jdt.core.dom.MethodInvocation)
47+
*/
48+
public boolean visit(MethodInvocation node) {
49+
IMethodBinding methodBinding = node.resolveMethodBinding();
50+
String[] filterMethods = getFilterMethods();
51+
for (int i = 0; i < filterMethods.length; i += 2) {
52+
if ("*".equals(filterMethods[i + 1])) {
53+
if (methodBinding == null) {
54+
continue;
55+
}
56+
ITypeBinding type = methodBinding.getDeclaringClass();
57+
if (type != null && filterMethods[i].equals(type.getQualifiedName())) {
58+
return false;
59+
}
60+
} else if (Bindings.isMethodInvoking(methodBinding, filterMethods[i], filterMethods[i + 1])) {
61+
return false;
62+
}
63+
}
64+
return super.visit(node);
65+
}
66+
67+
/* (non-Javadoc)
68+
* @see net.sf.j2s.core.astvisitors.ASTScriptVisitor#visit(org.eclipse.jdt.core.dom.MethodDeclaration)
69+
*/
70+
public boolean visit(MethodDeclaration node) {
71+
IMethodBinding methodBinding = node.resolveBinding();
72+
String[] filterMethods = getFilterMethods();
73+
for (int i = 0; i < filterMethods.length; i += 2) {
74+
if ("*".equals(filterMethods[i + 1])) {
75+
if (methodBinding == null) {
76+
continue;
77+
}
78+
ITypeBinding type = methodBinding.getDeclaringClass();
79+
if (type != null && filterMethods[i].equals(type.getQualifiedName())) {
80+
return false;
81+
}
82+
} else if (Bindings.isMethodInvoking(methodBinding, filterMethods[i], filterMethods[i + 1])) {
83+
return false;
84+
}
85+
}
86+
return super.visit(node);
87+
}
88+
4289
/* (non-Javadoc)
4390
* @see net.sf.j2s.core.astvisitors.ASTScriptVisitor#endVisit(org.eclipse.jdt.core.dom.MethodDeclaration)
4491
*/
4592
public void endVisit(MethodDeclaration node) {
4693
IMethodBinding methodBinding = node.resolveBinding();
4794
String[] filterMethods = getFilterMethods();
4895
for (int i = 0; i < filterMethods.length; i += 2) {
49-
if (isMethodInvoking(methodBinding, filterMethods[i], filterMethods[i + 1])) {
50-
return ;
96+
if ("*".equals(filterMethods[i + 1])) {
97+
if (methodBinding == null) {
98+
continue;
99+
}
100+
ITypeBinding type = methodBinding.getDeclaringClass();
101+
if (type != null && filterMethods[i].equals(type.getQualifiedName())) {
102+
return;
103+
}
104+
} else if (isMethodInvoking(methodBinding, filterMethods[i], filterMethods[i + 1])) {
105+
return;
51106
}
52107
}
53108
super.endVisit(node);

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

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ protected String[] getFilterMethods() {
274274
"org.eclipse.swt.widgets.Dialog", "checkSubclass",
275275
"org.eclipse.swt.widgets.Widget", "checkWidget",
276276
"org.eclipse.swt.widgets.Display", "checkDevice",
277-
"org.eclipse.swt.graphics.Device", "checkDevice"
277+
"org.eclipse.swt.graphics.Device", "checkDevice",
278+
"org.eclipse.jface.util.Assert", "*",
279+
"org.eclipse.core.internal.commands.util.Assert", "*",
280+
"org.eclipse.core.internal.runtime.Assert", "*"
278281
};
279282
}
280283
/* (non-Javadoc)
@@ -352,7 +355,15 @@ public boolean visit(MethodInvocation node) {
352355
}
353356
String[] filterMethods = getFilterMethods();
354357
for (int i = 0; i < filterMethods.length; i += 2) {
355-
if (Bindings.isMethodInvoking(methodBinding, filterMethods[i], filterMethods[i + 1])) {
358+
if ("*".equals(filterMethods[i + 1])) {
359+
if (methodBinding == null) {
360+
continue;
361+
}
362+
ITypeBinding type = methodBinding.getDeclaringClass();
363+
if (type != null && filterMethods[i].equals(type.getQualifiedName())) {
364+
return false;
365+
}
366+
} else if (Bindings.isMethodInvoking(methodBinding, filterMethods[i], filterMethods[i + 1])) {
356367
return false;
357368
}
358369
}
@@ -365,8 +376,16 @@ public void endVisit(MethodDeclaration node) {
365376
IMethodBinding methodBinding = node.resolveBinding();
366377
String[] filterMethods = getFilterMethods();
367378
for (int i = 0; i < filterMethods.length; i += 2) {
368-
if (Bindings.isMethodInvoking(methodBinding, filterMethods[i], filterMethods[i + 1])) {
369-
return ;
379+
if ("*".equals(filterMethods[i + 1])) {
380+
if (methodBinding == null) {
381+
continue;
382+
}
383+
ITypeBinding type = methodBinding.getDeclaringClass();
384+
if (type != null && filterMethods[i].equals(type.getQualifiedName())) {
385+
return;
386+
}
387+
} else if (Bindings.isMethodInvoking(methodBinding, filterMethods[i], filterMethods[i + 1])) {
388+
return;
370389
}
371390
}
372391
super.endVisit(node);
@@ -379,7 +398,15 @@ public boolean visit(MethodDeclaration node) {
379398
IMethodBinding methodBinding = node.resolveBinding();
380399
String[] filterMethods = getFilterMethods();
381400
for (int i = 0; i < filterMethods.length; i += 2) {
382-
if (Bindings.isMethodInvoking(methodBinding, filterMethods[i], filterMethods[i + 1])) {
401+
if ("*".equals(filterMethods[i + 1])) {
402+
if (methodBinding == null) {
403+
continue;
404+
}
405+
ITypeBinding type = methodBinding.getDeclaringClass();
406+
if (type != null && filterMethods[i].equals(type.getQualifiedName())) {
407+
return false;
408+
}
409+
} else if (Bindings.isMethodInvoking(methodBinding, filterMethods[i], filterMethods[i + 1])) {
383410
return false;
384411
}
385412
}
@@ -407,7 +434,9 @@ public boolean visit(Block node) {
407434
String[] filterMethods = getFilterMethods();
408435
boolean isContinue = false;
409436
for (int i = 0; i < filterMethods.length; i += 2) {
410-
if (Bindings.isMethodInvoking(exp, filterMethods[i], filterMethods[i + 1])) {
437+
if ("*".equals(filterMethods[i + 1])) {
438+
continue;
439+
} else if (Bindings.isMethodInvoking(exp, filterMethods[i], filterMethods[i + 1])) {
411440
isContinue = true;
412441
break;
413442
}

0 commit comments

Comments
 (0)