Monday, May 14, 2012

Oh, IntelliJ IDEA, how I miss you

I'm switching from IDEA to Eclipse for the sake of conformity, with a great deal of mourning. No, it's not ideal, but it's a startup and not a good time to shave a yak.

Here are some features I miss. If you know how to do this in Eclipse, please, post a comment!

* Save the file whenever it loses focus!
* JavaScript highlighting even within .vm velocity templates
* JavaScript autocompletion. It's a dynamic language so the IDE can never be sure what properties an object will have, but IDEA comes remarkably close. It highlights known properties in one color, and underlines ones it can't verify. Great jQuery integration.
* Automatically importing classes that are only found in one place, or classes from specific libraries. Like, I want to type List<..> and the IDE should import java.util.List without asking me.
* Populating the filter of packages to exclude from the import suggestion list, from the import suggestion list. Not requiring a separate trip to the preferences dialog and typing in the useless ones.
* Ctrl-W. In IDEA, this widens the selection. Widen it to the word, then the expression, then the containing expression, etc.
* At the end of a line that contains an expression, command-shift-V to introduce a variable that stores the result of that expression. -- solution from Moandji: Command-2 (or ctrl-2 on Windows), then L
* Static imports: from an explicit static method call, alt-space for suggestions including "static import"-- solution from Moandji: Command-shift-M
* Recognition and auto-import of static methods from certain files (such as JUnit assertions)
* add a private final field; have the IDE generate the constructor or add the parameter to the existing constructor.
* switch back and forth between a source file and its test file.
* generate a test class and have it automatically go into test sources rather than defaulting to main
* When I copy a class, open the new copy. Don't make me go looking for it.
* In the debugger, increase the font size on variables. This is possible through some deep menu options, but then it increases the font without increasing the height of the row with the text in it. Not helpful.
* Reload projects when they change on the filesystem. Eclipse sometimes opens files with an error "This resource is out of sync with the filesystem" and no option to refresh it. Sometimes F5 on the project doesn't cut it and I have to restart the IDE. IntelliJ handles reloads smoothly, with a prompt and a quick reload.

and, to be fair, things that are handy about Eclipse:

* Opening multiple projects in one window. Our project structure was invented by Eclipse users, so instead of one project with several modules, we have several projects with tribal-knowledge-based dependencies between them. Having three IDEA windows open and switching between them was a pain.
* Make "missing @Override annotation" an error that occurs at compile-time, without a separate code-inspection step. Same with "empty method."
* Run tests when there are compile errors elsewhere in your project, in files that won't be hit by the test.

I'll add to this, and update it when people point out solutions. Suggestions in comments welcome.

3 comments:

  1. Here's my attempt to resolve some of your requests:

    "Save the file whenever it loses focus!"
    Don't know how to do that, but ctrl+shift+S saves all dirty files.

    "At the end of a line that contains an expression, command-shift-V to introduce a variable that stores the result of that expression."

    The default binding is ctrl+2, then L for a local variable or F for a field.

    "Static imports: from an explicit static method call, alt-space for suggestions including "static import""

    Doesn't quite work the same way: place cursor on method call and ctrl+shift+M.

    "Recognition and auto-import of static methods from certain files (such as JUnit assertions)"

    I believe what you are looking for is Window > Preferences > Code Style > Organize Imports then on the right, New Static...

    "add a private final field; have the IDE generate the constructor or add the parameter to the existing constructor."

    When there is no constructor, alt+shift+S, O pops up a window to choose the fields you want in the constructor (final fields are pre-selected).

    For existing constructors, I find it easiest to add the parameter, place cursor on it, then ctrl + 1 and assign parameter to new field.

    "Ctrl-W."

    Could you elaborate on what that does?

    ReplyDelete
  2. Thanks! the ctrl-2, L does exactly what I wanted. So does ctrl-shift-M!

    Organize Imports is not what I'm looking for -- IDEA will automatically import certain classes and methods with no prompting or extra clicks.

    I couldn't get alt-shift-S to work. Probably a Macintosh thing. What menu option is that activating?
    and you're right, that method works well for existing constructors; it even adds the field as final.

    Thank you for your help!

    ReplyDelete
  3. "IDEA will automatically import certain classes and methods with no prompting or extra clicks."

    AFAIK, the closest you can get to that are save actions, but those are triggered when you save the file. I guess you could change the New Java files code template to include the imports you want, but that feels weird.

    "I couldn't get alt-shift-S to work. Probably a Macintosh thing. What menu option is that activating?"

    It's equivalent to right-click > Source > Generate constructor using fields...

    ReplyDelete