Community
Participate
Working Groups
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.
Created attachment 84639 [details] Command line RCP app that reproduces the behavior
This is AST rewrite. Moving to Martin.
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.
Verified for 3.4RC1.