Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Members Sort Order vs Oracle Java Code Conventions

In Eclipse, the default "Members Sort Order" (in Preferences - Java - Appearance - Members Sort Order) is:

  • Types
  • Static Fields
  • Static Initializers
  • Static Methods
  • Fields
  • Initializers
  • Constructors
  • Methods

But Oracle's Java Code Conventions say the order should be:

  • Class (static) variables
  • Instance variables
  • Constructors
  • Methods

So Oracle don't distinguish between static and non-static methods in the ordering. I'm getting a Checkstyle error because of this:

Instance variable definition in wrong order.

So I'm wondering whether to modify the order in Eclipse or disable the Checkstyle check. Leaning towards disabling the Checkstyle check so everyone who joins the project doesn't have to modify their Eclipse settings but it seems a bit wrong to be ignoring the official conventions.

What are people's views and is there any other way round this?

like image 481
Steve Chambers Avatar asked Oct 21 '22 20:10

Steve Chambers


2 Answers

"So I'm wondering whether to modify the order in Eclipse or disable the Checkstyle check. Leaning towards disabling the Checkstyle check so everyone who joins the project doesn't have to modify their Eclipse settings but it seems a bit wrong to be ignoring the official conventions."

I would suggest changing Eclipse to conform to the rules that YOU want to use. Preferably using Oracles if that what you want. I usually generate my Eclipse project files using Maven (so all code formatting is created automatically for new users). I know CXF uses something similar, take a look at their POMs for inspiration.

like image 54
Peter Svensson Avatar answered Oct 27 '22 00:10

Peter Svensson


Following on from the accepted answer by Peter Svensson, these Checkstyle errors can be resolved by using the following Member Sort Order in Eclipse:

  1. Types
  2. Static Fields
  3. Fields
  4. Static Initializers
  5. Initializers
  6. Constructors
  7. Static Methods
  8. Methods
like image 38
Steve Chambers Avatar answered Oct 26 '22 23:10

Steve Chambers