X Tutup
Skip to content

Commit 41c4b97

Browse files
committed
Fixed bug #13 :
Duplicate static field initialization codes are generated. Generate correct b$["$..$"] inside anonymous classes Supported @j2sIgnore for anonymous classes
1 parent 8710578 commit 41c4b97

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,18 @@ public boolean visit(AnonymousClassDeclaration node) {
258258
ASTNode element = (ASTNode) iter.next();
259259
if (element instanceof FieldDeclaration) {
260260
FieldDeclaration field = (FieldDeclaration) element;
261+
if (getJ2STag(field, "@j2sIgnore") != null) {
262+
continue;
263+
}
261264
needPreparation = isFieldNeedPreparation(field);
262265
if (needPreparation) {
263266
break;
264267
}
265268
} else if (element instanceof Initializer) {
266269
Initializer init = (Initializer) element;
270+
if (getJ2STag(init, "@j2sIgnore") != null) {
271+
continue;
272+
}
267273
if ((init.getModifiers() & Modifier.STATIC) == 0) {
268274
needPreparation = true;
269275
break;
@@ -280,12 +286,21 @@ public boolean visit(AnonymousClassDeclaration node) {
280286
//}
281287
// there are no static members/methods in the inner type
282288
// but there are static final members
283-
// } else if (element instanceof Initializer) {
284-
// continue;
289+
} else if (element instanceof Initializer) {
290+
Initializer init = (Initializer) element;
291+
if (getJ2STag(init, "@j2sIgnore") != null) {
292+
continue;
293+
}
294+
if ((init.getModifiers() & Modifier.STATIC) == 0) {
295+
continue;
296+
}
285297
} else if (element instanceof FieldDeclaration
286298
/*&& isFieldNeedPreparation((FieldDeclaration) element)*/) {
287299
// continue;
288300
FieldDeclaration fieldDeclaration = (FieldDeclaration) element;
301+
if (getJ2STag(fieldDeclaration, "@j2sIgnore") != null) {
302+
continue;
303+
}
289304
if (isFieldNeedPreparation(fieldDeclaration)) {
290305
visitWith(fieldDeclaration, true);
291306
continue;
@@ -365,12 +380,18 @@ public boolean visit(AnonymousClassDeclaration node) {
365380
ASTNode element = (ASTNode) iter.next();
366381
if (element instanceof FieldDeclaration) {
367382
FieldDeclaration field = (FieldDeclaration) element;
383+
if (getJ2STag(field, "@j2sIgnore") != null) {
384+
continue;
385+
}
368386
if (!isFieldNeedPreparation(field)) {
369387
continue;
370388
}
371389
element.accept(this);
372390
} else if (element instanceof Initializer) {
373391
Initializer init = (Initializer) element;
392+
if (getJ2STag(init, "@j2sIgnore") != null) {
393+
continue;
394+
}
374395
if ((init.getModifiers() & Modifier.STATIC) == 0) {
375396
element.accept(this);
376397
}
@@ -1804,6 +1825,7 @@ public boolean visit(Initializer node) {
18041825
}
18051826
//visitList(node.getBody().statements(), "\r\n");
18061827
node.getBody().accept(this);
1828+
buffer.append("\r\n");
18071829
return false;
18081830
}
18091831

@@ -2723,9 +2745,9 @@ private void appendFieldName(ASTNode parent, ITypeBinding declaringClass) {
27232745
}
27242746
}
27252747
String binaryName = declaringClass.getBinaryName();
2726-
int idx = levels.lastIndexOf(binaryName);
2748+
int idx = levels.indexOf(binaryName);
27272749
if (idx == -1) {
2728-
idx = classes.lastIndexOf(binaryName);
2750+
idx = classes.indexOf(binaryName);
27292751
if (idx == -1) {
27302752
// Check each super class
27312753
int index = 0;

0 commit comments

Comments
 (0)
X Tutup