Community
Participate
Working Groups
HEAD ASTRewrite#replace(..) does not consider the TargetSourceRangeComputer. My fix for bug 331116 only resolved that bug partially because of this core bug. Steps (with QuickAssistProcessor from HEAD): - have: void foo() { String message; // this comment gets removed message = ""; } - set caret into second "message" - apply the "Join variable declaration" quick assist => comment wrongly gets removed At the end of QuickAssistProcessor#getJoinVariableProposals(..), we have the line: rewrite.replace(assignParent, rewrite.createMoveTarget(statement), null); When I replace that line with the following, (using #remove() instead of #replace()), then it works as expected: ListRewrite listRewrite= rewrite.getListRewrite(assignParent.getParent(), (ChildListPropertyDescriptor)assignParent.getLocationInParent()); listRewrite.insertAfter(rewrite.createMoveTarget(statement), assignParent, null); rewrite.remove(assignParent, null);
Ayushman, if you get some time, please take a look.
Created attachment 188141 [details] proposed fix v1.0 + regression tests This patch makes sure that whenever a replace operation takes place in the ASTRewriteAnalyzer, we check for comments, and place the starting point beyond the end of comments so that they dont get removed.
Created attachment 188210 [details] proposed fix v1.1 + regression tests Modified the fix a bit to handle multiple comments and to make sure the comments in the extended source range of a node are also replaced with the node. Unfortunately, since the extended source range is defined to include comments and whitespaces just preceeding or trailing a node, they will get deleted if the node is replaced by another node. ASTRewritingModifyingReplaceTest.test0014b() shows such a case. Anyway, the fix takes care of preserving all other comments and will fix several UI bugs where comments are deleted upon refactoring, etc.
Olivier, can you please review? Thanks. I'll also get the JDT/UI tests run with the patch.
> I'll also get the JDT/UI tests run with the patch. All UI tests pass.
Looks good to me.
Released in HEAD for 3.7M6
Verified for 3.7M6.