Posts Tagged ‘completion’

More intelligence for web.xml editor

Wednesday, March 3rd, 2010

With IntelliJ IDEA 9.0.2 you can enjoy editing web.xml with the new initial parameters support. IntelliJ IDEA now collects parameter names and is also aware of parameter values types. This allows the IDE to generate (with Alt-Insert), complete, highlight and validate them appropriately.

web.xml context-param completion

Grab the latest EAP of IntelliJ IDEA 9.0.2 to try it today.

If you are a plugin writer, you can provide your specific context parameters through the special com.intellij.javaee.model.xml.converters.ContextParamsProvider extention point.

Super Completion

Tuesday, September 15th, 2009

Do you often find yourself calling a super method with a large number of parameters? Typing all those arguments one by one is soooooo boring, isn’t it?! Don’t be upset anymore — latest Maia EAP can rescue you. Just use Smart Completion (Ctrl+Shift+Space):

Debugger Evaluate Expression Enhancements

Monday, September 14th, 2009

Say, you hit a breakpoint in Java code:

And you cleanly see that component is a label:

You now want to investigate label internals via Evaluate Expression (Alt+F8), e.g. invoke its getText() method, but component declared type is Component and it does not have this method! The only way out is to use Surround with run-time type (Ctrl+Alt+T) first to cast it to JLabel and only then completion becomes available:

Not anymore it isn’t. IntelliJ IDEA tries to help with casting wherever possible, so you can now get the same results using Basic code completion (Ctrl+Space) only:

…press Enter and the cast is done for you:

Needless to say, it works with Smart completion (Ctrl+Shift+Space), too. It works even for complex expressions with method calls. Note, that method evaluation can take a lot of time, not to mention the possible side effects, so evaluating expressions every time you hit completion is not so nice. This is why you need to press the same shortcut twice to get the run-time type variants. That’s what you’re going to see at the bottom of completion list:

And you can play with all this now!

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!

Named Parameters Completion in Groovy

Tuesday, June 9th, 2009

Groovy language support becomes a little bit better in Maia with the support for named parameters completion. Maia is now capable of displaying all named parameters ever used in method bodies.

Second Smart Completion for Array Elements

Sunday, April 19th, 2009

Do you use second smart completion feature? Did you know that it also can help you when you have an array and want an element of it? Just press Ctrl+Shift+Space two times when completing:

Easy Exclusion of Classes

Tuesday, April 7th, 2009

You should already know that you can exclude certain classes from auto-import and code completion in IntelliJ IDEA 8.1. In Maia it will be even easier — you will be able to do it directly from the auto-import popup:



And from completion list, too:

Excluding Classes from Auto-Import

Monday, March 30th, 2009

IntelliJ IDEA auto-import popup is a very handy feature that lets you stop worrying about import statements in your Java class files. However, sometimes it can show more choices than you need (e.g. when some of the class names in your project match the names of internal JDK or unrelated library classes).

To make auto-import easier to use and to avoid accidental imports of wrong classes, you can open the Settings dialog, then go to Editor | Auto-Import and add their package prefixes to the exclusion list. This will also hide the specified classes from class name completion lists.

Smart Completion of Java Primitive Method Parameters

Tuesday, March 24th, 2009

Many API include methods like setXxx(int) where int is one of the predefined values, typically declared in the same class. The fact that these are just legacy methods that have been created prior to enums invention, does not stop IntelliJ IDEA from helping you with such parameter values. For example, have a look at JList#getSelectionModel. Just invoke the Smart Completion (Ctrl+Shift+Space) inside the call parentheses:

Smart Completion for Primitives