Java Editor Hint: Change variable type fix
In NetBeans 6.0 Java editor supports writing custom, so called, fixes, hints and suggestions. These appear as a light bulb icon in the left margin of the Java editor. For example, in the code below:
100 List list = ...;
101 :
:
110 String s = list.get(0);
the type of the variable s does not match the type of the expression list.get(0). In such cases a light bulb icon appears in the left margin of the Java editor on the line 110 of the code. Clicking or invoking the fix action reveals a menu item saying Cast ...get(...) to String. Selecting the menu item changes the code on line 110 to:
110 String s = (String) list.get(0);
This is all well and good. However what if you wanted to adjust the type of the variable s to Object. It is very easy to write such a fix and that is what I have implemented.
With this fix, I always write my variable like this:
110 int i = .....; // some expression that return a type I don't know - assume it is RefactoringPluginFactory
Select the hint to change the type of i to the correct type.
110 RefactoringPluginFactory i = ....;
(I know, I know some may say why I am doing this...because I am an extremely poor typist :( )
Then I quickly delete i and use the smart variable name proposal code completion to get:
110 RefactoringPluginFactory refactoringPluginFactory = ....;
I have added the fix to the Experimental Java Hints (contrib/editorhints/java) module. You can get the module from Development Update center.
Sources
DISCLAIMER: This module is experimental. So no guarantees. Use the module at your own risk.
Posted by sandipchitale
( May 04 2007, 11:21:36 AM PDT ) Permalink
Trackback URL: http://blogs.sun.com/scblog/entry/java_editor_hint_change_variable
Posted by Sandip on May 04, 2007 at 11:22 AM PDT #
Posted by Insider Scoop From the Tutorial Divas on May 09, 2007 at 08:37 AM PDT #
e
Posted by 61.17.90.56 on September 29, 2007 at 03:02 AM PDT #