Archive for the ‘Tips & Tricks’ Category

Smarter and Faster Introduce Variable in Java

Thursday, November 11th, 2010

Introduce variable is one of those refactorings used many times a day. So, how can we make it work faster?
Get rid of modal dialogs!

So, in order to introduce a variable from an expression press Ctrl+Alt+V.

Remember modal dialog? No more of it! Now you can edit your code right in the editor:

Oh, you prefer List as variable type? No problem, press Shift+Tab, choose List from drop down and IntelliJ IDEA will remember your choice for future.

You already pressed Ctrl+Alt+V but then realized that such variable already exists? Not a problem! Now it is possible to reassign a variable right from introduce template. Press Ctrl+Alt+V one more time and IntelliJ IDEA will collect all available variables of appropriate types and will suggest you to choose one:

You can try it yourself using a latest IntelliJ IDEA X EAP.

And let us know what you think!

Faster XML coding with new completion features

Wednesday, October 27th, 2010

How often do you write XML configurations like that above? How many keystrokes does it take?

This one is written in just moments, with the help of the new completion features coming in IntelliJ IDEA 10. First of all, the IDE completes all required subtags for you, even nested ones. Second, you can use smart completion feature to ensure that the tags you write are in order described in your XML schema.

If you do not know where your new tag should be inserted, invoke the Generate / XML Tag action from context menu, choose the tag you want, and IntelliJ IDEA will generate a completely valid XML structure and insert it in the right place of the document.

Download the latest IntelliJ IDEA EAP build and try this in the next XML file you open.

Grails: extracting text from GSP to resource bundle

Wednesday, October 27th, 2010

By user requests we have added functionality for easy extraction of GSP text to resource bundles. To do this you can select a text fragment, press Alt+Enter and choose the intention “Extract selected text to messages.properties”:

I18nize String dialog will open:

This feature is available in IntelliJ IDEA X #98.231

Grails: debugging GSP

Friday, October 22nd, 2010

Now IntelliJ IDEA X is able to debug GSPs. You can set breakpoints and view variable values or evaluate expressions.

A Few Little UI Tricks

Monday, October 11th, 2010

Here are some new UI-related tricks which you may find useful:

1. Docked Navigation Bar (View | Navigation Bar) now shows Run/Debug controls if the toolbar is switched off.

2. You may also switch off Tool Buttons (View | Tool Buttons) and get them to appear on demand by pressing Alt key twice (or Command key on Mac OS X).

3. If the new dark tooltips on Mac OS are too hard for your eyes, go to “IDE Settings | Appearance | Tooltip mode” and set it to “System”.

These new features are available since recent IntelliJ IDEA 10 EAP, so try them now and tell us what you think!

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:

No more misspellings in your VCS commit comments

Thursday, August 26th, 2010

How many times you wished you could edit your last VCS commit comment to correct a misspelling?

Now you will notice such mistakes because IntelliJ IDEA 10 checks the spelling in the comment field.

And it not just spellchecks the text, it runs the Spelling inspection on it and uses your custom dictionary too. Hit Alt+Enter/⌥↩ on an underlined word and fix it as you normally fix things in IntelliJ IDEA code editor.

Spellchecker is also enabled in other dialogs throughout the IDE, e.g. Search/Replace dialog.

Try IntelliJ IDEA X EAP and let us know your impressions.

Getting External Libraries Easily

Friday, August 13th, 2010

JARs of many frameworks and their dependencies get updated too often now. But you do not want to turn your project into a Maven project just because of this? Then this feature is just for you.

In IntelliJ IDEA 10 you can search for & download libraries with dependencies for any framework published on some public maven repository. Minimum Maven experience is required. Just click ‘Attach Classes from Repository…

You can add your company repository to the list of searched repositories, if it is managed by Nexus, by providing the Nexus URL in Settings | Maven | Repository Indices | Nexus Locations list.

Try this in IntelliJ IDEA X EAP and let us know how it works for you.

UPDATE JavaDocs & Sources download as well as the Artifactory support are now available.

Tracing back changes in IDEA X

Thursday, August 12th, 2010

When diving into code details, the most common question would often be:

- Why does this line stay here?

When annotation doesn’t give the answer, jump into the change contents in one click:

(coming in next IntelliJ IDEA EAP)

Full-featured IntelliJ IDEA Editor for Injected Language Fragments

Tuesday, August 10th, 2010

You probably know about IntelliJ IDEA’s language injection feature. Right?

IntelliJ IDEA X takes it even further. Now you can edit fragments of code injected in literals in a designated full featured editor with all your changes immediately reflected in the original code.

You do not see all other code around the injected fragment. There’s no need to worry about code escaping. No modal popups. Just do what you need to. The fragment editor opens in a convenient split mode remembering your caret position and closes instantly when Esc is pressed.

The feature is available for any combination of injected language that IntelliJ IDEA supports, e.g. SQL in Java, HTML in JavaScript, and many others.

All the editor functionality including completion, code inspections, intention and code style actions is of course available in the fragment editor.

And a couple of examples. JPA QL fragment editor:

HTML fragment editor:

Your feedback is welcome!