Author Archive

Do you know where ‘Go To…’ can get you?

Thursday, January 19th, 2012

How often do you use ‘Go To Class/File/Symbol’ feature in IntelliJ IDEA? Pretty often I would guess. But do you know everything you can do with it? Let me go through a couple of often overlooked gems.

Do you know that when you search for file or class you can preview an image (Ctrl-Shift-I) or see a quick doc (Ctrl-Q)?

It is also possible to open multiple items in the editor (multiselect with Ctrl or Shift) or run multiple selected tests right from the search (Ctrl-Shift-F10).

And you can open all search results in the ‘Find’ tool-window to process them one by one later.

Did I mention your favorite feature? No? Please, share it with everyone! :)

IntelliJ IDEA does not show some files? Know the hiding-places

Thursday, April 28th, 2011

Have you ever found yourself in a situation when there is a file that exists on the disc but IntelliJ IDEA doesn’t show it anywhere? You press synchronize but nothing happens? OK, may be the next few tips will be helpful.

  • Check “Ignored files and folders” in File | Settings | File Types:
  • Check “Excluded roots” in File | Project Structure

Your files are shown in Project View but they are missed at runtime?

  • Check compilation patterns in File | Settings | Compiler
  • Check that they were not excluded from compilation in File | Settings | Compiler | Excludes

We hope that these simple tricks will save your time as well as ours. :)

Fork your tests with IntelliJ IDEA 10.5 EAP build 106.447

Tuesday, April 12th, 2011

One of the latest features was long awaited fork mode for JUnit run configurations. Since now it is possible to run your tests in separate VMs. It is possible to choose to fork on class level only.

Check out the list of all changes in the release notes on the IntelliJ IDEA EAP page and download the new build.
Btw, we are going to freeze IDEA 10.5 development soon, so we are actively looking forward for your feedback!

Java 7. @SafeVarargs

Friday, April 8th, 2011

Java 7 provides a way to remove a compiler warning about generics vararg invocation. With Java 7 you can annotate your vararg method with SafeVararg annotation and your clients won’t get these nasty warnings any more. IntelliJ IDEA 10.5 will help you to perform this migration. It will find for you all the places where @SafeVarargs annotation is applicable and suggest you to add this annotation. Of course, it will also check if existing @SafeVarargs annotations are applicable.

Suppose you have annotated your method with @SafeVararg but already have suppressions for unchecked warning in client’s code:

Since its version 6 IntelliJ IDEA contains an inspection to find redundant suppressions (available in batch mode only). Now you can use it to remove all suppressions which are garbage in your code. It will carefully check that these unchecked warnings were caused by generics vararg invocation and suggest you to remove all such suppressions. Simply run the ‘Redundant Suppression’ inspection (Ctrl-Alt-Shift-I).

All you need to do is to install Java 7 and setup language level to 7.

Download IntelliJ IDEA 10.5 EAP, try the new described features and let us know what you think.

More flexible and configurable @Nullable/@NotNull annotations

Tuesday, March 29th, 2011

For quite a while IntelliJ IDEA can detect probable NPE’s in your code. But you have to annotate it with JetBrains’ @Nullable/@NotNull. In order to leave your code free from JetBrains’ annotations you could use external annotations, but they were not so convenient to use as they were not visible in the code. With libraries and SDK code, however, there is no other way except using the external annotations.

So, to make things better, 10.5 IntelliJ IDEA will be able to recognize the most common annotations, such as javax @Nullable/@Nonnull, FindBugs @Nullable/@NonNull, as well as your own annotations with the same semantics.

You just need to configure which annotations are allowed in you code and which should be used by quick fixes to annotate the code.

Try it in IntelliJ IDEA 10.5 EAP and let us know what you think.

Smarter and Faster Introduce Parameter in Java

Thursday, March 24th, 2011

As a logical next step after inplace introduce variable refactoring we did in IntelliJ IDEA 10, version 10.5 will offer inplace introduce parameter.

Here is a brief overview of what we’re working on.

Once called, it will gently ask you to choose a method you want to add parameter to

Note, that you can introduce parameter in hierarchy by selecting the “Use super method of” option.

Then you’ll get a familiar template-like editor with a possibility to change parameter type and name. The refactoring settings you’ve got used to have in the dialog, are now available during template editing. You can make the parameter final, and generate method delegate, to remove unused parameters and replace field usages with getters. When multiple occurrences found you will be able to replace all of them or decide to replace only one right in place. No need to rerun the refactoring to see the results — they are already in the editor.

All method usages are already processed once you finish typing.

Just make sure you have inplace refactoring enabled in ‘IDE Settings | Editor | Enable in place refactorings‘.

The feature will be available in IntelliJ IDEA 10.5 EAP.

Watch our progress on inplace refactorings and let us know what you think!

Auto-infer @Nullable/@NotNull Annotations

Tuesday, December 14th, 2010

For a long time already IntelliJ IDEA can detect probable NPE’s in your code. You need to annotate your methods/fields/variables with @Nullable/@NotNull annotations and IntelliJ IDEA will highlight possible contract violations. Good. But the annotations only begin to work when there is enough of them in the code. You do need to annotate your code to get the benefits.

IntelliJ IDEA 10 can do it for you.

Just run Analyze | Infer Nullity… and choose a scope where you want annotations to be inferred. IntelliJ IDEA uses many rules to analyze nullity and make a decision. Here are just 2 examples:

1) The IDE detects parameters that are used without checking for null:

and presumes that they are @NotNull:

2) Variables that are checked for null are assumed as @Nullable, etc.

As a result you can benefit from static code analysis without paying an entrance fee.

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!

ThreadLocal in One Click

Friday, October 30th, 2009

Most of applications initially are single threaded, and IntelliJ IDEA was no different; though luckily, now it isn’t — but we had to adapt our code to use multiple threads. In this post I’m going to tell you how.

In our example we see SAXBuilder, which is too expensive to be created every time we need it, so it is stored in a static final field.

Because SAXBuilder is not thread safe, multiple calls to loadDocument from different threads cause a lot of interesting exceptions. This is why we need either to make access to this field synchronized, or to make the field ThreadLocal. In our case, we’re choosing the latter. We encapsulate the field, change its type and initializer, then fix a generated getter. Quite a lot of work, right? Luckily in Maia you can do it all in just one click. Just place caret on a field and press Alt+Enter to smoothly migrate it to ThreadLocal.

Create a Class Really Quickly

Tuesday, March 31st, 2009

To quickly create a new class I press Alt+Home and then Alt+Ins. And you?

Quick Create with Alt-Home Alt-Ins