[ANN] Rearranger plugin - new version 2.1

This plugin
- rearranges (reorders) class and class member declarations according to a user-specified order and/or method call hierarchy;
- generates section-marking comments; and
- provides several controls for spacing within and between methods and classes.

Version 2.1 adds the following features:

1) A default configuration is loaded when plugin is first installed. An additional "Configuration" pane allows the user to clear the configuration, reload the default configuration, load the configuration from a file, or save it to a file. (Like other settings changes, 'Cancel' will discard these changes.)

If you don't like the default configuration provided, it could be replaced in the plugin.jar file. File structure of the configuration is just the

]]>

element of the IDEA configuration file, although you can also load a configuration from such a file; enclosing element is ignored. 2) Live Rearranger feature providing manual rearrangement capability. It is activated from the Edit menu, or with default keystroke Ctrl-comma. This pops up a window containing a tree view of the file structure (file, classes, class contents such as fields, methods, and inner classes.) You can drag and drop elements at the same level (with the same parent); this causes them to be reordered. Close the popup window by clicking outside or with any keystroke. If you hold Ctrl-comma until the dialog appears, perform at least one rearrangement, and then release Ctrl-comma, the dialog will close; if you release Ctrl-comma at any point before a rearrangement is made, the dialog will remain open. Three features are not yet implemented: - autoscrolling - automatic expansion of the node containing the current cursor location - simplification of the tree by removing top-level nodes with only one child (e.g., if the file contains only one class, that class will not be shown in the tree, only its children.) Thanks to Keith Lea for the request & design details. Bug fixes: - "force ]]> lines" spacing options now properly saved and restored. You should recheck your settings.

- Force Spacing logic improved to handle nested anonymous classes. Special cases provided for last method of class (ignore "Force Spacing After Method Close Brace") and for last class in file (place one newline character after the final brace.)

- Fixed exception in spacing logic. Thanks to Bas Leijdekkers for the report.


I have uploaded this to the plugin manager site but not to the wiki site. (Going out of town for several days; will do it when I get back.)

Please let me know if you have any problems or requests.

-Dave


- Additional planned plugin features:

1) ability to rearrange entire directories from the project tree.

2) Rearrange a selection, not entire file.

3) Progress bar.

26 comments

I'm using this plugin in combination with Tabifier. It seems that
every time I ]]>-L, extra blank lines are added to ceratin block
delimiters. For example:

// -


GETTER / SETTER METHODS -
// -


OTHER METHODS -

continuously add blank lines to their sections.

Additionally, the

// -


INNER CLASSES -

delimiter is added on every invocation of -L These behaviors are present when using the default configuration. Tony On Wed, 25 Feb 2004 00:10:47 +0000 (UTC), Dave Kriewall wrote: >This plugin >- rearranges (reorders) class and class member declarations according to a user-specified order and/or method call hierarchy; >- generates section-marking comments; and >- provides several controls for spacing within and between methods and classes. >]]>snip
>3) Progress bar.

0

Hi Tony,

We can easily determine if tabifier is contributing to the problem. Try ctrl-shift-alt-R (or select Rearrange from the Edit menu) a few times; the problems you describe should repeat if caused solely by the rearranger, as I suspect. Let me know if this is not the case.

I'll look into it. Thanks for the report -
-Dave

0

Great work! Dave.

A small bug: the inner class comment is not removed when i rearrange my class layout. So when i rearrange the layout several times, there are a lot of inner class comments. I try to use the default layout, still the same. this really make me feel bad.

BTW, can u add keyboard operation to the living layout window, maybe ctrl-up/ctrl-down to move the selected elements.

And another request is can u set an option to just layout the public class. many times i use some simple inner class and i don't want them to be populated with structure comments, and most of the times i don't want them to be rearranged. at least please add an option that disable the structure comments for inner classes.

0

Thanks for the suggestions, tc.

As a temporary workaround for the inner class comment problem, it might work to go to the General panel, and press the "Generate" global pattern button. This creates a regular expression that matches all generated comments; these should be removed next time you run the rearranger.

I will look into adding keyboard support for the live rearranger popup window.

Yes, I will add an option to avoid recursive rearrangement of inner classes. (Until just a few versions ago, the plugin couldn't rearrange inner classes.)

-Dave

0

Dave, sorry to post on here, don't have an email for you. The following
gif shows a bug in rearranger where it considers my getName() method to
be other, I'm guessing because there is a toUppercase() call in it, but
that should not be the case.

Thanks
R



Attachment(s):
rearranger.gif
0

Robert S. Sfeir wrote:

Dave, sorry to post on here, don't have an email for you. The following
gif shows a bug in rearranger where it considers my getName() method to
be other, I'm guessing because there is a toUppercase() call in it, but
that should not be the case.

Thanks
R

------------------------------------------------------------------------

Never mind just saw the setting to tell it return one line makes it a
getter. Thanks
R

0

Robert S. Sfeir wrote:

Dave, sorry to post on here, don't have an email for you. The following
gif shows a bug in rearranger where it considers my getName() method to
be other, I'm guessing because there is a toUppercase() call in it, but
that should not be the case.


Hum... seems setting even ignore body as long as it has get in the
method name still doesn't pull this method into its own group. Further
if you keep rearranging (ctrlaltshift+r), it keeps adding a space
after the //--- OTHER -


// comment.

Thanks
R

0

Yep, ctrl-shift-alt-r shows the same behaviour

Cheers
Tony

On Wed, 25 Feb 2004 04:04:18 +0000 (UTC), Dave Kriewall
<no_mail@jetbrains.com> wrote:

>Hi Tony,
>
>We can easily determine if tabifier is contributing to the problem. Try ctrl-shift-alt-R (or select Rearrange from the Edit menu) a few times; the problems you describe should repeat if caused solely by the rearranger, as I suspect. Let me know if this is not the case.
>
>I'll look into it. Thanks for the report -
>-Dave

0

Robert,

I'll take a look at the getter bug you described.

That problem with the // -- OTHER comment which you and others have noticed is due to one or more blank lines preceding the comment. When I remove the comment, the blank lines before and after the comment become adjacent and consecutive, and are viewed by the parser as belonging to the subsequent item (method or field). Then when the comment is regenerated, it is emitted in front of the newly grouped blank lines. In effect it moves any blank lines before the comment to after the comment. And to make matters worse, it introduces one more newline character before the comment, to perpetuate the error. :)

So, I'll retract my original suggestion for workaround. I think there are only two workarounds:

1) remove blank lines before the generated comments.
2) delete the comments from the configuration! :)

I'm out of town until Tuesday but will try to have all these issues fixed by mid next week. If the current version (2.1) of the plugin is too annoying, version 2.0 is still available at the wiki site. (http://www.intellij.org)

-Dave

0

Dave Kriewall wrote:

If the current version (2.1) of the plugin is too annoying, version 2.0 is still available at the wiki site. (http://www.intellij.org)


Dave, I can only speak for myself, but I couldn't even consider going back
to 2.0 now. I didn't expect it, but the live drag-n-drop rearranging has
turned out to be a killer feature for me! Thanks so much for all your hard
work on this plugin - I'm developing with even more pleasure because of it.

There seems to be a problem with the toolbar icons in the live rearrange
popup. They just show up as tiny (1x1 pixel) squares for me. I've attached a
screenshot showing the problem.

Finally, a suggestion: a bit more visual feedback while dragging
methods/fields would be good. I'm thinking something like the Mozilla
bookmarks manager, with a line showing where the the dropped item will be
inserted. I wrote some code a few years ago that did this; I can resurrect
it and send it to you if you think it will help.

Thanks again,
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/



Attachment(s):
screenshot.png
0

A suggestion for a usability enhancement from a dumb user ;)

I've been having problems using this plugin for a while - it never
seemed to arrange things in the way I wanted - but I've not had a chance
to properly work out why 'til now.

What was happening was that I'd always end up with some methods at the
end of my file no matter what I did. Then I realised what it was - I'd
set up all the conditions for special methods, e.g. abstract,
getter/setters, inner classes etc. but that everything else that didn't
satisfy these conditions was sent to the end of the file. Once I set up
an item for non-specific methods it all worked beautifully.

So in essence there is an implicit item in the list "All other methods"
which is always at the end, but invisible. I was just thinking it might
stop others getting confused like me if an explicit undeletable element
was added for "All other methods"; it would also be more convenient for
the user to have this already defined as it would be one less entry to
construct and is always used.

Maybe if I worked from the default layout that is now provided I
wouldn't have got this problem, and because of that you might not want
to bother, but I just thought I'd suggest it.

Cheers again for the great plugin! :)

N.

0

Robert,

It occurred to me that perhaps you set the default getter/setter definition but did not change the definition in your rule. When you create a rule, I copy the default g/s definition into it. Subsequent changes to the default g/s definition don't affect existing rules. (This is probably bad -- I should really have a flag or something that indicates whether to use the global definition or the rule's overriding definition.)

Anyway, could you either

1) set your default g/s definition to "ignore body," delete your method-matching rule, and recreate it; or

2) go to your method-matching rule's getter/setter definition and ensure that it says "ignore body."

Thanks, -Dave

0

You're right; all unmatched items match a default rule (which matches everything - fields, methods, inner classes.)

The default rule shows up if you select "confirm rearrangement" on the General options pane and "Show Rules". (I hoped this would be a good diagnostic tool.)
Anyway, you would see all your unmatched items showing up there.

So perhaps I should add an undeleteable "default rule" entry ("matches everything") with a fixed priority of zero. For existing configurations, I can automatically add it to the end of the list of rules with the next version of the plugin. The default rule could appear anywhere in the list, i.e. it is moveable; but must appear somewhere.

Then you could even do fancy stuff like put the default stuff somewhere besides the end.

Any objections? Only one I can think of is a little more clutter to the rules list.

-Dave

0

Hi Vil,

Wow - those icons are so small they hardly showed up on my screen. I suppose you only found them because a tooltip appeared? :)

I had plans to use those icons on the existing "confirm before rearrangement" dialog (instead of the clunky checkboxes); now I'm glad I didn't get it done. I haven't any idea why they would be so small. They're just a JCheckbox with an icon assigned. Maybe there's some size attribute I need to set. If I can't reproduce it (which is likely), could I give you a test version?

Yes, if you can send me some old code that illustrates the 'bookmark manager' behaviour you described, I'll try to add it. Java D&D offers the ability to show an Image with the cursor, but it isn't supported on Windows (and perhaps other platforms). So I abandoned that approach. But I agree, the D&D feedback is minimal.

Thanks, -Dave

0

Dave Kriewall wrote:

Hi Vil,

Wow - those icons are so small they hardly showed up on my screen. I suppose you only found them because a tooltip appeared? :)


I was wondering what those strange dots were, then I found that if I had my
mouse pointer in exactly the right place a tool-tip came up... :)

I had plans to use those icons on the existing "confirm before rearrangement" dialog (instead of the clunky checkboxes); now I'm glad I didn't get it done. I haven't any idea why they would be so small. They're just a JCheckbox with an icon assigned. Maybe there's some size attribute I need to set. If I can't reproduce it (which is likely), could I give you a test version?


Most likely the icon-loading code (are you using ImageIcons?) is failing to
find them on my system, for some reason, but I'm not sure why that would be
happening.

Yes, if you can send me some old code that illustrates the 'bookmark manager' behaviour you described, I'll try to add it. Java D&D offers the ability to show an Image with the cursor, but it isn't supported on Windows (and perhaps other platforms). So I abandoned that approach. But I agree, the D&D feedback is minimal.


Will do. It may not be pretty... ;)

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

Hey, I didn't even see this released until just now, I thought you were still working on Live Rearrange. It works just like it should so far, it works great. It seems like you got the modality and stuff problems fixed. Thanks for implementing this for me! :)

0

Where I can get this 2.1 version? I can only see version 2.0 at the wiki pages. Is my proxy playing tricks with me?

0

Hi Otto,

Use the Plugin Manager in IDEA 4.0 (under File...Settings...IDE Settings), or go to http://plugins.intellij.net. I had to rush out of town last Wednesday and didn't have time to upload 2.1 to the wiki site.

Should be a newer version in both places in a day or two.

-Dave

0

Hi,

First, thanks for the great plugin! It's exactly what I have wished to see in IDEA for a long time.

Some suggestions:

Could you support multiselection in the Class Member Order and similar lists? That would make it faster to edit the configuration.


Could it be possible to enforce some empty lines before and after a separator comment when it is created by the rearranger?

If I include the empty lines in the separator comment itself then it will not match my old comments that do not always have empty lines around them, and thus the comments will be inserted twice.

It would also be nice if extra empty lines adjacent to added separator comments would be deleted.

Perhaps just add a setting for number of empty lines to enforce before and after separator comments. Or alternatively, allow the user to specify the number of preceding and trailing empty lines around each separator comment (more control, but also more settings to edit).

0

Dave Kriewall wrote:

Yes, if you can send me some old code that illustrates the 'bookmark manager' behaviour you described, I'll try to add it. Java D&D offers the ability to show an Image with the cursor, but it isn't supported on Windows (and perhaps other platforms). So I abandoned that approach. But I agree, the D&D feedback is minimal.


I've resurrected that code and checked that it still works. It was written
for JDK 1.3, so it doesn't take advantage of any of the DnD simplifications
that 1.4 introduced (in fact, the bulk of the code is for providing a
simpler DnD API). Hopefully you'll be able to find something useful in it.

If you email me directly, I'll send the code straight to you rather than
clutter the list with it.

Thanks, -Dave


No worries - glad to be giving something back!

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

1) Regarding multiselection support, are you planning to move up/down or delete a set of rules? "Add" and "Edit" (and maybe "Duplicate") seem out of place with more than one rule selected; perhaps I should gray them out.

2) In working out the separator comment bugs reported above, I arrived at a solution similar to what you are suggesting. Here's what will happen:

- When looking for existing comments, disregard empty lines in the text and in the comment. When an existing comment is found, remove it and all adjacent blank lines. (This prevents comments from being duplicated just because of differences in blank lines.) Specifically, anything matching the following pattern will be removed:
\n*]]>

- Insert the new comment text including any blank lines specified. There was a bug that prevented blank lines from being saved in a comment. That's fixed (in 2.2), so now you can specify any number of preceding or trailing blank lines just by putting them in the comment text.

- I'm not planning on removing "internal" blank lines; so a comment like
will have to match exactly.

-Dave

0

&gt; 1) Regarding multiselection support, are you planning
&gt; to move up/down or delete a set of rules? "Add" and
&gt; "Edit" (and maybe "Duplicate") seem out of place with
&gt; more than one rule selected; perhaps I should gray
&gt; them out.

Yes, I'm planning to move rules.
Greying out non-applicable commands on multiselection sounds reasonable.


&gt; 2) In working out the separator comment bugs reported
&gt; above, I arrived at a solution similar to what you
&gt; are suggesting. Here's what will happen:

&lt;snip&gt;

Sounds good to me!

0

Hi Vil,

please check out the toolbar icons in version 2.2. The case did not exactly match that of the icon .png resources in the plugin jar file. So I am guessing that it worked for me on Windows because case is ignored in filenames, but failed for you on a Linux or other "case sensitive filename" platform.

If they still don't work, I added some special log messages. Let me know and I'll give you the details.

-Dave

0

Dave Kriewall wrote:

Hi Vil,

please check out the toolbar icons in version 2.2. The case did not exactly match that of the icon .png resources in the plugin jar file. So I am guessing that it worked for me on Windows because case is ignored in filenames, but failed for you on a Linux or other "case sensitive filename" platform.


I doubt that was the problem, since I'm on Windows 2000 SP2. :-/

If they still don't work, I added some special log messages. Let me know and I'll give you the details.


I can now see the "Show Parameter Types" icon. The others all seem to be the
correct size, but are completely invisible (i.e. as if transparency was set
to 100%). The mouse-over highlighting appears for them though.

I extracted the icons from rearranger.jar and wrote a little program to view
them. All of them displayed correctly in my little test program (using the
ImageIcon class to load the icons), so I can rule out video driver issues.

What are the log messages I should be looking out for?

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

Put the following in your /bin/log.xml file just before the final ]]> element.
]]>
and be sure that the console is enabled in idea.lax for stderr and stdout redirection (search for "console" and add it to the respective properties.) Restart IDEA and do a live rearrangement.

There should be some output if the icon can't be found, or it is the wrong size, etc. Send me whatever it dumps. If it dumps nothing, then it thinks it's finding the icons.

It puzzles me that you can see one of the icons but not the rest. Only thing that could really be different between them at the .png level is transparency, but even then you should see something. I suppose you could try substituting the icon that you can see for the ones you can't in the rearranger.jar file. If it appears in every position, then it must be a problem with the creation of the icons themselves.

Please also try a normal (automatic) rearrangement with "confirm before rearranging" option (general pane) set. I've just replaced all those checkboxes with the icons. Let me know if you see any of those.

Very weird..

Thanks,
-Dave

0

Dave Kriewall wrote:
> Put the following in your /bin/log.xml file just before the final > element. >]]> > > > > ]]>
> and be sure that the console is enabled in idea.lax for stderr and stdout
> redirection (search for "console" and add it to the respective
> properties.) Restart IDEA and do a live rearrangement.
>
> There should be some output if the icon can't be found, or it is the wrong
> size, etc. Send me whatever it dumps. If it dumps nothing, then it
> thinks it's finding the icons.

Have done this, and was able to fix the problem as a result! You were right
about it being to do with case sensitivity in the file names: the png files
in the jar had different combinations of capitalisation for their names and
their extension (i.e. the "Show Rules" icon was Showrules.PNG in the jar,
whereas the "Show Parameter Types" icon - the one that worked - was
ShowParamTypes.png). I changed the file names so that all of them were
camel-case with a lower-case ".png" at the end and recreated the jar; now
all of them appear as expected.

I suspect that you're running the plugin from a directory, rather than a jar
file...? Looks like file names in jars are case sensitive, regardless of
whether the local file system is or not.

Cheers!
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

Please sign in to leave a comment.