Using CodeModel, is there a way to control the order of modifiers? Specifically when creating fields.
CodeModel seems to have it's own definition of modifier order which differs than that of the Java Language Specification and products like SonarQube and CheckStyle:
https://sonar43.spring.io/rules/show/squid:ModifiersOrderCheck?layout=false http://checkstyle.sourceforge.net/config_modifier.html
Modifiers should appear in the following order:
- Annotations
- public
- protected
- private
- abstract
- static
- final
- transient
- volatile
- synchronized
- native
- strictfp
This sample code:
// Create field for serialVersionUID
JFieldVar field1 = newClass.field(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, long.class, "serialVersionUID");
field1.init(JExpr.lit(1L));
Produces the following modifiers that does not follow suggested order:
private final static long serialVersionUID = 1L;