Author Archive

Complete static methods and fields with the new IntelliJ IDEA 12 EAP build 122.29

Thursday, August 9th, 2012

Did you know how to quickly complete a static method call or a constant reference without writing the class name first? Just type some prefix and invoke Basic Code Completion (Ctrl+Space) twice (or Ctrl+Alt+Space once):

There are two problems though:

  1. The entire project is searched and there might be just plain too many completely unrelated suggestions, and it’s hard to search among them what you need.
  2. You may not remember the name of the member you want while knowing what it type should be.
Now we have a solution for these problems. It’s the plain old second SmartType Completion (Ctrl+Shift+Space). It now also scans the entire project for static methods and fields, but suggests only those whose type is suitable in the context:
This may be very handy with collection libraries like Guava:
You can try this in the new EAP: build 122.29. Of course, it contains other improvements as well: code completion has become faster in Java, Groovy extensions are now recognized in more cases, Extract Style refactoring for Android, etc. Simply download the build or “Check for updates” in the IDE itself.

Better Code Completion in IntelliJ IDEA 12 Leda

Wednesday, July 11th, 2012

As you know code completion in IntelliJ IDEA constantly evolves. Here’s a few new features coming in IntelliJ IDEA 12:

  • Middle matching
  • Class Name Completion in Basic Completion
  • Completion statistics in Productivity Guide
  • Other minor improvements

(more…)

Groovy support improvements in IntelliJ IDEA 11.1

Tuesday, April 3rd, 2012

Here I would like to tell you about some of the Groovy language support improvements available in IntelliJ IDEA 11.1.

Unused Symbol Highlighting

If a class, method or property is unused even if it is in fact public, you may notice it immediately with new unused symbol highlighting feature.

(more…)

Want more from IntelliJ IDEA? Press the same shortcut again!

Wednesday, February 22nd, 2012

Sometimes you invoke an action and you don’t get what you wanted immediately. In such cases it may help to invoke the action again by pressing the same shortcut. In basic code completion (Ctrl+Space) this will list non-imported classes:

It works in similar way for smart-type and class name completions:

In File Structure popup (Ctrl+F12) you will show inherited members with it:

When introducing a variable (Ctrl+Alt+V), you may want to reassign an existing one instead:

I may have missed something, but all this is already available in IntelliJ IDEA 11. And there’s a couple more nice things you can try in IntelliJ IDEA 11.1 EAP. First, all Goto actions (Ctrl+N for classes, Ctrl+Shift+N for files etc.) now expand their search scope after you press their shortcut again. For example, Goto Action (Ctrl+Shift+A) suggests to search in non-menu actions:

Finally, Show Usages action (normally Ctrl+Alt+F7, remapped to Meta+Alt+F7 by me) will expand the search scope as well:

Try it and tell us how you like it.

Chained expression completion in IntelliJ IDEA 11.1

Monday, February 20th, 2012

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.

Shiftless code completion and navigation in IntelliJ IDEA 10.5

Friday, April 15th, 2011

With IntelliJ IDEA 10.5, you may press up to twice as less keys every day as you do now. Seriously! Here’s how.

The reason IDEs exist in the first place is that they make your life easier. In particular, they are able to generate code for you. An ideal IDE would do all the boring typing by itself, leaving you more time for thinking about the great software engineering problems you face. Unfortunately, such an ideal is not there yet. Currently, if you want an IDE to help you, you first have to help it help you. Usually this means giving it some cues on a word you have in mind, and it then tries to guess the whole word. So you can just type  NPE and smart IntelliJ IDEA will suggest that you must have meant NullPointerException. Or StBui for StringBuilder. I’m sure you get the idea. This handy “camel case” matching feature saves quite a lot of typing.

Here it gets complicated. In the first place, you had to so something (coding) and the IDE was there to help you. Now you have to do something easier, namely giving the cues to the IDE. But since this requires some action from you, why couldn’t IDE help you with this as well? This means helping you help the IDE help you :). But how can such a simple task as giving the cues be made even simpler?

As it’s easy to see from the examples, the “camel case” matching requires you to enter LOTS of capital letters. And this means pressing Shift quite often. Very often. In fact, almost always. But is this really needed? Following our colleagues from ReSharper team, we asked ourselves this question and, like they, have found no adequate reason. After that we just removed this requirement to press Shift in IntelliJ IDEA. Well, you can still do it, and the capital letters will match “camel hump” starts as they did before. But why bother if you can get the same result without Shift? OK, chances are that you’ll see a bit more variants in this case, but this still pays off in the productivity.

Shiftless matching is now everywhere in IntelliJ IDEA.

When searching for a class (Ctrl+N / Cmd+N):

When typing in the editor with the autopopup enabled:

In the File Structure popup (Ctrl+F12 / Cmd+F12):

So, grab an IntelliJ IDEA 10.5 EAP build, rest to your little fingers and enjoy!

Custom file types in IntelliJ IDEA

Tuesday, September 14th, 2010

IntelliJ IDEA is a great IDE for Java, Groovy, Flex, Python, Ruby and many other languages. The text editor with camel-hump completion, and version control support are so great that it may be hard to switch to another editor which may lack some useful features. So, when a need arises for me to code in a language that’s not listed on the features page, I just teach IDEA some basics about that language, and feel much more comfortable than I would if I was editing a plain text. Luckily, you don’t have to write a plugin for that, it is possible via the GUI.

Assume you want to edit Haskell code in IDEA. You go to IDE Settings | File Types and press the ‘Add‘ button next to the file types list:

This brings a dialog where you can provide some knowledge about Haskell: case sensitivity, brace matching settings, ways of defining comments and keywords. You can have up to four lists of keywords, which will be colored differently in the editor. And, of course, all of them will be auto-completed.

After you are done with this dialog, all that remains is to assign the *.hs extension to the newly created file type:

And enjoy hacking:

Groovy/Groovy++ object creation

Thursday, August 5th, 2010

Groovy’s as keyword allows for some interesting features. In particular, it provides a convenient syntactic sugar for object creation:

Point point = [4, 2] as Point
KeyAdapter listener = [
        keyTyped: { e -> … },
        keyReleased: { e -> … }
] as KeyAdapter

Still in development, but already quite usable, there is Groovy++: a library which adds static typing, performance and much more to Groovy language. One thing you get addicted to quite soon is that you don’t have to write as in the cases above anymore. If the compiler can statically figure out the expected type, it will insert all the necessary casts for you. This works, for example, for variable declarations, method return types and even method calls. So, if you have

JComponent comp = …

you can then write

if (comp.contains([x:2, y:4])) { … }

Cool, isn’t it? But why am I writing about all this in IntelliJ IDEA blog? Well, just to boast. Unusual syntax is not a reason for not helping you in coding, right? So, now the converted list/map literals will be shown if you search for the constructor usages in IntelliJ IDEA:

And the syntax highlighting on the brackets will help you distinguish between plain list/map literals and the ones that serve for object creation:

Finally, you can easily navigate to the constructor called via a literal. Just place your caret before the opening bracket and go to the declaration (e.g. press Ctrl+B)!

All this will be available in the next IntelliJ IDEA X EAP.

Console folding customization

Monday, July 12th, 2010

Once I wrote about console folding for Groovy stacktraces. Naturally, many people wished similar things could work for other languages and frameworks. Long story short, there’s now a settings page dedicated to the console folding. It provides a settings page where you may specify which console lines to fold:

This functionality is available in IDEA 9.0.2 via Console Folding plugin. In IDEA X, it will be bundled. Furthermore, there will be a nice addition to these settings: an action that allows you to add folding rules very easily right from the console. Just select the fragment which will toggle the folding of the lines containing it, and right-click:

Groovy stacktrace folding

Wednesday, March 17th, 2010

When you look at a typical Groovy stack trace, you usually see something like this:

This is not terribly helpful, since there are only three lines from the actual source code. Everything else refers to Groovy’s internals. From now on, though, reading Groovy stack traces will be much easier: