Monday Dec 03, 2007
Thursday Nov 29, 2007
Thursday Nov 15, 2007
By sandipchitale on Nov 15, 2007
I have uploaded the Highlight Boxing Unboxing Varargs module to the NetBeans Plugin Portal. It enables highlighting of occurences of boxing, unboxing and varargs in the Java editor. Obviously this only works for files belonging to projects with source level set to 1.5+.
UPDATE: The download link on the Plugin Portal has now been fixed.
The Java compiler silently applies the boxing and unboxing to the primitive types and the corresponding reference types as needed. This module reveals where that may be happening in your code. This module may help you diagnose mysterious NPEs when a reference type null value is attempted to be unboxed at runtime (well the example in the screen shot is not the best ;) ). To turn the highlighting on or off use the toggle buttons on the toolbar. Here is a screen shot:
Jan Lahoda contributed to this module.
Sunday Nov 11, 2007
By sandipchitale on Nov 11, 2007
In any NetBeans 6.0 editor you can shift the text of selected lines or the current line to the left or right using the following key bindings:
Alt+Shift+Left (Ctrl+Shift+Left on Mac) - shift the text of selected lines or the current line to the left by one indent unit
Alt+Shift+Right (Ctrl+Shift+Right on Mac) - shift the text of selected lines or the current line to the right by one indent unit
The number of spaces used for shifting is controlled by the Tools:Options:Editor:Indetation:Number of Spaces per Indent: option.
Sunday Nov 04, 2007
By sandipchitale on Nov 04, 2007
You can configure the property settings. The preview window shows what code will be inserted in Java editor. Select OK to insert the code at current caret position.
You can customize the template by editing it using the Tools:Templates action.
The template uses the freemarker template engine.
- validation of name and type
- validation of duplicate property name
- browse to select type
- nicer positioning of the field, getters and setters
- insertion of required import statements instead of using FQNs
Friday Oct 19, 2007
Friday May 11, 2007
By sandipchitale on May 11, 2007
In the previous entry I talked about the Change Variable Type fix. In this entry I will talk about how it is implemented.
Registration of the factory
Like many other features in NetBeans the hints/fixes/suggestions are implemented using a factory mechanism. The factory is registered in the module's layer file like this:
The factory is registered under the org-netbeans-modules-java-hints/rules/errors folder because it creates a fix for certain compilation errors such as type mismatch of the left and right side of a vatriable declaration statement.
Implementation of the factory
As the user edits the source code, the Java editor incrementally runs the javac in the background. As the javac emits compilation errors the editor shows the red squiggly lines. Aside from that it also invokes the factories registered to handle the particular compilation errors. In this case org.netbeans.modules.javahints.ChangeTypeCreator is one such factory. The ChangeTypeCreator implements the interface org.netbeans.modules.java.hints.spi.ErrorRule. This intreface essentially has two important method:
/\*\* Get the diagnostic codes this rule should run on
public Set<String> getCodes();
/\*\* Return possible fixes for a given diagnostic report.
public List<Fix> run(CompilationInfo compilationInfo,
The getCodes() method essentially indicates the set of compilatioin error codes that are handled by the factory. The ChangeTypeCreator handles:
These codes are part of standard error codes emitted by the javac.
In the run(...) method of ChangeTypeCreator,enough information about the context in the editor is passed in. The ChangeTypeCreator uses the APIs to determine the types of expressions on the left and right side of a variable assignmenets and returns an instance of org.netbeans.modules.javahints.ChangeTypeHint. This instance is used to populate the list of fixes that appear as actions in the light bulb pop up menu in the left margin of the editor.
Implementation of the Change variable type fix
The ChangeTypeHint which implements org.netbeans.spi.editor.hints.Fix . It provides the text of menu item which is returned from:
public String getText()
The actual fix is implemented in the method:
public ChangeInfo implement()
using the Java Source APIs.
Friday May 04, 2007
By sandipchitale on May 04, 2007
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 = ...;
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.
DISCLAIMER: This module is experimental. So no guarantees. Use the module at your own risk.
- Moving on...
- Readonly Editors Mode Module
- Trunk NetBeans cluster dependency graph generated using dot
- DOM Inspector in Firefox Sidebar
- E4X assignment gotcha
- NetBeans 6.1 and trunk compatible Code Template Tools NBMs
- YouTube Viewer add-on project
- Using NetBeans 6.1 freeform project to build iPhone mode add-on for Firefox project.
- Open Location in iPhone Mode in Firefox