Tag: ide

Recently I switched from using Eclipse to IntelliJ IDEA as our Java EE application’s front-end was done with JavaScript and the support for front-end technologies in Eclipse is more or less non-existent. The switch for long time Eclipse user wasn’t easy as IDEA works a bit differently but the change was worth it. The biggest difference in daily work with IDE is the shortcuts which are quite different in IDEA. In theory you can use Eclipse keymap for shortcuts but it just doesn’t work like it should and in practice you have to learn the IDEA way. There are many posts in the Internet about keyboard shortcuts in IDEA but there’s always place for more :) So, here’s my list of shortcuts to keep in your finger memory.

Learn keymap with Key Promoter

To learn your way around IntelliJ IDEA’s keyboard shortcuts there’s nice “Key Promoter” plugin to train yourself. It prompts whenever you use the mouse when you could’ve used the keyboard instead (similar to Eclipse’s Mousefeed).

To install the plugin:

Ctrl+Alt+S to pull up the Settings screen

Filter on “plugin”. Click “Plugins”, then “Browse Repositories” at the bottom

Filter on “key promoter”

Double click to install

Essential IntelliJ IDEA keyboard shortcuts

You may be tempted to just go with the Eclipse keymap but it’s better to learn the IDEA way although it’s quite irritating at start. You also should change some default IDEA keyboard shortcuts to better ones like “closing editor window” with Ctrl+F4 which is too cumbersome compared to the de facto Ctrl+W. And changing “comment current line or selection” with Ctrl+/ which is impossible with Finnish keyboards to Ctrl+7.

Recent Viewed or edited Files: CTLR + E / CTRL + SHIFT + E
Shows you a popup with all the recent files that you have opened or actually changed in the IDE. If you start typing, you can filter the files.

Go to Class or file: CTRL + N and CTRL + Shift + N
Allows you to search by name for a Java file in your project. If you combine it with SHIFT, it searches any file. Adding ALT on top of that it searches for symbols. (Eclipse: Ctrl+Shift+T and Ctrl+Shift+R)

Syntax Aware Selection: CTRL + W
Allows you to select code with context. Awesome when you need to select large blocks or just specific parts of a piece of code.

Complete Statement: CTRL + SHIFT + ENTER
This will try to complete your current statement. How? By adding curly braces, or semicolon and line change.

Smart Type Completion: CTRL + SHIFT + SPACE
Like auto complete (CTRL + SPACE) but if you add a SHIFT you get the smart completion. This means that the IDE will try to match expected types that suit the current context and filter all the other options.

Quick Fix: Alt+Enter
(Eclipse: Ctrl+1)
Gives you a list of intentions applicable to the code at the caret.

Paste one of the previous values from clipboard: CTRL + SHIFT + V
Shows you a dialog to select previous value from the clipboard to be pasted.

Comment or uncomment line or block: Ctrl+7 / Ctrl+Shift+7
Allows you to comment or uncomment the current line or selected block of source code. This is originally Ctrl + / (Slash) which is impossible with Finnish keyboard layouts.

Refactoring String Fragments: CTRL + ALT + V
Refactor hardcoded string into variable/field/constant. Select the section of the String you want to extract, and use the normal “Extract…” shortcuts to extract it into a variable.

Other useful keyboard shortcuts

There are many useful keyboard shortcuts and you can print them from Help > Default Keymap Reference. Here are some more shortcuts which are also handy.

Not a keyboard shortcut exactly but the “iter” smart template is great. If you want to iterate though something using a for loop type “iter” then TAB to use the live template. It will figure out the most likely variable you want to iterate over and generate a for loop for it. In Eclipse it worked more logically with just typing for and then autocomplete.

Eclipse likes to validate JavaScript when doing Dynamic Web Modules and thus may give you false positive validation errors on 3rd party JavaScript libraries like JQuery. Although you can turn off the validation altogether but better solution is to configure it to exclude files as Alexander shows us at Stackoverflow.

Eclipse Indigo (3.7) has the option to selectively remove some JavaScript sources from validation. The information about JavaScript source inclusion/exclusion is saved into .settings/.jsdtscope file.

Right click your project

Select Properties → JavaScript → Include Path

Select Source tab

Expand JavaScript source folder

Highlight Excluded pattern

Click Edit button

Click Add button next to Exclusion patterns box

You may use wildcard pattern, or click Browse button to add the source by name.

Exclude all JQuery files with pattern like: js/jquery-*

The configuration with JQuery files excluded from validation looks like this:

Eclipse is nice IDE but it has it’s own problems. This time the Java Search and Open Type -search produced an error saying “Class file name must end with .class”. Very helpfull. Fortunately almost all the answers in the world can be found in the Internet and so with a quick googling the solution to this annoying problem was found on Stack Overflow.

I had already tried Project -> Clean… and closing Eclipse, deleting all the built class files and restarting Eclipse to no avail as was the original question author. The right answer lies in deleting the corrupted search index which is explained in Eclipse bug’s #269820 comment.