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

Bug 475281

Summary: When removing unused import in cleanup, Luna strips all the comments before it as well.
Product: [Eclipse Project] JDT Reporter: Alex Pogrebnyak <alex-pub.eclipse>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3    
Version: 4.5   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X   
Whiteboard: stalebug

Description Alex Pogrebnyak CLA 2015-08-18 13:25:14 EDT
If you happen to remove a reference to a foreign package class and it happens to be a first import statement in the java file, it removes all comments in front of it as well.  This is really unfortunate as it removes copyright headers.

E.g.

In Java Cleanup make sure that 'Remove Unused Imports' is checked.

Create this class foo/bar/Foo.java

package foo.bar

/**
 * Copyright notice
 */

import java.lang.String

public class Foo
{
}

Click save. import statement and copyright notice are gone.

This behavior is new to Luna.  Previous version used by me (Kepler) worked as expected (remove unused import and left comments intact).
Comment 1 Alex Pogrebnyak CLA 2015-08-18 13:46:07 EDT
This issue may be related to to https://bugs.eclipse.org/bugs/show_bug.cgi?id=475282 (Luna QuickFix does not insert first import statement into correct location.)
Comment 2 Eclipse Genie CLA 2020-03-17 03:02:11 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.