Bug 10496 - DOM/AST: need for a node that holds the body statements of a ClassInstanceCreation
Summary: DOM/AST: need for a node that holds the body statements of a ClassInstanceCre...
Status: RESOLVED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.0 M4   Edit
Assignee: Jim des Rivieres CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-02-28 11:39 EST by Dirk Baeumer CLA
Modified: 2002-03-06 11:09 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.