I am noticing that the FieldDeclarationsShouldBeAtStartOfClass rule is firing for cases where static enums are declared before non-static fields. Consider the following code:
public class Foo { private static final Logger LOGGER = LoggerFactory.getLogger(Foo.class); public static enum MyType { ABC, DEF, GHI, JHK }; private int id; private MyType myType; private String name; // OK, now constructors, getters, setters, etc. }
I do not find it objectionable to declare static enums before fields. In fact, I would prefer it because my fields reference the static enum... Also, I feel that the static declarations should be bunched together at the top.
I tried to find a reference to the official Java Code convention document that was the impetus for this rule, but I don't see that it specifically addresses this use-case. Technically, an enum is similar to an inner-class, but it is also declared statically in this case.
Can we agree that the above code is OK? If so, can the rule be relaxed such that this doesn't fire? If not, please provide an explanation as to why this is a problem.
Thank you,
Anthony
I've added a new rule property: "ignoreEnumDeclarations". This is by default true, so the rule is relaxed by default. If a more strict interpretation of this rule is needed, one can set this property to false, to have the old behavior.