Bug 212154 - [ast rewrite] Cannot attach comment to programatically generated AST
Summary: [ast rewrite] Cannot attach comment to programatically generated AST
Status: VERIFIED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3.1   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: 3.4 RC1   Edit
Assignee: Martin Aeschlimann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-12-06 11:14 EST by Robert Enyedi CLA
Modified: 2008-05-13 06:47 EDT (History)
3 users (show)

See Also:


Attachments
Command line RCP app that reproduces the behavior (3.54 KB, application/octet-stream)
2007-12-06 11:22 EST, Robert Enyedi CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Enyedi CLA 2007-12-06 11:14:59 EST
Build ID: M20071023-1652

Steps To Reproduce:
1. Import into an Eclipse workspace the plug-in source project from the attached JavaCommentsTest.zip
2. Run the "javacommentstest.Application RCP" application
3. Notice that comments are not attached to the AST when the getAstItemsFromDom() call is uncommented.


More information:
I am trying to attach comments to specific nodes of a generated Java AST, based on suggestions found on this newsgroup.

1. If I use an already saved (stringified) source, it works. This is built by the getAstItemsFromSrc() method.

2. When I programatically build the AST in method getAstItemsFromDom(), the comment is not attached.

I need to keep a reference to specific anchor statements, so adopting solution 1 (first saving the AST as string and reloading it for rewrite) is not suitable for me.

I'm reporting this bug since my mailing list post hasn't been answered.
Comment 1 Robert Enyedi CLA 2007-12-06 11:22:03 EST
Created attachment 84639 [details]
Command line RCP app that reproduces the behavior
Comment 2 Jerome Lanneluc CLA 2007-12-10 09:12:37 EST
This is AST rewrite. Moving to Martin.
Comment 3 Martin Aeschlimann CLA 2008-05-08 12:07:16 EDT
The descriptive AST rewrite (ASTRewrite rewrite= ASTRewrite.create(..)) only works on an AST that has been created on the source you later pass in rewrite. In your case the source the AST has been created is the empty string.

What you can do:

- After you build the first AST (getAstItemsFromDom..), create a new AST on the new source (ast.toString()) and use the this AST for the descriptive rewrite

- Do everything with the descriptive AST, including the creation of the AST. Start with an empty document, create an AST. now add a type, method etc all with the descriptive AST rewriter (rewritegetLis.

Comment 4 David Audel CLA 2008-05-13 06:47:03 EDT
Verified for 3.4RC1.