Rearranger users, feedback please - Rearranger plugin and annotations

I am thinking about adding the capability of rearranging (grouping and/or sorting) by annotation to the Rearranger plugin. There are several degrees of doing this, and I would appreciate your feedback on what would be useful to you.

Annotations are special kinds of modifiers (like public, static or final). Therefore Rearranger should at a minimum be able to select fields, methods or classes based on the presence or absence of an annotation. For example, a rule

"@Override final methods"

would group all final methods with the @Override annotation.

However, annotations are different from other modifiers in that they can have any number of associated values (called elements). For example, the following annotation has three elements:

Declaration:


Usage:


Therefore it might be useful to add the ability to select or sort based on annotation elements. For example, a rule

"All methods with annotation @MyAnnotation where doSomething matches "What." sorted by MyAnnotation.count()"*

would group all methods annotated with @MyAnnotation where the doSomething string matched the regular expression "What.*", and would sort them by count.

Doing so would add a new level of complexity to the Rearranger configuration panels. In particular, the current scheme of just checking a box to indicate presence of a modifier won't work for annotations. I think I would have to replace it completely with a new UI control that allows you to add traditional modifiers, marker annotations like @Override, or annotations with values. The sorting checkboxes would also have to be replaced to allow for sorting by modifiers (including annotations), by type, and/or by name. These changes would occur for rule definitions for fields, methods and classes.

I would like to know whether this kind of feature would be useful to you, and why. (What kind of problem would it solve that the current Rearranger can't address?) If yes, which of the following rearrangement rule types would you need:

1) grouping simply by individual annotation name alone (e.g. All methods with @Override annotation)

2) grouping by annotation names matching a pattern or a list (e.g. All methods with annotations matching "@MyAnn."*)

3) grouping by annotation elements (e.g. All methods with @MyAnnotation annotation where MyAnnotation.doSomething matches "some.thing"*)

4) Rules permitting optional sorting by annotation names as well as other modifiers, type and name (e.g. All methods with annotations matching "." sorted by annotation name (ignore case), modifiers, return type, method name(ignore case)*)

Of course I'd like to avoid a complex solution if it won't be used.

Thanks for your time!

-Dave

4 comments
Comment actions Permalink

Dave,

I like your annotations idea but unfortunately it won't be very helpful for me because on almost every project I work on, I'm the only (or one of the only) person(s) using it. Consequently, people wouldn't be too thrilled about me checking in code that has stuff specific to my IDE. Now, if you had an equivalent Eclipse plugin as well, then it might be a different story.

I would like some more specific handling for Java 1.5 Enums. I'm not working on a 1.5 project right now but as I recall, I had some difficulty making it do what I wanted to with Enums especially as to how simple Enums could be organized. For example, I'd like to be able to put...

public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES }

up with the public static final constants. So, unless something's changed recently that would be a very nice addition (although not at all necessarily related to your annotations feature).

My main reason for posting though is to simply say thanks for making such a great plugin. It's definitely made my life easier over the years and I have you to thank for it. I wouldn't even mind if you charged a (modest! :)) fee for it. JetBrains should pay you a bunch of money for it and include it as part of the base IntelliJ product. IntelliJ just isn't IntelliJ without it, IMHO.

Again, thanks for providing such a great tool! JetBrains should hand out awards for stuff like this.

0
Comment actions Permalink

Marc,

Thanks for your very kind comments.

I will add the ability to select classes based on whether they are enums (or not). Then you can group your enums with other constants by specifying the rules:

public static final fields
enum inner classes

("all enums" is probably a better description than "enum inner classes", but since enums are really specialized classes, I thought I would leave it and see if anyone complains. :) )

I'll post a message when the new release goes up.
-Dave

0
Comment actions Permalink

So, I guess it's a bit late to be replying to this, but --  Yes.  Please!  It would be super awesome if you could rearrange methods and fields by annotations.  This would allow users to do things like put all their @Transient getters together when using JPA or Hibernate, and it would allow them to put all injected fields (@In for seam @EJB for ejb) at the top of a class as is commonly expected.

I would really like to see this feature, and I'm sure I'm not the only one, despite the crickets on this forum.

-
Loren

0

Please sign in to leave a comment.