Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 343651 - Sort Members in Enum with Comments on entries doesn't move comments
Summary: Sort Members in Enum with Comments on entries doesn't move comments
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-22 09:28 EDT by Nathaniel Mills CLA
Modified: 2019-11-15 11:33 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nathaniel Mills CLA 2011-04-22 09:28:46 EDT
Build Identifier: 20110301-1815

Using Sort Members / sort all members on an enum set up like this:
public enum Test {
   Second, // second comment
   First, // first comment
   Third // third comment
}
results in a sorted list of variables, but the comments don't move with them:
public enum Test {
   First, // second comment
   Second, // first comment
   Third // third comment
}
I was also able to use comments like /* first comment */ and they also did not get moved when the Sort Members was used.

I wasn't sure if this was a "Normal" bug  -- if you aren't paying attention, your code becomes fouled, but execution is not broken.

Reproducible: Always

Steps to Reproduce:
1. Create enum like:
public enum Test {
   Second, /* second comment */
   First, /* first comment */
   Third /* third comment */
}

2. Either select the file in Package Explorer and select Sort Members or use Alt+Shift+S, M, <enter>, then select sort all members, OK

3. you should get the errant result like this:
public enum Test {
   First, /* second comment */
   Second, /* first comment */
   Third /* third comment */
}
Note the comments are wrong
Comment 1 Ayushman Jain CLA 2011-04-25 02:14:15 EDT
Moving to JDT/UI
Comment 2 Markus Keller CLA 2011-04-26 08:51:46 EDT
The CompilationUnitSorter is in JDT/Core.

If I compare enum constants to e.g. class fields, a difference I see is that the extended source range of the fields include the comments, but the enums don't.

package xy;
public enum Test {
   Second, // second comment
   First, // first comment
   Third // third comment
}

class Klazz {
    int fSecond; // second comment
    boolean fFirst; // first comment
    long fThird; // third comment
}
Comment 3 Markus Keller CLA 2011-04-26 08:54:54 EDT
BTW: The correct way to document enum constants is to use Javadoc:

public enum Test {
    /** second comment */
    Second,
    /** first comment */
    First,
    /** third comment */
    Third
}
Comment 4 Ayushman Jain CLA 2011-04-26 09:10:46 EDT
Thanks Markus. I'll investigate.
Comment 5 Nathaniel Mills CLA 2011-04-26 12:13:52 EDT
(In reply to comment #3)
> BTW: The correct way to document enum constants is to use Javadoc:
> 
> public enum Test {
>     /** second comment */
>     Second,
>     /** first comment */
>     First,
>     /** third comment */
>     Third
> }

Perferred perhaps... correct implies what was done was incorrect which is arguable.  Regardless, had I used this method, the sorting appears to work but I would hope the issue can still be resolved as it can unknowingly create misleading comments in the code.  Had they been // TODO: reminders they would have been messed up as well.
Comment 6 Eclipse Genie CLA 2019-11-15 11:33:14 EST
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.