Pages

Wednesday, June 29, 2011

What’s Cool In IntelliJIDEA. Part I

Eclipse or IntelliJ? NetBeans or Eclipse? IntelliJ or NetBeans? The dispute about the IDEs is the most popular among the software developers and hardly will ever end. I consider myself being a big IntelliJ fan, but I do realize that there are a lot of things that IntelliJ could do better and that NetBeans and Eclipse are better in some ways. In this post I’d like to make an overview of IntelliJ’s features which I like the most, and and beyond that. Also I’d like point out some of the aspects in which IntelliJ could do better.

UPDATE: due to the popularity of this blog post I took some time to combine my blog posts about IntelliJ IDEA into one big article, published at RebelLabs as Getting Started with IntelliJ IDEA as an Eclipse User. You will find it interesting, I'm sure :)


Other post in the series:
One of my friends said once:
I don't like IDEs. They help to write verbose code. In real life 90% of time I spend on code reading. Verbose code kills my productivity

I think he's wrong. The reality is that IDEs are used not only for writing/generating code, but to a greater extent IDEs are used to read and analyze the code. You might be a hard-core Emacs/Vim ninja but still, there are things that you just cannot do with the text editors.


Navigation


Navigation through the source code is one of the activities that programmer executes on a regular basis. Basically, it is not hard to navigate the code with Emacs or Vim, but it would limit you only to a basic navigation options. IDEs take navigation abilities one step further.

Let's see what are the navigation features in IntelliJ. First of all, "Open Type" which is executed via Ctrl+N:


The same can be achieved with Ctrl+Shift+T in Eclipse and the behavior is exactly the same.

Ctrl+Shift+N will help you to open any resource. Eclipse does the same with Ctrl+Shift+R.

And it could have been all but there's more - Ctrl+Shift+Alt+N will find you all the appearances of a specific symbol, e.g. a method name:


It doesn't mean IntelliJ will scan the code for the occurrence of the specific symbols but it rather will match the code structure and look for the elements in your code so you will get a list of method declarations but not just any appearance of the method name in the code. This is quite useful if your classes are not sharing the same hierarchy.

Often when you navigate the source code you jump over class hierarchies, browse different methods, open type declarations, etc. It is quite common that once in a while you would like to step several steps back in your navigation and proceed with some other direction. Ctrl+Alt+(left|right) arrow is a very useful shortcut for such purpose. Whenever a caret hits any place in the code this place is remembered and you can go back and forward in the your browsing history. This is quite cool as if you navigate a large code base you might not even remember which classes you actually opened just a second ago.

Actually you can get a list of the recently visited files by pressing Ctrl+E - also quite often used to reopen the recently closed files.

Navigating back in forward is the same in Eclipse (with Alt+(left|right)arrow shortcuts). But I failed to find a list of recently edited files there, while this can be done in IntelliJ by hitting Ctrl+Shift+E shortcut.

There are plenty of other feature that make your code browsing experience more pleasant. For instance, both IntelliJ and Eclipse provide a feature to quickly browse the location of the currently opened class - Alt+Home will popup a navigation bar with the path to the class.

The cool feature in IntelliJ for this navigation par is that it is possible to brows the content of any file with Ctrl+Shift+I without having to really open the file:


In Eclipse a similar feature is called "Browse in Breadcrumb" called via Alt+Shift+B. The difference is that in Eclipse it works only if a Java type is opened and it acts only as a navigation bar - no quick preview available. Also, I didn't find an easy way how to get rid of that "Breadcrumb" in Eclipse besides clicking a dedicated button on the toolbar.

Ctrl+Shift+I also works in IntelliJ for any symbol that you'd probably like to inspect. For instance, you may press this shortcut on any method call, and it will raise a popup that displays the methods source code:


Also, if you try to browse the code that maybe involved in the type hierarchy, it is possible to select the implementation by choosing the type in the very same quick view popup:


Talking about navigation on the hierarchy of classes, IntelliJ implements that also quite nicely - quick hierarchy view is available the same way as in Eclipse. The feature that distinguishes IntelliJ is the ability to easily navigate to implementation. For instance, from interface method declaration to any of the implementations. If there are multiple implementations of an interface method Ctrl+Alt+B will call a popup dialog with the list of implementations:


Disqus for Code Impossible