Community
Participate
Working Groups
Build: 3.3 final 1) Start with this CU: public class A { int x; public void foo() { if (x == 5) {//This is a very important comment return; } } } 2) Run the code cleanup wizard, with this setting applied: "Remove blocks containing a single return or throw statement" 3) The resulting CU is: public class A { int x; public void foo() { if (x == 5) return; } } Note the "important" comment is missing.
Internally we have a comment mapping heuristic that maps comments to nodes. In your case, the comment is mapped to the block, which is removed. This of course would be the right thing to do, if the comment would have said something about the block. We believe the current heuristic is doing well and no changes or special cases are planed at the moment.
The cleanup doesn't just remove blocks - it converts blocks to statements. Since it leaves the rest of the block body intact, it's unexpected that it deletes the comment. The particular case I noticed was statements with a //$NON-NLS-1$ comment at the end of the line. I have unexternalized strings flagged as an error so luckily the compiler caught the problem and I manually added the comments back.
*** Bug 202252 has been marked as a duplicate of this bug. ***
Martin? Can't we map the comment to the single statement if we have a block with only one statement? It is very likely that the comment is related to the single statement (or the condition). This seams to be a annoyance.
It's very difficult to detect these cases in the AST rewriter.
Is there a plan for this bug ?
No plans here. I don't see an easy way to fix this. For a major redesign of our mapping strategies there is no time.
*** Bug 258078 has been marked as a duplicate of this bug. ***
Has the architecture changed enough to make a fix possible in today's JDT? I'm personally more interested in the opposite operation (add block) to be fixed in case that is easier to archive.