47

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

Carl Manaster
  • 39,912
  • 17
  • 102
  • 155

2 Answers2

68

select the class, Source > Sort Members

you can set the order in Java preferences

via Eclipe forums

kryger
  • 12,906
  • 8
  • 44
  • 65
marcgg
  • 65,020
  • 52
  • 178
  • 231
  • 1
    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 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
  • 1
    This answer was actually added one minute earlier than the selected one. – Cacovsky Aug 05 '14 at 02:46
  • 2
    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. – Carl Manaster Aug 05 '14 at 14:03
  • 1
    Oh, I didn't noticed you were the OP. I understand now your decision. – Cacovsky Aug 05 '14 at 15:07