[ANN] Rearranger plugin - new version 1.0 released

The plugin rearranges class and class member declarations according to a user-specified order.

Bug fix in version 1.0 (from previous version 0.9):

- Fix deletion of previously inserted comments configured with trailing spaces.
Trailing spaces are truncated in Java file, so string comparison for comments was failing.

The plugin is available via Plugin Manager or at http://www.intellij.org/twiki/bin/view/Main/RearrangerPlugin.

Next planned features:

- Add global configuration setting "Rearranger comment pattern". All comments in the file matching this pattern will be deleted when the rearrangement begins. This allows you to change your configured comments without leaving artifacts from previous runs of the plugin.

Existing comments will be matched to the pattern, so you'll be warned if you have comments that don't match the pattern you specified.

- Ability to position extracted methods below the calling method. See the thread at http://www.intellij.net/forums/thread.jsp?forum=18&thread=50947&tstart=0&trange=15.

- Ability to order constructors which invoke others. For example,

orders the constructors from most parameters to least.

-Dave

13 comments

I've just been giving this plugin a try and so far I really like it. I've
got a few suggestions for it. I haven't a clue how difficult they'd be to
implement, so please tell me if I'm asking too much.

  • If a class provides an implementation of some interface, I generally like

to group the implementing methods together. It would be awesome if the
plugin could support this.

  • It would be good to be able to use the return type of a method as one of

the ordering criteria - that way I'd be able to specify a rule for putting
factory-type methods immediately after the constructors.

Thanks for a great plugin!
Vil.
--
Vilya Harvey
vilya.harvey@digitalsteps.com / digital steps /
(W) +44 (0)1483 469 480
(M) +44 (0)7816 678 457 http://www.digitalsteps.com/

0

Hi Vilya,

Great suggestions!

  • I think I could add a checkbox to the Method dialog like "Implements interface method". But this would only group any methods implementing any interface. If you had two interfaces, the implementing methods might be interleaved after rearrangement. Would this be a problem? If so, I could add a "match interface name" regular expression so you could specify which interface(s) you wanted grouped together.

  • I could easily provide another field like the "Name match" field, which would be a regex to match the return type. That would enable you to group methods returning the same type or same set of types together.


-Dave

0

Dave Kriewall wrote:

Hi Vilya,

Great suggestions!

  • I think I could add a checkbox to the Method dialog like "Implements

> interface method". But this would only group any methods implementing
> any interface. If you had two interfaces, the implementing methods might
> be interleaved after rearrangement. Would this be a problem? If so, I

could add a "match interface name" regular expression so you could specify

> which interface(s) you wanted grouped together.

Hmm, I'm not sure either of those solutions would really suffice. I
generally have code which looks like this:

public class SomeClass implements InterfaceA, InterfaceB
{
//
// InterfaceA IMPLEMENTATION
//

... methods from InterfaceA ...

//
// InterfaceB IMPLEMENTATION
//

... methods from InterfaceB ...
}

What I'd like is a way to tell the plugin to group methods according to
which interface they implement regardless of what the interface is called.
Where it gets even more problematic is that I'd like to be able to include
the name of the interface in the separator comment that precedes it. Is that
possible?

  • I could easily provide another field like the "Name match" field, which

> would be a regex to match the return type. That would enable you to group
> methods returning the same type or same set of types together.

That sounds perfect. Thanks a lot!

Vil.
--
Vilya Harvey
vilya.harvey@digitalsteps.com / digital steps /
(W) +44 (0)1483 469 480
(M) +44 (0)7816 678 457 http://www.digitalsteps.com/

0

Hmm. Yes, I think it's possible, though I have to think about how to organize it. The other big new feature, arranging "extracted" methods immediately below their parent (calling method), is similar. It's going to require a separate configuration pane. I might be able to integrate your suggestion with that feature. In a way, the interface is being treated like the "parent" of the methods that implement it. Maybe I should stop calling them "extracted methods" because it's turning into parent/child or ancestor/descendant relationship.

This relationship-based reordering would override the normal reordering of the "extracted" methods.

I was pondering whether comments would be needed; sounds like it would be a good idea. And with some %keywords% that can be expanded in place.

Thanks, Vil, you've given me a lot to think about! :) (I really do enjoy it.)

-Dave

0

without wishing to sound cheesy, I'd like to say that we're very lucky to have you so interested in this stuff...

0

Thanks...I'm in between projects at work and have some spare time. I must be obsessed or something with neatness and order, given the nature of my plugins, but it doesn't seem to have permeated my living space. (But my wife keeps hoping...)

I have to say, figuring out how to tabify complicated cases properly has been a big but enjoyable challenge (not that it's bug free yet); and everybody seems to appreciate the rearranger, much more than I ever expected. It's nice to have such a good group of folks involved in the EAP. We ought to have a big party when it ships.

Thanks,
-Dave

0

+10

joe martinez wrote:

without wishing to sound cheesy, I'd like to say that we're very lucky to have you so interested in this stuff...


--
Vilya Harvey
vilya.harvey@digitalsteps.com / digital steps /
(W) +44 (0)1483 469 480
(M) +44 (0)7816 678 457 http://www.digitalsteps.com/

0

Vil,

Just wanted you to know I hadn't forgotten about your request to group methods by interface. But the current obfuscated idea.jar won't let me compile with classes like PsiSuperMethodUtil and PsiUtil. Without these, I can't easily figure out which methods implement interfaces. In fact, I can't figure out if a method overrides another.

This has been going on for quite a few releases. There are bug reports but I think it's beyond JetBrain's ability to fix -- it's a bug in the obfuscator they use. Makes certain class files look corrupted.

Of course, if somebody knows of an alternate way of determining these relationships that uses only accessible Psi classes, I'd be happy to get to work on this... :)

-Dave

0

Dave Kriewall wrote:

Vil,

Just wanted you to know I hadn't forgotten about your request to group methods by interface. But the current obfuscated idea.jar won't let me compile with classes like PsiSuperMethodUtil and PsiUtil. Without these, I can't easily figure out which methods implement interfaces. In fact, I can't figure out if a method overrides another.

This has been going on for quite a few releases. There are bug reports but I think it's beyond JetBrain's ability to fix -- it's a bug in the obfuscator they use. Makes certain class files look corrupted.


Thanks for the concern Dave. I'm sorry to have to admit that I haven't had
much opportunity to use the plugin lately anyway - my duties at work have
been mostly away from code for the last week or so. I'm certainly going to
be using it when I do get fully back into coding again, so hopefully
JetBrains or the suppliers of their obfuscator will be able to find a
workaround. I really appreciate all the effort you're putting in to this.

Of course, if somebody knows of an alternate way of determining these relationships that uses only accessible Psi classes, I'd be happy to get to work on this... :)

-Dave


Vil.
--
Vilya Harvey
vilya.harvey@digitalsteps.com / digital steps /
(W) +44 (0)1483 469 480
(M) +44 (0)7816 678 457 http://www.digitalsteps.com/

0

Vilya,

I'm finally able to use IDEA's utility code to determine if a method implements an interface. So I've been thinking a little more about how to implement your request.

At the moment, I'm thinking of adding a new type of rule (besides field, method, inner class, and comment), named "interface" or "interface methods" or similar. The rule would move all methods implementing interfaces that match the rule to that point in the rearranged code. You could match the interface name to a regular expression (so have some arbitrary control over order) or take them all.

Methods belonging to a given interface would be grouped together, i.e. not interleaved with methods implementing other interfaces matching the rule.

Interfaces matching a rule could be ordered alphabetically or in the order (of implementing methods) encountered.

Methods of a particular interface could be ordered alphabetically, in the order declared in the interface, or in the order encountered.

Comments can be specified before and after each interface, and the interface name is available for insertion in the comments with a %keyword%. (If you want a comment before or after the entire block of interface methods, the current "Comment" rule will do the trick.)

Sound OK, or did I overlook something?

-Dave

0

Sounds perfect! It's exactly what I wanted. Thanks so much for this!

Vil.


Dave Kriewall wrote:

Vilya,

I'm finally able to use IDEA's utility code to determine if a method implements an interface. So I've been thinking a little more about how to implement your request.

At the moment, I'm thinking of adding a new type of rule (besides field, method, inner class, and comment), named "interface" or "interface methods" or similar. The rule would move all methods implementing interfaces that match the rule to that point in the rearranged code. You could match the interface name to a regular expression (so have some arbitrary control over order) or take them all.

Methods belonging to a given interface would be grouped together, i.e. not interleaved with methods implementing other interfaces matching the rule.

Interfaces matching a rule could be ordered alphabetically or in the order (of implementing methods) encountered.

Methods of a particular interface could be ordered alphabetically, in the order declared in the interface, or in the order encountered.

Comments can be specified before and after each interface, and the interface name is available for insertion in the comments with a %keyword%. (If you want a comment before or after the entire block of interface methods, the current "Comment" rule will do the trick.)

Sound OK, or did I overlook something?

-Dave


--
Vilya Harvey
vilya.harvey@digitalsteps.com / digital steps /
(W) +44 (0)1483 469 480
(M) +44 (0)7816 678 457 http://www.digitalsteps.com/

0

Hi Vil,

Give version 1.8 a try. The "interface methods" rule is implemented -- you'll probably be the first guinea pig! Let me know how it works out.

Thanks,
-Dave

0

Thanks Dave! Downloading it now...

Vil.

Dave Kriewall wrote:

Hi Vil,

Give version 1.8 a try. The "interface methods" rule is implemented -- you'll probably be the first guinea pig! Let me know how it works out.

Thanks,
-Dave


--
Vilya Harvey
vilya.harvey@digitalsteps.com / digital steps /
(W) +44 (0)1483 469 480
(M) +44 (0)7816 678 457 http://www.digitalsteps.com/

0

Please sign in to leave a comment.