Is there an easy way to sort methods within a class in Eclipse?
Asked
Active
Viewed 2.8k times
47
-
1Why would you want to sort the methods? – Paul Sonier May 12 '09 at 18:47
-
4I've got a couple of versions of the class to merge; this will make merging more straightforward, because some methods wound up at different places and diff doesn't resolve them nicely. – Carl Manaster May 12 '09 at 18:49
-
By name is sufficient, but by protection, static-ness, and name is probably better. – Carl Manaster May 12 '09 at 18:50
2 Answers
68
select the class, Source > Sort Members
you can set the order in Java preferences
via Eclipe forums
-
1Sometimes this gives compilation error.Say if one variable is instantiated based on the other and it on sort the variable goes above. I was wondering if this can be handled in any way – Ravisha Jun 23 '10 at 05:01
-
@Ravisha I usually handle this by hacking the variable name to force alphabetic order OR simply by not using sort members on that file... – Christophe Roussy Mar 11 '13 at 12:17
17
Found it on the Eclipse newsgroup:
select the class, Source > Sort Members

kryger
- 12,906
- 8
- 44
- 65

Carl Manaster
- 39,912
- 17
- 102
- 155
-
1This answer was actually added one minute earlier than the selected one. – Cacovsky Aug 05 '14 at 02:46
-
2First isn't always best, and generally it's better to have an answer from someone other than the OP. The accepted answer also includes some useful information about settings which my answer here is missing. – Carl Manaster Aug 05 '14 at 14:03
-
1Oh, I didn't noticed you were the OP. I understand now your decision. – Cacovsky Aug 05 '14 at 15:07