Sorting methods in Eclipse
Asked Answered
T

2

47

Is there an easy way to sort methods within a class in Eclipse?

Thomasina answered 12/5, 2009 at 18:45 Comment(3)
Why would you want to sort the methods?Clockwork
I'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.Thomasina
By name is sufficient, but by protection, static-ness, and name is probably better.Thomasina
B
68

select the class, Source > Sort Members

you can set the order in Java preferences

via Eclipe forums

Biome answered 12/5, 2009 at 18:49 Comment(2)
Sometimes 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 wayTimaru
@Timaru I usually handle this by hacking the variable name to force alphabetic order OR simply by not using sort members on that file...Gain
T
17

Found it on the Eclipse newsgroup:

select the class, Source > Sort Members

Thomasina answered 12/5, 2009 at 18:48 Comment(3)
This answer was actually added one minute earlier than the selected one.Kanishakanji
First 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.Thomasina
Oh, I didn't noticed you were the OP. I understand now your decision.Kanishakanji

© 2022 - 2024 — McMap. All rights reserved.