I guess, this an often discussed topic. But I still hope, it can be done.
The Java specification describes the order of modifiers. An I agreee with it in total with one exception. And I am not sure, if this is actually precisely covered by the specification. At least I think, it is a mistake then.
Consider the following inner class.
public class Foo
{
public static abstract class Bar // FP (well, kind of)
{
}
}
The rule would complain about wrong modifier ordering between static and abstract. But I think, this is wrong. It is an abstract class in the first place. As a super ordinary criterium it is static and super to that it is also public. There’s a clear naive logical order to be applied. “abstract static” would be wrong.
So, my approach is, that this rule could be configured to allow exactly that. All other ordering claims are perfect. But I would not want to disable the rule as it produces great results. And I would also not want to make the modifer ordering wrong in these cases.
Hi Marvin, I see your point here.
Even if the JLS order is a recommendation, the objective of the Java analyzer in terms of best practices is to make code uniform with what is best readable to most users.
Also, this rule specifically might be quite complicated to adapt to allow custom configuration, as you might want to define different modifier orders for methods, classes, fields, etc…
If I may suggest a possible solution for your projects, is to look at the code of this rule and create a clone of it in a custom plugin, with a different order of modifiers.
Ok, I checked the code. I think, it can be very easily extended to support this single option. I am not asking for full configurability, as the rule is perfect except dor this single point.
I suggest to simplify the code by copying the current modifiers to an array and compare it to the order of two arrays, that contain the two possible orders.
This way the code should be a lot shorter, more readable and mor slower. No offence, of course. And once done, it is also simpler to extend for new options.