tags:

views:

318

answers:

3

In Eclipse IDE how do you customize the Java code style formatter to have it sort the class members with a specified order, for example to group all instance methods by visibility?

+2  A: 

If the question is, "how do you customize the 'Source -> Format' command to re-order members?", I don't think it can be done. To change the order used for the 'Source -> Sort Members' command, change the "Members Sort Order" preference: "Window -> Preferences -> Java -> Appearance -> Members Sort Order"

Chris Conway
It seems to me this only affects the sort order in viewers, e.g. an outline. It does not reformat the source file.
Joel
This is the order that will be used if you do "Source -> Sort Members". "Source -> Format" does not re-order members AFAIK.
Chris Conway
A: 

I'm not sure when they added this functionality, but it seems to be there in 3.5:

Window -> Preferences

Java -> Editor -> Save Actions

Additional actions -> Configure ...

Code Organizing -> Members -> Sort Members

A: 

Another way to do this is to perform a code Clean Up:

Setting sorting order:

1 - Window -> Preferences -> Java -> Appearance -> Members Sort Order - Check "Sort members in same category by visibility

2 - Window -> Preferences ... Java -> Code Style -> Clean up ... On code Organizing, select Sort Members

Clean up:

3 - On your java source, right click -> Source -> Clean up.

André