Using Editor Hints to Generate Missing Code


When the IDE detects an error for which it has identified a possible fix, a lightbulb () icon appears in the left margin of that line. You can click the lightbulb or press Alt-Enter to display a list of possible fixes. If one of those fixes suits you, you can select it and press Enter to have the fix generated in your code.

Often, the "error" is not a coding mistake but a reflection of the fact that you have not gotten around to filling in the missing code. In those cases, the editor hints simply automate the entry of certain types of code.

For example, assume you have just typed the following code, but x is not defined anywhere in the class.

   int newIntegerTransformer () {        return x;    }


If your cursor is still resting on the line of the return statement, the icon will appear. If you click the icon or press Alt-Enter, you will be offered three possible solutions as shown in Figure 5-6. You can select one of those hints to generate the code.

Figure 5-6. Display of editor hints


In NetBeans IDE 5.0, editor hints only appear when you are in the line where the error is detected. In subsequent releases that is likely to change.


The IDE is able to provide hints for and generate the following solutions to common coding errors:

  • Add a missing import statement

  • Insert abstract methods that are declared in a class' implemented interfaces and abstract superclasses

  • Insert a method parameter

  • Create a missing method

  • Create a missing field

  • Create a missing local variable

  • Initialize a variable

  • Insert a cast

  • Add a throws clause with the appropriate exception

  • Surround the code with a try-catch block including the appropriate exception



NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
NetBeans IDE Field Guide(c) Developing Desktop, Web, Enterprise, and Mobile Applications
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 279

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net