Skip to content

Commit 05f375e

Browse files
author
zhourenjian
committed
Support @j2sIgnore for fields and initializer blocks
1 parent 15aa520 commit 05f375e

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2253,9 +2253,15 @@ public void endVisit(TypeDeclaration node) {
22532253
for (Iterator iter = node.bodyDeclarations().iterator(); iter.hasNext();) {
22542254
ASTNode element = (ASTNode) iter.next();
22552255
if (element instanceof Initializer) {
2256+
if (getJ2STag((Initializer) element, "@j2sIgnore") != null) {
2257+
continue;
2258+
}
22562259
needReturn = true;
22572260
} else if (element instanceof FieldDeclaration) {
22582261
FieldDeclaration field = (FieldDeclaration) element;
2262+
if (getJ2STag(field, "@j2sIgnore") != null) {
2263+
continue;
2264+
}
22592265
if ((field.getModifiers() & Modifier.STATIC) != 0) {
22602266
needReturn = true;
22612267
} else if (node.isInterface()) {
@@ -2371,12 +2377,18 @@ public void endVisit(TypeDeclaration node) {
23712377
ASTNode element = (ASTNode) iter.next();
23722378
if (element instanceof FieldDeclaration) {
23732379
FieldDeclaration field = (FieldDeclaration) element;
2380+
if (getJ2STag(field, "@j2sIgnore") != null) {
2381+
continue;
2382+
}
23742383
needPreparation = isFieldNeedPreparation(field);
23752384
if (needPreparation) {
23762385
break;
23772386
}
23782387
} else if (element instanceof Initializer) {
23792388
Initializer init = (Initializer) element;
2389+
if (getJ2STag(init, "@j2sIgnore") != null) {
2390+
continue;
2391+
}
23802392
if ((init.getModifiers() & Modifier.STATIC) == 0) {
23812393
needPreparation = true;
23822394
break;
@@ -2389,12 +2401,18 @@ public void endVisit(TypeDeclaration node) {
23892401
ASTNode element = (ASTNode) iter.next();
23902402
if (element instanceof FieldDeclaration) {
23912403
FieldDeclaration field = (FieldDeclaration) element;
2404+
if (getJ2STag(field, "@j2sIgnore") != null) {
2405+
continue;
2406+
}
23922407
if (node.isInterface() || !isFieldNeedPreparation(field)) {
23932408
continue;
23942409
}
23952410
element.accept(this);
23962411
} else if (element instanceof Initializer) {
23972412
Initializer init = (Initializer) element;
2413+
if (getJ2STag(init, "@j2sIgnore") != null) {
2414+
continue;
2415+
}
23982416
if ((init.getModifiers() & Modifier.STATIC) == 0) {
23992417
element.accept(this);
24002418
}
@@ -2430,6 +2448,9 @@ public void endVisit(TypeDeclaration node) {
24302448
element.accept(this);
24312449
}
24322450
} else if (element instanceof Initializer) {
2451+
if (getJ2STag((Initializer) element, "@j2sIgnore") != null) {
2452+
continue;
2453+
}
24332454
if (staticCount != -1) {
24342455
buffer.append(");\r\n");
24352456
staticCount = -1;
@@ -2441,6 +2462,9 @@ public void endVisit(TypeDeclaration node) {
24412462
}
24422463
} else if (element instanceof FieldDeclaration) {
24432464
FieldDeclaration field = (FieldDeclaration) element;
2465+
if (getJ2STag(field, "@j2sIgnore") != null) {
2466+
continue;
2467+
}
24442468
if ((field.getModifiers() & Modifier.STATIC) != 0) {
24452469
List fragments = field.fragments();
24462470
for (int j = 0; j < fragments.size(); j++) {
@@ -2786,6 +2810,9 @@ public static void main(String[] args) {
27862810
continue;
27872811
}
27882812
FieldDeclaration fieldDeclaration = (FieldDeclaration) element;
2813+
if (getJ2STag(fieldDeclaration, "@j2sIgnore") != null) {
2814+
continue;
2815+
}
27892816
if (isFieldNeedPreparation(fieldDeclaration)) {
27902817
visitWith(fieldDeclaration, true);
27912818
continue;

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,20 @@ public boolean visit(TypeDeclaration node) {
446446
return super.visit(node);
447447
}
448448

449+
public boolean visit(FieldDeclaration node) {
450+
if (getJ2STag(node, "@j2sIgnore") != null) {
451+
return false;
452+
}
453+
return super.visit(node);
454+
}
455+
456+
public boolean visit(Initializer node) {
457+
if (getJ2STag(node, "@j2sIgnore") != null) {
458+
return false;
459+
}
460+
return super.visit(node);
461+
}
462+
449463
private void readTags(AbstractTypeDeclaration node) {
450464
Javadoc javadoc = node.getJavadoc();
451465
if (javadoc != null) {
@@ -653,13 +667,19 @@ protected void visitForRequires(AbstractTypeDeclaration node) {
653667
requires.addAll(visitor.optionals);
654668
}
655669
} else if (element instanceof Initializer) {
670+
if (getJ2STag((Initializer) element, "@j2sIgnore") != null) {
671+
continue;
672+
}
656673
DependencyASTVisitor visitor = getSelfVisitor();
657674
element.accept(this);
658675
requires.addAll(visitor.musts);
659676
requires.addAll(visitor.requires);
660677
requires.addAll(visitor.optionals);
661678
} else if (element instanceof FieldDeclaration) {
662679
FieldDeclaration field = (FieldDeclaration) element;
680+
if (getJ2STag(field, "@j2sIgnore") != null) {
681+
continue;
682+
}
663683
List fragments = field.fragments();
664684
for (int j = 0; j < fragments.size(); j++) {
665685
VariableDeclarationFragment vdf = (VariableDeclarationFragment) fragments

0 commit comments

Comments
 (0)