Archive for the ‘Tips & Tricks’ Category

Invoking Run/Debug Actions in IntelliJ IDEA 9

Monday, October 26th, 2009

In IntelliJ IDEA 9 (Maia), we’ve slightly changed the way you run and debug your applications. You’re still able to quickly run or debug a previous configuration (Shift+F10/F9), as well as to create and run/debug a temporary configuration in a context-dependent manner (Ctrl+Shift+F10/F9). However, it’s now much easier to select and run/debug different configurations from the keyboard.

In IntelliJ IDEA 9, you can choose a configuration that you wish to run with one of the following shortcuts:

  • Alt+Shift+F9 to debug your application.
  • Alt+Shift+F10 to run it.

Invoking any of these actions displays a pop-up window with available configurations, like this:

You can edit a configuration before launch (press F4) or show a configuration dialog box to edit all your configurations and their default settings (press 0). You can also instantly delete a temporary configuration by pressing Delete.

That’s not the end of the story: you’re now able to temporary switch to an opposite action directly from this pop-up window by pressing and holding Shift. When you do that, Run becomes Debug and vice versa.

And even more: we’ve extended the pop-up window with context-dependent configurations. That means whenever you press Alt+Shift+F10 right in a test method’s body, the pop-up displays a temporary configuration to run the current method only or all tests from the current test class.

We’ve also added a number of quick access shortcuts:

  • 1 for a previously selected configuration.
  • 2 and 3 for context-dependent configurations.
  • 0 to display the Edit Configuration dialog box.

One more tip: we’ve mapped this pop-up to F9 (debugger’s Resume Program action). The pop-up now displays on pressing F9 when you’re unable to actually resume anything - that is, when you’re not yet running any debug session.

Intelligent Copy&Paste

Friday, October 2nd, 2009

Do you find yourself copying and pasting parts of bodies between different methods and then facing broken code?

Unfortunately, parameter names tend to differ — like in this (very simplified) example:

Nothing is easier than fixing this problem with a few keystrokes in IntelliJ IDEA!

First, move caret on any red reference (highlighted with red color), or simply press F2, and then invoke available Quick-Fixes via Alt+Enter:

Now select Rename Reference (again, you can use arrow keys or just start typing Ren.. + Enter) and… IntelliJ IDEA fixes code for you!

See, sometimes it’s just the small features making it possible to achieve maximum productivity.

Quick Lists to Group Your Favorite Actions

Thursday, October 1st, 2009

There’s a lot of useful actions in IntelliJ IDEA that don’t have shortcuts for many different reasons: they’re not used too often or there’s simply no more convenient key combinations left.

For example, I often want to get access to VCS actions like Compare with latest repository version or Revert current file or even submit a single file with a quick NPE fix without opening a menu or going to Changes view.

So how can I call any of these actions with a single shortcut? That’s really easy: I just need to define my own Quick List and map it to a shortcut (Control-X in my case). After I’ve done that, every time I press Control-X I will get a pop-up like this:

Quick List in action

Quick List in action

Now I can press 5 to quickly commit the current file or 2 to revert all my changes. OK, now let’s see how to create a Quick List and assign it a shortcut.

(more…)

Improved Linking of Perforce Jobs

Thursday, August 27th, 2009

In the upcoming Maia EAP you will find a slightly different Commit Changes dialog.

  • Automatic use of JobView filter on search results.
  • Support for Perforce native search query syntax (in an example below we’re looking for Job in any field)

search result

Original IntelliJ Cast

Friday, August 14th, 2009

Let’s talk about type casts — those things you hardly can avoid in JVM-based code. Being a helpful IDE, IntelliJ IDEA now does all the casting stuff for you when you are using its code completion in Java and Groovy.

To get you started, have a look at this Groovy example. In a dynamic language there’s almost no need in type casting at all — you just invoke any method on any object and hope it won’t fail. IDE can help you here, suggesting a list of acceptable choices based on preceding type checks:

In Java, there’s always a need in explicit casting. It’s easy of course, when you know the type to cast expression to. Smart completion after opening parenthesis has been able to do this for ages:

Imagine you’ve just checked an expression type via instanceof and now you want to invoke a method on the cast expression. Quite a natural wish, isn’t it? A week ago you had to write a cast manually, use a light bulb intention action or inst live template. Now you just invoke code completion after the cast expression and it suggests the members of the cast type. A lot simpler, right? Of course, the cast will be inserted automatically:

This works for both basic (Ctrl+Space) and smart completion (Ctrl+Shift+Space). I’ve been using this feature for 2 days now and I already can’t understand how could I survive without it through all the previous years.

Impressed already? But, there’s more. Say you’ve just checked that a certain expression has certain type. Then, you may want to cast that expression and assign the result to a variable, or pass it to a method. All you need is smart completion:

Moreover, as you know, IntelliJ IDEA has second smart completion feature. It’s now also aware of the run-time type checks that you made. After such a check you can perform cast and method invocation in a single action! Well, actually, you have to press Ctrl+Shift+Space two times, but that still counts:

Enjoy!

Analyzing Dataflow with IntelliJ IDEA

Wednesday, August 5th, 2009

Upcoming IntelliJ IDEA version, Maia brings you an improved version of the Dataflow to this feature and the completely new Dataflow from this.

Here I am describing how these features work and how they can help you the Code Archeologists better understand your code.

I am using Apache Tomcat source code as an example.
Let’s have a look at the SingleSignOnMessage class and its obscure String authType field.

(more…)

5 Cool Shortcuts You Have Probably Never Tried

Thursday, July 30th, 2009

I’d like to tell you a bit about a bunch of cool IntelliJ IDEA shortcuts you have probably never heard of.

Ctrl+W/Ctrl+Shift+W When it comes to precisely selecting a value, expression, statement or any other block of code, these shortcuts are a real killer. Just try it to see how quicker it works than traditional Ctrl+Shift+NavKeys combo.

Ctrl+Shift+F12 This hides everything but the editor and so leaves you tête à tête with the code.

Ctrl+Tab, Delete Pressing Delete when Switcher is open (Ctrl+Tab) allows you to close arbitrary editor tabs and hide tool windows (available in Maia builds 10612 and later).

Ctrl+Alt+Shift+Up/Down If you are using Version Control integration, you gonna love this because so you can quickly navigate between changes in a file.

Alt+Home Summons Navigation Bar to an active window, so you can now hide it from under main menu and quickly use whenever needed. By the way, all the cool shortcuts (Alt+Insert, for example) work nice inside of Navigation Bar, which lets you create new files, classes, and everything really really quickly.


Hope this all makes development even more a pleasure!

Ctrl+Tab Switcher in Maia

Wednesday, July 8th, 2009

Maia brings a new powerful action Ctrl+Tab that allows you to switch between open files in editor and tool windows. It works similar to Alt+Tab on Windows or ⌘+Tab on Mac.



There are two columns: tool windows and open files (tabs). Navigation is available through the use of navigation keys and Tab (forward) or Shift+Tab (backward) keys.

Is there anything else you think would be handy to have in Switcher Panel?

Find Action Saves Time

Tuesday, June 9th, 2009

Instead of wasting your time searching the menus and toolbars in an attempt find out that action you need right now, use the Find Action command (Ctrl+Shift+A) to quickly locate what you need. It works just like Go to Class:

Find Action (Ctrl+Shift+A)

On-demand Tooltip for Values in Debugger

Wednesday, June 3rd, 2009

In Maia you can quickly look up a value in a debugger session by hovering your mouse over it (which is very handy for text values, for example):


When you need to browse through a large tree of values, this popup can be set to appear only after you invoke it.


The trick is that it is still viewable, but only when you hover mouse over a value holding the Alt key. Hitting Alt when the popup is open hides it — but that’s what you probably have already guessed.

There is also an option in the Settings dialog: