3
votes

We're are using PMD and Checkstyle (from developers IDE and central CI server) to check code to our coding conventions.

I was expecting for these tools to provide a rule that checks for class members order but they don't seem to have one.

By class member order I mean something like:

public static properties
public properties
protected properties
private properties

public constructors
protected constructors
private constructors

static methods

non-static methods

I could certainly write my own PMD rule but I'm not used of it and would prefer not reinventing the wheel.

Do you know any tool that could do this kind of checks for us?

2
I suggest to you that with modern IDEs which show the members in that order anyway, there are better things to obsess about.user207421

2 Answers

5
votes

Checkstyle actually does that: DeclarationOrder

2
votes

You can use Checkstyle's Declaration Order Check

Checks that the parts of a class or interface declaration appear in the order suggested by the Code Conventions for the Java Programming Language.

1.Class (static) variables. First the public class variables, 

then the protected, then package level (no access modifier), and then the private.

2.Instance variables. First the public class variables, then the protected,

then package level (no access modifier), and then the private.

3.Constructors

4.Methods

Reference