Skip to content

Commit a2edb24

Browse files
committed
adds Clazz.super$(cla$$,this) -- only shifts the problem of an anonymous
class using a default constructor that is really a varargs method
1 parent 76b05a2 commit a2edb24

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public boolean visit(AnonymousClassDeclaration node) {
252252
}
253253
}
254254

255-
addDefaultConstructor();
255+
//addDefaultConstructor();
256256

257257
for (Iterator<?> iter = bodyDeclarations.iterator(); iter.hasNext();) {
258258
ASTNode element = (ASTNode) iter.next();
@@ -2687,7 +2687,6 @@ public boolean visit(TypeDeclaration node) {
26872687
ITypeBinding binding = node.resolveBinding();
26882688
ASTTypeVisitor typeVisitor = ((ASTTypeVisitor) getAdaptable(ASTTypeVisitor.class));
26892689
if (binding != null && binding.isTopLevel()) {
2690-
haveDefaultConstructor = false;
26912690
typeVisitor.setClassName(binding.getName());
26922691
}
26932692
if ((node != rootTypeNode) && node.getParent() != null && (node.getParent() instanceof AbstractTypeDeclaration
@@ -2892,8 +2891,7 @@ private String getJ2SParamQualifier(IMethodBinding binding) {
28922891
private void addDefaultConstructor() {
28932892

28942893
if (!haveDefaultConstructor) {
2895-
buffer.append("\r\nClazz.newMethod$(cla$$, 'construct', function () {\r\n"); // was
2896-
// $_
2894+
buffer.append("\r\nClazz.newMethod$(cla$$, 'construct', function () {"); // was // $_
28972895
addSuperConstructor(null, null);
28982896
buffer.append("},true);\r\n");
28992897
}
@@ -2912,23 +2910,13 @@ private void addAnonymousFunctionWrapper(boolean isOpen) {
29122910

29132911
private void addSuperConstructor(SuperConstructorInvocation node, IMethodBinding methodDeclaration) {
29142912
if (node == null) {
2915-
buffer.append("if (cla$$.superClazz && cla$$.superClazz.construct) {"); // was
2916-
// $_
2917-
}
2918-
buffer.append("cla$$.superClazz.construct")
2919-
.append(node == null ? "" : getJ2SParamQualifier(node.resolveConstructorBinding())); // was
2920-
// $_
2921-
buffer.append(".apply(this");
2922-
// buffer.append(assureQualifiedName(shortenQualifiedName(getFullClassName())));
2923-
if (node != null)
2913+
buffer.append("Clazz.super$(cla$$, this");
2914+
} else {
2915+
buffer.append("cla$$.superClazz.construct").append(getJ2SParamQualifier(node.resolveConstructorBinding()));
2916+
buffer.append(".apply(this");
29242917
visitMethodParameterList(node.arguments(), methodDeclaration, true, ", [", "]");
2925-
else
2926-
buffer.append(", []");
2927-
2928-
buffer.append(");\r\n");
2929-
if (node == null) {
2930-
buffer.append("}\r\n");
29312918
}
2919+
buffer.append(");\r\n");
29322920
addCallInit();
29332921
}
29342922

0 commit comments

Comments
 (0)