Community
Participate
Working Groups
Consider this code: --------------------------------- package p; /* comment */ import java.util.List; public interface I {} --------------------------------- Now, invoke the organize import feature, the following code will result --------------------------------- package p; public interface I {} --------------------------------- The comment has gone. The expected output would have been: --------------------------------- package p; /* comment */ public interface I {} ---------------------------------
I am not an expert in this area, but things works fine with the following code: package p; import java.util.List; /* comment */ import java.sql.*; public interface I { Connection sql = null; } which makes me think this may be the expected behavior. Lukas, can you tell me why you expect the comment to be kept.
(In reply to Jay Arthanareeswaran from comment #1) > Lukas, can you tell me why you expect the comment to be kept. I'm using comments as tokens to be used by preprocessors, e.g. --------------------------------- package p; /* [start] */ import java.util.List; public interface I {} /* [end] */ --------------------------------- The comment is not related to any specific line of code, e.g. I'm not commenting the import statement. The preprocessor will (in some cases) strip the contents between the above tags to produce still compilable output: --------------------------------- package p; /* [start] */ /* [end] */ --------------------------------- With the comment removed, that no longer works. But we don't have to talk about such an esoteric use case like mine. Here's a more probable one: --------------------------------- package p; // These import statements are blah blah import java.util.List; import java.util.Set; import java.util.Collection; // These import statements are xyz xyz import java.io.Serializable; public interface I extends Serializable, Set<Object>, Collection<Object> {} --------------------------------- The output after organising imports is now: --------------------------------- package p; // These import statements are xyz xyz import java.io.Serializable; import java.util.Collection; import java.util.Set; public interface I extends Serializable, Set<Object>, Collection<Object> {} --------------------------------- Which seems quite arbitrary. Maybe, this isn't so much of a bug report but a feature request: To implement more sophisticated organize import functionality. When comments are present around the import section, then ordering the imports could be avoided, but unnecessary imports could still be removed...
Duplicate of bug 154559?
Looks similar indeed
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. If you have further information on the current state of the bug, please add it. 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.