Archive for March, 2009

Create a Class Really Quickly

Tuesday, March 31st, 2009

To quickly create a new class I press Alt+Home and then Alt+Ins. And you?

Quick Create with Alt-Home Alt-Ins

Excluding Classes from Auto-Import

Monday, March 30th, 2009

IntelliJ IDEA auto-import popup is a very handy feature that lets you stop worrying about import statements in your Java class files. However, sometimes it can show more choices than you need (e.g. when some of the class names in your project match the names of internal JDK or unrelated library classes).

To make auto-import easier to use and to avoid accidental imports of wrong classes, you can open the Settings dialog, then go to Editor | Auto-Import and add their package prefixes to the exclusion list. This will also hide the specified classes from class name completion lists.

Towards Side Effectless Assert Statements

Friday, March 27th, 2009

It is a well known rule that assert statements should cause no changes in state outside of them (aka side effects). Until now, you could only check if this rule was followed by visually inspecting the code. In IntelliJ IDEA 9 a new assert statement with side effects inspection will be available to help you keep assert statements free of side effects.

'assert' has side effects warning

The inspection will warn about modification of variables and fields inside of the assert statement. The assert statement will also be reported if a method called by it modifies any fields.

Quick Navigation to Project Structure

Friday, March 27th, 2009

To change settings of a module that hosts the file you are currently editing, just press Alt+F1, 7 or open the View menu, select Select In and click Project Structure.



IntelliJ IDEA will open the Project Structure dialog and jump to the required module.



This action works for files from libraries and JDK, too, and is available in every view that lists files — Project View, Changes tool window and so on.

Code Foldings for I18n Support

Thursday, March 26th, 2009

As you may know, IntelliJ IDEA 8 includes the complete i18nization support. In IntelliJ IDEA 9 (Maia) it will be improved with special i18n foldings that would allow to hide method calls, retrieving properties from resource bundles and replace them with actual property values.


If properties contain any parameters, they will be automatically evaluated before displaying.

No More Missing TestNG Tests

Wednesday, March 25th, 2009

I often forget to add newly created tests to the testng.xml, which is used in our TeamCity build, and by the time I realize that they don’t run something is surely went wrong. What a bummer! Not any more, fortunately — IntelliJ IDEA makes sure no tests are missing. All it takes is to enable the Undeclared test inspection under TestNG in the Errors section of the Settings dialog.
Undeclared Test Warning

Smart Completion of Java Primitive Method Parameters

Tuesday, March 24th, 2009

Many API include methods like setXxx(int) where int is one of the predefined values, typically declared in the same class. The fact that these are just legacy methods that have been created prior to enums invention, does not stop IntelliJ IDEA from helping you with such parameter values. For example, have a look at JList#getSelectionModel. Just invoke the Smart Completion (Ctrl+Shift+Space) inside the call parentheses:

Smart Completion for Primitives

User Defined Language Injection

Friday, March 20th, 2009

In IntelliJ IDEA you can quickly configure language injection for XML tags, attributes and Java method parameters and their return values. Just use Inject Language Intention on the code like this:



and it will immediately turn to:




And you get the complete coding assistance, with syntax and error highlighting, completion and navigation.

This functionality is provided by the bundled IntelliLang plugin. The full configuration is available for edit in the Settings dialog (see screenshot below). Default configuration includes various mappings like RegExp language in Pattern.compile(), SQL in JDBC API calls, JPA & Hibernate QL injections and much more.

Spring Webflow Support in IntelliJ IDEA 8

Thursday, March 19th, 2009

IntelliJ IDEA 8 support for Spring Webflow includes:

  • Smart code completion, with all expression attributes
  • Syntax and error highlighting
  • Code generation
  • Rename refactoring
  • Usage search
  • Graphical flow designer
  • and more.

Quick Code Cleanup

Thursday, March 19th, 2009

With IntelliJ IDEA you can quickly clean up your legacy code. If a problem occurs multiple times in a file, you do not need to manually apply a quick-fix every time — use the Fix all intention to repair them all at once.