Skip to content

Commit 581b59a

Browse files
author
zhourenjian
committed
Fixing bug#2797539 : Incorrect instantiation of member before inner class declaration inside interface
http://sourceforge.net/tracker/?func=detail&aid=2797539&group_id=155436&atid=795800 Interface's inner classes declaration is not in the correct order. Fix it by move codes a few lines ahead of member initialization.
1 parent 3b44616 commit 581b59a

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,7 @@ public boolean visit(MethodInvocation node) {
17351735
//if (args.size() == 1) {
17361736
Expression arg = (Expression) args.get(args.size() - 1);
17371737
ITypeBinding resolveTypeBinding = arg.resolveTypeBinding();
1738-
if (resolveTypeBinding.isArray()) {
1738+
if (resolveTypeBinding != null && resolveTypeBinding.isArray()) {
17391739
needBrackets = false;
17401740
}
17411741
//}
@@ -2437,6 +2437,12 @@ public void endVisit(TypeDeclaration node) {
24372437

24382438
int staticCount = -1;
24392439
ReferenceASTVisitor refVisitor = new ReferenceASTVisitor();
2440+
/*
2441+
* Fixing bug#2797539 : Incorrect instantiation of member before inner class declaration inside interface
2442+
* http://sourceforge.net/tracker/?func=detail&aid=2797539&group_id=155436&atid=795800
2443+
* Interface's inner classes declaration is not in the correct order. Fix it by move codes a few lines
2444+
* ahead of member initialization.
2445+
*/
24402446
for (Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) {
24412447
ASTNode element = (ASTNode) iter.next();
24422448
if (element instanceof TypeDeclaration) {
@@ -2447,6 +2453,19 @@ public void endVisit(TypeDeclaration node) {
24472453
*/
24482454
element.accept(this);
24492455
}
2456+
}
2457+
}
2458+
// Interface's inner interfaces or classes
2459+
buffer.append(laterBuffer);
2460+
2461+
for (Iterator iter = bodyDeclarations.iterator(); iter.hasNext();) {
2462+
ASTNode element = (ASTNode) iter.next();
2463+
if (element instanceof TypeDeclaration) {
2464+
if (node.isInterface()) {
2465+
// the above codes have already dealt those inner classes inside interface
2466+
// just ignore here
2467+
continue;
2468+
}
24502469
} else if (element instanceof Initializer) {
24512470
if (getJ2STag((Initializer) element, "@j2sIgnore") != null) {
24522471
continue;
@@ -2586,8 +2605,6 @@ public void endVisit(TypeDeclaration node) {
25862605
if (staticCount != -1) {
25872606
buffer.append(");\r\n");
25882607
}
2589-
// Interface's inner interfaces or classes
2590-
buffer.append(laterBuffer);
25912608

25922609
String fieldsSerializables = prepareSimpleSerializable(node, bodyDeclarations);
25932610
if (fieldsSerializables.length() > 0) {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@ public boolean visit(MethodInvocation node) {
111111
*/
112112
public boolean visit(SuperMethodInvocation node) {
113113
IMethodBinding methodBinding = node.resolveMethodBinding();
114-
String key = methodBinding.getKey();
115-
if (key != null) {
116-
key = key.replaceAll("<[^>]+>", "");
114+
String key = null;
115+
if (methodBinding != null) {
116+
key = methodBinding.getKey();
117+
if (key != null) {
118+
key = key.replaceAll("<[^>]+>", "");
119+
}
117120
}
118121
if (methodSignature.equals(key)) {
119122
isReferenced = true;

0 commit comments

Comments
 (0)