[ANN] Rearranger plugin - new version 1.8 released

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.

New features in version 1.8:

- Interface Method rule added which allows grouping of methods by the interface(s) they implement. Leading and/or trailing comments may be specified.

- Rules may be prioritized. Matching takes place in order of priority; rearranged file is created in sequence order of rules. (See documentation for description and examples.) New Rule UI allows sorting based on sequence or priority.

- In the "Confirm before rearranging" file structure popup, rules may now be displayed as nodes in the tree, with matching items appearing beneath. This should simplify debugging.

- Documentation reorganized. See http://www.intellij.org/twiki/bin/view/Main/RearrangerPlugin.

Please let me know if you have any problems. I "reorganized" (OK, changed) the code quite a bit.

Thanks -
Dave

0
12 comments
Avatar
Permanently deleted user

Very nice work, Dave. I think it will be better to have
1. a default layout come with the plugin and
2. a duplicate button to duplicate current selection under the selection and
3. invoke the edit action when an item is double clicked.

0
Avatar
Permanently deleted user

1. By default layout, you mean a predefined configuration, including set of rules? That has been requested before, but I didn't do it because I wasn't sure what that configuration should be. AlainR requested the ability to create the rules by inspecting a sample file and deriving them; that sounds hard. Perhaps I could add a "Load Default Configuration" button and a "Clear Configuration" button, and create a default configuration that I like. :)

2. "Duplicate" button - will do.

3. Double clicking invokes "edit" action - will do.

Thanks for your suggestions!
-Dave

0
Avatar
Permanently deleted user

I got this trying to rearrange a class with methods for several interfaces:



Please find attached my configuration. One other thing I noticed: The table display does not distinguish my setter-method-configuration from the NO-setter-configuration properly (the 'not' is not displayed).

Besides that, good work!



Attachment(s):
other-rearranger.xml
0
Avatar
Permanently deleted user

1. By default layout, you mean a predefined
configuration, including set of rules? That has been
requested before, but I didn't do it because I wasn't
sure what that configuration should be. AlainR
requested the ability to create the rules by
inspecting a sample file and deriving them; that
sounds hard. Perhaps I could add a "Load Default
Configuration" button and a "Clear Configuration"
button, and create a default configuration that I
like. :)


A default configuration u like will do. And maybe u could publish the layout first for comments.


2. "Duplicate" button - will do.

3. Double clicking invokes "edit" action - will do.

Thanks for your suggestions!
-Dave


Thanx.

0
Avatar
Permanently deleted user

Hi Frank,

Found and fixed the bug, which occurs when you have a method rule declared and a class initializer in the file. Will upload shortly.

Also fixed the "not" (i.e., invert) ]]> feature. Turns out I lost the "not" checkbox completely when I redid the UI a few versions back; the one you were probably looking is the one to invert the protection level checks.

Good eye! Thanks,
-Dave

0
Avatar
Permanently deleted user

Dave --

Just tried rearranger for the first time, and managed to hang IDEA by trying to rearrange a read-only file.

- a.

0
Avatar
Permanently deleted user

I would add a simple configuration. So that the user can understand the rules easily...

0
Avatar
Permanently deleted user

Here's a proposed default configuration for the Rearranger plugin.

I think I will bring up a dialog the first time the user visits the configuration pane that asks if the default configuration should be loaded. If not, it will be an empty configuration, just as it starts now; this would be more useful to those who want minimal or no rearranging done.

The default configuration will be stored in the plugin .jar file as a separate resource (XML file); in theory, you could replace that entry with your desired default (perhaps a company standard) and distribute that amended version of the plugin around your company.

Here's the proposed default configuration. (Rev 1) I'm happy to revise it based on your collective feedback.

Comments will be conditionally generated based on presence of what they precede. (E.g. the "// -- getter/setter" comment will only be generated if there are getter/setters.) I'll make the dashes look pretty. :)


Extracted Methods:


General Options:


Silence will be construed as assent!

-Dave

0
Avatar
Permanently deleted user

Dave,

I have found a little bug. Apparently the plugin always uses the global default for codestyle and not any project level override. The indentation style for example will already be the global style.

Thanks for this much needed plugin

Jacques

0
Avatar
Permanently deleted user

Hi Jacques,

1) I'm not sure that you are right, that the Rearranger uses global, not project, code styles. I get the CodeStyleManager using this code:

This seems to return project-specific code styles. In fact, I couldn't find a way to get only application-wide code styles. (There must be one since IDEA does it, but I didn't find a likely looking method.)

2)I'm a little confused by your example of indentation style. The Rearranger only uses code styles to determine if a method name matches getter/setter criteria; in particular, it only calls


However, Tabifier uses indentation style; did you perhaps mean that plugin?

3) I've been thinking more about your request to make Rearranger configuration be project-specific, too. (http://www.intellij.net/forums/thread.jsp?forum=18&thread=66038&tstart=90&trange=15; also http://www.intellij.net/tracker/idea/viewSCR?publicId=26029.) I know you've written plugins so perhaps you can offer some advice.

You mentioned that people would be able to choose between global (application-wide) and project-specific configuration by changing the plugin.xml file. If I implemented two Rearranger entry points, one for <application-components> and the other for <project-components>, and left one commented out, then I suppose your technique would work. But that seems awkward. I might as well offer two versions and let them download the one they want.

Valentin suggested:

>"If you need this for your own component you may easily implement this by having 2 components - one saving to workspace and another saving to project and providing UI for user to choose which one to use."

How would that work, though? AFAIK IDEA instantiates the plugin once (if application specific) or once per project (if project specific). Let's say I save the global-or-project configuration setting in the application configuration file (other.xml). How then do I tell IDEA that it is supposed to invoke the project-specific or application-wide plugin instance? I don't know of any way to dynamically register and unregister plugins as app- or project components. (If it existed, we wouldn't have to restart IDEA to install a new plugin.)

It seems that there are three related requests here:

1) Provide default configuration
2) Import/Export settings to a file (and save the file name in configuration)
3) Make configuration project- or application- specific

If the Rearranger plugin was project specific and gave you the option to use an external file, then:
(a) you could specify different files for each project or set of projects with identical configuration;
(b) the only configuration information you'd lose when upgrading IDEA or plugin would be the file name -- easily replaceable.
(c) you could simulate application-wide settings by having all point to the same file.
(d) supplying a default configuration is as simple as distributing a file and configuring the file name.

However, one big obstacle to changing the plugin settings to be project-specific is that all current users would lose their settings.

Suggestions?

-Dave

0
Avatar
Permanently deleted user

Let me start with this: this is a common problem for every plugin which motivated my request to JetBrains to make it part of the openapi. Whatever solution we come up we need to make sure it is general and decoupled from any one plugin.

The behavior should be copied from the existing code-style component. Here is how they handle it:
- - ]]>
I believe what Valentin proposed is to have 2 entry points that both tries to load their own configuration. This is how I think it would work:
Application component would have directly or indirectly (through a file) the default settings and load it at startup time.
The project settings would have a flag USE_PER_PROJECT_SETTINGS to tell if the user chose to override the global settings with a project specific settings. By default it would be off and the project component would just load its settings from the application component.
If the user selected to save the specific project settings then the project settings flag would be turned on and the project component would load its own project specific settings (again directly or indirectly).

Does that make sense?

We could implement the same ui as CodeStyle but ideally there should be 2 toggles that the user could use to customize where his/her settings go:
1) store settings in an external file or in the component settings
2) store as global settings or as project specific settings

As far as migration, we should be able to do it without too much problem.
1) Keep the old component as is.
2) Put in the new component a field named "activated" by default false. On load let it load its settings. Once all components have loaded (StartupManager.registerPostStartupActivity) the new one would check if it is activated. If not it would copy the old component settings into its own and set the activited to true.

I think this would work and would require minimum work.

Obviously the next step would be to not overwrite the external setting file completely but to just update the section of that component. That way a team could have an external settings file that they could share and won't have to worry about having different plugins installed on different IDEA instances.

Jacques

0
Avatar
Permanently deleted user

>However, Tabifier uses indentation style; did you perhaps mean that plugin?
Sorry Dave you are right. It must be the Tabifier. But since you are the one shop code reformatting/realigning/reordering (;) I did not really investigate further than: it must be Dave's problem ;)

Could it still be a problem with Tabifier or could it be an IDEA problem?

Jacques

0

Please sign in to leave a comment.