Bug 10496

Summary: DOM/AST: need for a node that holds the body statements of a ClassInstanceCreation
Product: [Eclipse Project] JDT Reporter: Dirk Baeumer <dirk_baeumer>
Component: CoreAssignee: Jim des Rivieres <jeem>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Olivier_Thomann
Version: 2.0   
Target Milestone: 2.0 M4   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Dirk Baeumer CLA 2002-02-28 11:39:26 EST
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.
Comment 1 Jim des Rivieres CLA 2002-02-28 14:52:57 EST
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);

Comment 2 Olivier Thomann CLA 2002-03-06 11:09:43 EST
Fixed and released in HEAD.