[ANN] Rearranger plugin - new version 1.6

The 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 1.6 adds controls to force N (N >= 0) number of blank lines at certain locations in the file, namely:

Also added a control to remove leading and trailing blank lines inside a code block.

These were all the options I could find when I searched the ITN request list; let me know if I missed your favorite one!

-Dave

8 comments
Comment actions Permalink

Hey Dave,

Been playing with the newest Rearranger. I love the extracted methods going below the calling methods name and have started using it. However, I would love the ability to exclude the main method from that process. That is to say, I don't want the methods that main() calls to be below the main method (which I keep at the bottom of the class). Would it be possible to add a checkbox to exclude the methods that are called by main() from that rule?

thanks (as always) for the excellent work...

BTW - I also seem to have extra lines appearing in some places if I use ReArranger multiple times in succession. I've included my class file (just begun) and my options that are causing it.

BTW II - I got the following error when calling rearranger twice in quick succession (in order to verify the extra spacing issue)

Error message: Text block is not empty
java.lang.Throwable

at com.intellij.openapi.diagnostic.Logger.error(Logger.java:31)
at com.intellij.psi.impl.bh.childReplaced(bh.java:46)
at com.intellij.psi.impl.bf.m(bf.java:188)
at com.intellij.psi.impl.bf.i(bf.java:276)
at com.intellij.psi.impl.source.b.c.a(c.java:382)
at com.intellij.psi.impl.source.b.c.b(c.java:129)
at com.intellij.psi.impl.source.e.g.a(g.java:227)
at com.intellij.psi.impl.source.e.g.a(g.java:19)
at com.intellij.psi.impl.source.e.g.c(g.java:89)
at com.intellij.psi.impl.source.e.g.b(g.java:190)
at com.intellij.psi.impl.source.e.g.b(g.java:217)
at com.intellij.psi.impl.source.e.l.visitClass(l.java:363)
at com.intellij.psi.impl.source.s.accept(s.java:135)
at com.intellij.psi.impl.source.e.l.a(l.java:589)
at com.intellij.psi.impl.source.e.l.a(l.java:763)
at com.intellij.psi.impl.source.e.c.reformat(c.java:148)
at tzambalayev.ideaplugins.reformat.ReformatHandler.reformatFile(ReformatHandler.java:63)
at tzambalayev.ideaplugins.reformat.ReformatAndOptimizeHandler.executeWriteAction(ReformatAndOptimizeHandler.java:15)
at com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler$1.run(EditorWriteActionHandler.java:2)
at com.intellij.openapi.application.b.b.runWriteAction(b.java:300)
at com.intellij.openapi.editor.actionSystem.EditorWriteActionHandler.execute(EditorWriteActionHandler.java:3)
at com.intellij.openapi.editor.actionSystem.EditorAction$1.run(EditorAction.java:2)
at com.intellij.openapi.command.b.a.executeCommand(a.java:39)
at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:15)
at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:14)
at com.intellij.openapi.a.b.d.a(d.java:47)
at com.intellij.openapi.a.b.d.b(d.java:81)
at com.intellij.openapi.a.b.d.a(d.java:28)
at com.intellij.ide.s.dispatchEvent(s.java:130)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)


Joe



Attachment(s):
other.xml
ClassComparisonTest.java
0
Comment actions Permalink

here's something else also...

On the following file calling the rearranger and tabifier (latest of each) with ctrl-alt-R hangs idea. I'm using the same options file as in the previous post.

thanks

Joe.



Attachment(s):
ClassComparisonTest.java
0
Comment actions Permalink

Hi Joe,

1) I could add a checkbox on the Method rule panel that says something like "Exempt from extracted method treatment." It would mean that any methods matching the criteria would neither be organized underneath another calling method, nor would they gather their called methods under them. Sound OK?

2) I checked your comments for any extra newlines and didn't see any, so it's not that. If there are one or more blank lines that precede a field or method, they will travel with the field or method to the new destination. So something like

when sorted alphabetically yields

Is this what you are seeing?

3) That exception was caused when the Reformat plugin called IDEA's code layout tool, which it does before calling my plugin(s). It might be related to the document (text version of the file) being out of sync with the Psi tree (parsed version of file), but I have no way of knowing, or for that matter, fixing. You could submit it to IntelliJ but they might very well just say that it's the plugin's fault. Or maybe they would say why, which would give me a clue as to what might be done about it.

-Dave

0
Comment actions Permalink

By "hangs IDEA" I presume you mean it becomes unresponsive and you have to kill and restart it?

If so, please (next time) go to the IDEA console DOS box and do a Ctrl-break to get a thread dump, and attach that to your reply here.

0
Comment actions Permalink

1) sounds perfect. A more general solution to my personal need.

2) I don't think that's what I was seeing. What I saw was some of the comments getting extra blank lines after them each time I ran the rearranger (or perhaps it was the tabifier as I run them together)

3) Thanks for the heads up. That'll teach me not to tabify until my code compiles (perhaps that was it).

thanks!

0
Comment actions Permalink

RFE for you:
With the rearranging of extracted method functionality on (great job!)
I'm getting extracted methods interspersed between my constructors...
was just wondering if you had any bright ideas how this could be
avoided... maybe a processing order thing?

Cheers,
N.

Dave Kriewall wrote:

The 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 1.6 adds controls to force N (N >= 0) number of blank lines at certain locations in the file, namely:
after class left brace "{" > after method left brace "{" > before method close brace "}" > after method close brace "}" > before class close brace "}" > after class close brace "}" > ]]>
Also added a control to remove leading and trailing blank lines inside a code block.

These were all the options I could find when I searched the ITN request list; let me know if I missed your favorite one!

-Dave

0
Comment actions Permalink

Hi Nathan,

I proposed adding a checkbox to the method rule dialog (see a few messages back in this topic) to the effect of "exempt from extracted method processing." This was to address Joe M's request that his main() method not haul the methods it calls along with it. I think maybe it would do the same for you if you checked it on your constructor rules. Then the methods the constructors call would just show up where other rules would place them. Would this work for you?

One possible alternative is choosing 'move extracted methods below LAST usage'. Assuming all the constructors called another method, this method would appear after the last constructor. Wouldn't work, though, if not all constructors called it.

-Dave

0
Comment actions Permalink

Dave Kriewall wrote:

I proposed adding a checkbox to the method rule dialog (see a few messages back in this topic) to the effect of "exempt from extracted method processing." This was to address Joe M's request that his main() method not haul the methods it calls along with it. I think maybe it would do the same for you if you checked it on your constructor rules. Then the methods the constructors call would just show up where other rules would place them. Would this work for you?

Sounds like it would. Knew you'd have a good plan :)

One possible alternative is choosing 'move extracted methods below LAST usage'. Assuming all the constructors called another method, this method would appear after the last constructor. Wouldn't work, though, if not all constructors called it.

Yeah, I already have that set, but it's only used in the one constructor
unfortunately and thats one in the middle (as ordered by your plugin
using param count ;) ).

0

Please sign in to leave a comment.