Community
Participate
Working Groups
Currently if generating getters and setters for multiple attributes they are always in alphabetical order. It would be nice if they would be in the same order as the corresponding attribtutes.
Moving to JDT UI
I find it quite annoying too. The generation sort order is driven by what is being displayed in the dialog tree. What is being displayed in the tree is based on the content provider which returns the source order of the fields. First problem: gettter/setter entries are stored in a hashmap, which has an undertermined iteration ordering. The simplest solution there would be to use a LinkedHashMap which by default has a defined itertaion order based on insertion. Second problem: Regardless of what the content provider order is, the viewer gets attached to a view sorter (JavaElementSorter) that sorts elements by category (not really relevant in that case) and then by element name. Therefore what is being viewed is always alpha sorted. The simplest solution would be to not attach a JavaElementSorter to the viewer. Those two simple changes make that: - the view is guaranteed to be sorted by sourec order - the genration of getter/setters which only follows what the view order is is made in source order Now this is a very naive implementation (I have I think there could be a few avenues to investigate have something decent: (I am listing what comes up to mind, but there are surely other ways, and not all apply together) - a preference setting (or a persistent dialog setting) to drive if getters setters generation dialog should be alpha or source sorted by default. - a button in the dialog to sort by alpha or source order, or additional options in the sort order drop down (that would also change the displayed tree order) to have: -- First getters then setters (alpha order) -- First getters then setters (source order) -- Fields in getter/setter pairs (alpha order) -- Fields in getter/setter pairs (source order) - Implement a JavaElementSorter that would respect the source order. - update the generation operation to take into account this new sort ordering and be a bit independent of what is being passed from the dialog. Or just do something ultra simple based on the what the tree order is.
Created attachment 45681 [details] Naive patch based on 3.2 Release (3.2.0.v20060605-1400.)
Created attachment 45682 [details] Naive patch based on HEAD
Thanks for that very quick patch! It works great
Adding more options to the combo makes sense, I was hoping you're patch adds this... :-) To use a Hashmap looks like a bug. But the elements in the view should better be shown in alphabetical order. If you have lots of field you can't find them anymore. But I'm fine if we make this optional and also offer that the creation order can be configured.
Fixed in HEAD > 20060705 The view order is alphabetical and the generation order according to the declaration order of the fields.
Tobias, Martin: Thanks! I reckon that I was a bit lazy, but the patcher rule #1 is to make as few changes as possible to the code to make it easier on the recieving end. ;-) Getting the combination of alpha order in the view and declaration order for the generation sounds like an excellent compromise, if is not configurable.
*** Bug 56069 has been marked as a duplicate of this bug. ***