Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 121428

Summary: [import rewrite] organize imports removes header comments
Product: [Eclipse Project] JDT Reporter: Ed Burnette <ed.burnette>
Component: UIAssignee: Martin Aeschlimann <martinae>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: stuart.stephen
Version: 3.2   
Target Milestone: 3.2 M5   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Ed Burnette CLA 2005-12-19 10:58:25 EST
3.2M4
This is a bad regression in 3.2M4 that may warrant a 3.2M4a version. When you run organize imports, the header comments are deleted, whether they are regular comments or Javadoc style comments. Here's a test case:

--snip--
/*
 * comment
 */
import javax.imageio.ImageIO;

public class Hello {
	public static void main(String[] args) {
		System.out.println("Hello world " + ImageIO.class);
	}
}
--snip--

Create a new java file, paste this in, save, and hit Ctrl+Shift+O or ise the context menu from the Package explorer.

This may or may not be related to bug 102939, but that's an older bug. Something has definitely changed in 3.2M4 as compared to 3.2M3.
Comment 1 Tobias Widmer CLA 2005-12-19 11:59:19 EST
This is indeed a regression caused by the switch to the new import rewrite.
The comment mapper of ASTRewrite associates this comment with the import declaration, and bug 102939 then causes the comment to dispappear.

Since there is a simple workaround (inserting a blank line), this defect hardly warrants a milestone rebuild.

Martin, can you have a look? Since we are using ASTRewrite now, we may be able to easily fix bug 102939 as well.
Comment 2 Ed Burnette CLA 2005-12-21 12:53:16 EST
The workaround is to change all my source files to insert a blank line in front of the import? Hehe, no thanks, I'll just try to avoid organize imports (especially done over a whole project) until M5.
Comment 3 Martin Aeschlimann CLA 2006-01-09 06:49:46 EST
fixed > 20060109
Comment 4 Martin Aeschlimann CLA 2006-01-19 03:41:54 EST
*** Bug 124284 has been marked as a duplicate of this bug. ***