Search code examples
javaintellij-ideaannotationssyntax-highlighting

Does IntelliJ IDEA support grouping and highlighting Java annotations (groups) in code?


I've been using IntelliJ IDEA as a Java IDE for a decade, and I created my favorite syntax highlight scheme back in 2009. It remains unmodified since around 2015 just because I find it very comfortable to me making reading code easier and faster. However, there are some syntax elements that are not easy to read under certain circumstances. The most important elements among those, I guess, are Java annotations that appear messy and are just hard to read if there are too many annotations. I prefer the following annotations order scheme:

  • (possibly disabled) "entry points": @Disabled, @Test, @RequestMapping, @Scheduled, etc;
  • Java core: @Override, @FunctionalInterface, @Target, @RetentionPolicy, etc;
  • contracts: JSR-305 (@Nonnull, @Immutable), Checker Framework;
  • codegen: Lombok @Getter, @EqualsAndHashCode, etc;
  • runtime: various custom @Foo's and @Bar's, @Entity, @OneToMany, @JsonProperty etc;
  • documentation: @Api***, etc;
  • @SuppressWarnings as the least significant one.

Sometimes I place them in wrong order and it makes reading code less convenient making me feel that the code style is not as strict as I want it to be. My question is: it possible to define an order for annotations (or their groups) so I could reorder? IntelliJ IDEA can do exactly the same for imports.

(Also, is it possible to highlight such groups with different colors?)


Solution

  • There is a feature request to support such behaviour, please upvote the feature.