eclipse.jdt.ls icon indicating copy to clipboard operation
eclipse.jdt.ls copied to clipboard

Feature request: Warning (and code action / formatter config) for out of order modifiers

Open Frederick888 opened this issue 3 years ago • 3 comments

There is a suggested order of class/field/method modifiers in JLS.

For example, in https://docs.oracle.com/javase/specs/jls/se11/html/jls-8.html#jls-8.1.1

If two or more (distinct) class modifiers appear in a class declaration, then it is customary, though not required, that they appear in the order consistent with that shown above in the production for ClassModifier.

Out of order modifiers often cause a warning in linting tools. Can we please have this warning as well?

And it'd be even better if there are code actions or formatter configurations to fix it. Thanks.

Frederick888 avatar Jun 24 '21 06:06 Frederick888

I looked upstream in JDT and the closest thing I could find was https://bugs.eclipse.org/bugs/show_bug.cgi?id=25800 . Otherwise, it seems there is no option in errors/warnings to report such issues.

This could be a nice addition, and once there, users could easily set their project settings .settings/org.eclipse.jdt.core.prefs or java.settings.url to include the option. A you mention, the formatter could also be updated to conform with the ordering.

rgrunber avatar Jun 24 '21 14:06 rgrunber

@rgrunber FYI I also found https://bugs.eclipse.org/bugs/show_bug.cgi?id=322494

Frederick888 avatar Jun 24 '21 15:06 Frederick888

That's exactly the patch needed. The only annoying part is I suspect the patch introduces the feature through jdt.ui, and we can't reference or use functionality from there directly (can't satisfy the ui capabilities), but SortModifiersFix, which has the main functionality looks like it could easily exist in jdt.core.manipulation.

rgrunber avatar Jun 24 '21 16:06 rgrunber