Skip to content

Commit

Permalink
Fix for #1268: GROOVY-10141: store anon. inner class before block visit
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jun 16, 2021
1 parent 5640837 commit 5423f47
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,33 @@ public void testAnonymousInnerClass31() {
runConformTest(sources, "1:B;2:B;3:B;");
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1268
public void testAnonymousInnerClass32() {
//@formatter:off
String[] sources = {
"Script.groovy",
"class C {\n" +
" class D {\n" +
" }\n" +
" def obj = new Object() {\n" +
" @Override\n" +
" String toString() {\n" +
" return new Object() {\n" +
" @Override\n" +
" String toString() {\n" +
" new D()\n" +
" }\n" +
" }\n" +
" }\n" +
" }\n" +
"}\n" +
"new C().obj\n",
};
//@formatter:on

runConformTest(sources);
}

@Test
public void testMixedModeInnerProperties_GRE597() {
//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -802,13 +802,17 @@ protected Expression anonymousInnerClassDef(AST node) {
((InnerClassNode) classNode).setAnonymous(true);
classNode.setEnclosingMethod(methodNode);
configureAST(classNode, node);

// GRECLIPSE add
output.addClass(classNode);
// GRECLIPSE end
assertNodeType(OBJBLOCK, node);
objectBlock(node);

AnonymousInnerClassCarrier ret = new AnonymousInnerClassCarrier();
ret.innerClass = classNode;
/* GRECLIPSE edit
output.addClass(classNode);
*/
classNode = oldNode;
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3677,14 +3677,16 @@ public InnerClassNode visitAnonymousInnerClassDeclaration(AnonymousInnerClassDec
anonymousInnerClass.setAnonymous(true);
anonymousInnerClass.putNodeMetaData(CLASS_NAME, innerClassName);
configureAST(anonymousInnerClass, ctx);

// GRECLIPSE add
classNodeList.add(anonymousInnerClass);
// GRECLIPSE end
classNodeStack.push(anonymousInnerClass);
ctx.classBody().putNodeMetaData(CLASS_DECLARATION_CLASS_NODE, anonymousInnerClass);
this.visitClassBody(ctx.classBody());
classNodeStack.pop();

/* GRECLIPSE edit
classNodeList.add(anonymousInnerClass);

*/
return anonymousInnerClass;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,13 +889,17 @@ protected Expression anonymousInnerClassDef(AST node) {
((InnerClassNode) classNode).setAnonymous(true);
classNode.setEnclosingMethod(methodNode);
configureAST(classNode, node);

// GRECLIPSE add
output.addClass(classNode);
// GRECLIPSE end
assertNodeType(OBJBLOCK, node);
objectBlock(node);

AnonymousInnerClassCarrier ret = new AnonymousInnerClassCarrier();
ret.innerClass = classNode;
/* GRECLIPSE edit
output.addClass(classNode);
*/
classNode = oldNode;
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3533,14 +3533,16 @@ public InnerClassNode visitAnonymousInnerClassDeclaration(final AnonymousInnerCl
anonymousInnerClass.setAnonymous(true);
anonymousInnerClass.putNodeMetaData(CLASS_NAME, innerClassName);
configureAST(anonymousInnerClass, ctx);

// GRECLIPSE add
classNodeList.add(anonymousInnerClass);
// GRECLIPSE end
classNodeStack.push(anonymousInnerClass);
ctx.classBody().putNodeMetaData(CLASS_DECLARATION_CLASS_NODE, anonymousInnerClass);
this.visitClassBody(ctx.classBody());
classNodeStack.pop();

/* GRECLIPSE edit
classNodeList.add(anonymousInnerClass);

*/
return anonymousInnerClass;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -889,13 +889,17 @@ protected Expression anonymousInnerClassDef(AST node) {
((InnerClassNode) classNode).setAnonymous(true);
classNode.setEnclosingMethod(methodNode);
configureAST(classNode, node);

// GRECLIPSE add
output.addClass(classNode);
// GRECLIPSE end
assertNodeType(OBJBLOCK, node);
objectBlock(node);

AnonymousInnerClassCarrier ret = new AnonymousInnerClassCarrier();
ret.innerClass = classNode;
/* GRECLIPSE edit
output.addClass(classNode);
*/
classNode = oldNode;
return ret;
}
Expand Down

0 comments on commit 5423f47

Please sign in to comment.