Community
Participate
Working Groups
Now that I understand anonymous types better I found out that a common pattern we use is not straight forward to implement. The case is as follows: when we do analysis of a method we avoid visiting local type declarations. We did this by simply returning false from the corresponding visit methods (old AST). In the new world this got tricky for anonymous inner types. I know have to write the following code: boolean visit(ClassInstanceCreation node) { if (!node.isisAnonymousClassDeclaration()) return true; // visit everything except the body declarations node.getExpression().accept(this); node.getName().accept(this); for (Iterator iter= node.arguments().iterator(); iter.hasNext(); ) ((ASTNode)iter.next()).accept(this); return false; } Having a special node holding the body declaration would make this less error prone. What do you think about introducing a new node AnonymousTypeDeclarationBody. Then we would have a special visit method and could treat this case like other type declarations.
Agreed. Adding a new type of node to hold the anonymous class declaration would make it simpler all around. Proposal: + public class AnonymousClassDeclaration extends ASTNode { public List bodyDeclarations(); public ITypeBinding resolveBinding(); } ClassInstanceCreation + public AnonymousClassDeclaration getAnonymousClassDeclaration(); + public void setAnonymousClassDeclaration(AnonymousClassDeclaration anon); - public List bodyDeclarations(); - public boolean isAnonymousClassDeclaration(); - public void setAnonymousClassDeclaration(boolean isAnon);
Fixed and released in HEAD.