Sunday 7 March 2010

JDev 11gPS1 – Java editor "Declaration Insight"

The JDev11gPS1 New Features page lists a large amount of improvements, including something called the "Declaration Insight". The New Features blurb lists this feature as "When declaring local variables from method calls, declaration insight can automatically add the declaration and assignment code as well as completing the method call."

Like us, if you're using JDev11gPS1 you've probably already stumbled upon this feature and not realized it.

You'll be familiar with the traditional Completion Insight. Say in an EntityImpl you're implementing a method and within you want to call the super class method to get the database transaction. However you've forgotten the function name, is it getDBTransaction or getDatabaseTransaction? This is easily solvable by starting to type the function name "getD" then activating Completion Insight, either via pressing Ctrl-Space or the Source menu's same named option. The editor will show the Completion Insight popup in blue with all the functions starting with "getD" in the super class stack, including the method we’re interested in getDBTransaction:

Selecting the same named method, the method is instantly copied into the code:

...saving you some typing and hunting around for the right method.

However the Completion Insight only really gives the right hand side of the assignment expression. It would be good if you could get the IDE to create the left hand side of the assignment expression creating a variable of the correct type to take the result from the function, as well as the function call on the right hand side of the assignment operator as per what the Completion Insight does.

This is where the new "Declaration Insight" comes in. On invoking the Completion Insight with Ctrl-Space showing itself in blue, if you press Ctrl-Space again you'll see the popup changes to puce and displays the very similar Declaration Insight:

Again selecting the same named method, using the Declaration Insight the result is:

....where both the function call and the variable to be assigned the result are inserted into your code, ultimately saving you a bit more typing. If you're like me, and always forgetting what the return type is by the time you're back to the editor, and having to hunt for it again by double invoking the Completion Insight, this will same some extra time.

A minor but useful enhancement in the latest JDev11gPS1 release.

1 comment:

Unknown said...

This feature is cool once got used to it! But the first time it was a bit irritating, because you really have to be careful with Ctrl+Space now.