Skip to content

Commit d77068e

Browse files
author
zhourenjian
committed
Fixed bugs on dealing "int.class" or so TypeLiteral.
And Fixed bug that "Object ..." is not correctly wrapped with "[]" on the argument of "new Object [] {...}".
1 parent 22c47a5 commit d77068e

File tree

3 files changed

+65
-7
lines changed

3 files changed

+65
-7
lines changed

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,9 +1435,17 @@ public boolean visit(MethodInvocation node) {
14351435
if (paramTypes.length - 1 > 0) {
14361436
buffer.append(", ");
14371437
}
1438-
buffer.append("[");
1438+
boolean needBrackets = true;
1439+
if (args.size() == 1) {
1440+
Expression arg = (Expression) args.get(0);
1441+
ITypeBinding resolveTypeBinding = arg.resolveTypeBinding();
1442+
if (resolveTypeBinding.isArray()) {
1443+
needBrackets = false;
1444+
}
1445+
}
1446+
if (needBrackets) buffer.append("[");
14391447
visitList(args, ", ", paramTypes.length - 1, size);
1440-
buffer.append("]");
1448+
if (needBrackets) buffer.append("]");
14411449
} else {
14421450
for (Iterator iter = args.iterator(); iter.hasNext();) {
14431451
ASTNode element = (ASTNode) iter.next();
@@ -2548,7 +2556,22 @@ public static void main(String[] args) {
25482556
}
25492557

25502558
public boolean visit(TypeLiteral node) {
2551-
node.getType().accept(this);
2559+
Type type = node.getType();
2560+
if (type.isPrimitiveType()) {
2561+
ITypeBinding resolveBinding = type.resolveBinding();
2562+
String name = resolveBinding.getName();
2563+
if ("boolean".equals(name)) {
2564+
buffer.append("Boolean");
2565+
return false;
2566+
} else { // TODO: More types? Integer, Long, Double, ... ?
2567+
buffer.append("Number");
2568+
return false;
2569+
}
2570+
} else if (type.isArrayType()) {
2571+
buffer.append("Array");
2572+
return false;
2573+
}
2574+
type.accept(this);
25522575
return false;
25532576
}
25542577

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ protected void checkSuperType(Set set) {
108108
for (Iterator iterator = classBindingSet.iterator(); iterator
109109
.hasNext();) {
110110
ITypeBinding binding = (ITypeBinding) iterator.next();
111-
if (Bindings.isSuperType(binding, qn.binding)) {
111+
if (qn.binding != null && Bindings.isSuperType(binding, qn.binding)) {
112112
removed.add(qn);
113113
isRemoved = true;
114114
break;
@@ -126,11 +126,38 @@ protected void checkSuperType(Set set) {
126126
set.add(qn.qualifiedName);
127127
}
128128
}
129+
130+
131+
protected void remedyReflectionDependency(Set set) {
132+
boolean needRemedy = false;;
133+
for (Iterator iterator = set.iterator(); iterator.hasNext();) {
134+
Object next = iterator.next();
135+
String name = null;
136+
if (next instanceof QNTypeBinding) {
137+
QNTypeBinding qn = (QNTypeBinding) next;
138+
name = qn.qualifiedName;
139+
} else {
140+
name = (String) next;
141+
}
142+
if ("net.sf.j2s.ajax.AClass".equals(name)
143+
|| "net.sf.j2s.ajax.ASWTClass".equals(name)) {
144+
needRemedy = true;
145+
break;
146+
}
147+
}
148+
if (needRemedy) {
149+
set.add("java.lang.reflect.Constructor");
150+
}
151+
}
152+
129153
public String getDependencyScript(StringBuffer mainJS) {
130154
checkSuperType(musts);
131155
checkSuperType(requires);
132156
checkSuperType(optionals);
133-
157+
remedyReflectionDependency(musts);
158+
remedyReflectionDependency(requires);
159+
remedyReflectionDependency(optionals);
160+
134161
musts.remove("");
135162
requires.remove("");
136163
optionals.remove("");
@@ -449,6 +476,15 @@ public boolean isClassKnown(String qualifiedName) {
449476
public boolean isQualifiedNameOK(String qualifiedName, ASTNode node) {
450477
if (qualifiedName != null
451478
&& !isClassKnown(qualifiedName)
479+
&& qualifiedName.indexOf('[') == -1
480+
&& !"int".equals(qualifiedName)
481+
&& !"float".equals(qualifiedName)
482+
&& !"double".equals(qualifiedName)
483+
&& !"long".equals(qualifiedName)
484+
&& !"short".equals(qualifiedName)
485+
&& !"byte".equals(qualifiedName)
486+
&& !"char".equals(qualifiedName)
487+
&& !"boolean".equals(qualifiedName)
452488
&& !qualifiedName.startsWith("org.w3c.dom.")
453489
&& !qualifiedName.startsWith("org.eclipse.swt.internal.xhtml.")) {
454490
ASTNode root = node.getRoot();
@@ -573,7 +609,7 @@ protected void visitForRequires(AbstractTypeDeclaration node) {
573609
}
574610
}
575611
}
576-
612+
577613
private DependencyASTVisitor getSelfVisitor() {
578614
try {
579615
Object obj = this.getClass().getConstructor(new Class[0]).newInstance(new Object[0]);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ public class MethodReferenceASTVisitor extends ASTVisitor {
3434
private MethodReferenceASTVisitor(String methodSignature) {
3535
super();
3636
this.methodSignature = methodSignature;
37-
System.out.println("visitor:" + methodSignature);
3837
}
3938

4039
public static boolean checkReference(ASTNode node, String methodSignature) {

0 commit comments

Comments
 (0)