Bug 200680 - Lost comment after applying code cleanup
Summary: Lost comment after applying code cleanup
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 202252 258078 (view as bug list)
Depends on: 250142
Blocks:
  Show dependency tree
 
Reported: 2007-08-21 09:29 EDT by John Arthorne CLA
Modified: 2020-05-15 06:32 EDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description John Arthorne CLA 2007-08-21 09:29:22 EDT
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.
Comment 1 Martin Aeschlimann CLA 2007-08-21 09:38:58 EDT
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.
Comment 2 John Arthorne CLA 2007-08-21 10:53:59 EDT
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.
Comment 3 Benno Baumgartner CLA 2007-09-05 07:03:54 EDT
*** Bug 202252 has been marked as a duplicate of this bug. ***
Comment 4 Benno Baumgartner CLA 2007-09-05 07:04:43 EDT
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.
Comment 5 Martin Aeschlimann CLA 2007-09-05 09:51:43 EDT
It's very difficult to detect these cases in the AST rewriter.
Comment 6 NoName CLA 2008-03-10 05:48:48 EDT
Is there a plan for this bug ?
Comment 7 Martin Aeschlimann CLA 2008-03-10 06:49:58 EDT
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.
Comment 8 Dani Megert CLA 2008-12-09 11:25:51 EST
*** Bug 258078 has been marked as a duplicate of this bug. ***
Comment 9 Paul Pazderski CLA 2020-05-15 05:03:52 EDT
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.