IntelliJ IDEA 14.1.0 Help

Coding Assistance

In this section:

Both Eclipse and IntelliJ IDEA provide coding assistance features, such as code completion, code generation, quick-fixes, live templates, etc.

Quick-fixes

To apply a quick-fix in IntelliJ IDEA, press Alt+Enter:

migration_guide_quick_fix

All quick-fixes are based on inspections configured in Settings | Inspections:

migration_guide_inspection_settings

If you want to apply a quick-fix to several places at once (i.e. to a whole folder, module or even a project), you can do it by running the corresponding inspection via Analyze | Run Inspection By Name or by running the whole batch of inspections via Analyze | Inspect Code:

migration_guide_batch_inspections

Besides outright problems, IntelliJ IDEA also recognizes code constructs that can be improved or optimized via the so-called intentions (also available with Alt+Enter):

migration_guide_intention
EclipseIntelliJ IDEA
Action Shortcut Action Shortcut
Quick fix Ctrl+1 Show intention action Alt+Enter

Generating code

The key action for generating code is Code | Generate, available via Alt+Insert:

migration_guide_generate _code

This action is context-sensitive and is available not only within the editor, but also in the Project wool window and the Navigation bar:

migration_guide_cgenerate_code_project_tree

Code completion

IntelliJ IDEA is capable of giving you several different types of code completion, which include:

  • Basic completion
  • Second basic completion
  • Smart completion
  • Second smart completion
  • Statement completion

To learn more about the differences between these completion types, refer to Top 20 Features of Code Completion in IntelliJ IDEA.

Be default, IntelliJ IDEA doesn't show the Documentation popup for the selected item, but you can enable it in Settings | Editor | Code Completion | Autopopup documentatoin in (ms):

migration_guide_code_completion_settings

If you don't want to enable this option, you can manually invoke this popup by pressing Ctrl+Q when you need it:

migration_guide_code_completion_quick_doc

When the caret is within the brackets of a method or a constructor, you can get the infor about the parameters by calling Parameter Info with Ctrl+P:

migration_guide_parameter_info
EclipseIntelliJ IDEA
Action Shortcut Action Shortcut
Code completion Ctrl+Space Basic completion Ctrl+Space
Smart completion Ctrl+Shift+Space
Statement completion Ctrl+Shift+Enter

Templates

You may be used to typing main in the editor and then calling code completion to have it transformed into a main method definition. However, IntelliJ IDEA templates are a little different:

TemplateEclipseIntelliJ IDEA
Define a main method main psvm
Iterate over an array for itar
Iterate over a collection for itco
Iterate over a list for itli
Iterate over an iterable using foreach syntax foreach iter
Print to System.out sysout sout
Print to System.err syserr serr
Define a static field static_final psf

The list of available templates can be found in Settings | Editor | Live Templates. There you can also add your own templates or modify any existing ones.

While IntelliJ IDEA suggests templates in code completion results, you can quckly expand any template without using code completion simply by pressing Tab.

Postfix templates

In addition to 'regular' templates, IntelliJ IDEA offers the so-called postfix templates. They are useful when you want to apply a template to an expression you've already typed. For instance, type a variable name, add .ifn and press Tab. IntelliJ IDEA will turn your expression into an if (...==null){...} statement.

To see a complete list of available postfix templates, go to Settings | Editor | General | Postfix Completion.

Surround with live template

The surround with templates are another addition that works similarly to live templates but can be applied to selected code with Ctrl+Alt+J.

To define your own surround with template, go to Settings | Editor | General | Live Templates and use $SELECTION$ within the template text:

$LOCK$.readLock().lock(); try { $SELECTION$ } finally { $LOCK$.readLock().unlock(); }

Navigation

The table below roughly maps the navigation actions available in Eclipse with those in IntelliJ IDEA:

EclipseIntelliJ IDEA
Action Shortcut Action Shortcut
Quick access Ctrl+3 Search everywhere Shift x 2
Open type Ctrl+Shift+T Navigate to class Ctrl+N
Open resource Ctrl+Shift+R Navigate to file Ctrl+Shift+N
Navigate to symbol Ctrl+Shift+Alt+N
Quick switch editor Ctrl+E Switcher Ctrl+Tab
Recent files Ctrl+E
Open declaration F3 Navigate to declaration Ctrl+B
Open type hierarchy F4 Navigate to type hierarchy Ctrl+H
Show UML popup Ctrl+Alt+U
Quick outline Ctrl+O File structure Ctrl+F12
Back Ctrl+[ Back Ctrl+Alt+Left
Forward Ctrl+] Forward Ctrl+Alt+Right

Later, when you get used to these navigation options and need more, refer to Top 20 Navigation Features in IntelliJ IDEA.

Refactorings

The following table maps the shortcuts for the most common refactorings in Eclipse with those in IntelliJ IDEA:

EclipseIntelliJ IDEA
Action Shortcut Action Shortcut
Extract local variable Ctrl+Alt+L Extract variable Ctrl+Alt+V
Assign to field Ctrl+2 Extract field Ctrl+Alt+F
Show refactor quick menu Ctrl+Alt+T Rafactor this Ctrl+Shift+Alt+T
Rename Ctrl+Alt+R Rename Shift+F6

To learn more about many additional refactorings that IntelliJ IDEA offers, refer to Top 20 Refactoring Features in IntelliJ IDEA

Undo

Sometimes, refactorings may affect a lot of files in a project. IntelliJ IDEA not only takes care of applying changes safely, but also lets you revert them. To undo the last refactoring, switch the focus to the Project tool window and press Ctrl+Z.

Search

Below is a map of the most common search actions and shortcuts:

EclipseIntelliJ IDEA
Action Shortcut Action Shortcut
Open search dialog Ctrl+H Find in path Ctrl+Shift+F
References in workspace Ctrl+Shift+G Find usages Alt+F7
Show usages Ctrl+Alt+F7
Find usages settings Ctrl+Shift+Alt+F7
Occurrences in file Ctrl+Alt+U Highlight usages in file Ctrl+F7

Code formatting

IntelliJ IDEA code formatting rules (available via Settings | Editor | Code Style) are similar to those in Eclipse, with some minor differences. You may want to take note of the fact that the Using the Tab char option is disabled by default, the Indent size may be different, etc.

migration_guide_code_style_java

If you would like to import your Eclipse formatter settings, go to Settings | Editor | Code Style | Java, click Manage, click Import and select the exported Eclipse formatter settings (an XML file).

Note that there may be some discrepancies between the code style settings in IntelliJ IDEA and Eclipse. For example, you cannot tell IntelliJ IDEA to put space after (but not before). If you want IntelliJ IDEA to use the Eclipse formatter, consider installing the Eclipse code formatter plugin.

EclipseIntelliJ IDEA
Action Shortcut Action Shortcut
Format Ctrl+Shift+F Reformat code Ctrl+Alt+L

See Also

Last modified: 14 July 2015