Features

Chained expression completion in IntelliJ IDEA 11.1

If you use completion autopopup in IntelliJ IDEA 11, you may have seen “n variants…” suggestions:

This means there are two StringUtil classes available, neither of them is imported, and IDE can’t choose which of them to put to the first place. When you choose such variant no new import statements will be added. The good side is that you won’t get wrong imports after pressing space, dot or a bracket. The bad side is that you eventually have to face this choice: you may either explicitly invoke completion (Ctrl+Space) again or choose the correct qualified name from the auto-import hint which appears after choosing the item.

Here’s a good news though, now (since IntelliJ IDEA 11.1) you don’t ever have to choose the qualified name. In this particular case, you just type a dot, no import is inserted as before, but the next completion autopopup will list all the possible static members from both possible StringUtil classes:

Needless to say, after you choose the method you want all the necessary imports will be added.

In fact, this feature is even more powerful. It tries to enumerate all the completion variants matching the non-existent qualifier and suggest chained calls based on this. So you may spare some typing even if you don’t use autopopup (or have hit dot too early before it appeared):

Ah, yes, this works in Java and Groovy code.

image description