- Opening the Source Editor
- Managing Automatic Insertion of Closing Characters
- Displaying Line Numbers
- Generating Code Snippets without Leaving the Keyboard
- Using Code Completion
- Inserting Snippets from Code Templates
- Using Editor Hints to Generate Missing Code
- Matching Other Words in a File
- Generating Methods to Implement and Override
- Generating JavaBeans Component Code
- Creating and Using Macros
- Creating and Customizing File Templates
- Handling Imports
- Displaying Javadoc Documentation While Editing
- Formatting Code
- Text Selection Shortcuts
- Navigating within the Current Java File
- Navigating from the Source Editor
- Searching and Replacing
- Deleting Code Safely
- Changing a Method's Signature
- Encapsulating a Field
- Moving a Class to a Different Package
- Moving Class Members to Other Classes
- Creating a Method from Existing Statements
- Creating an Interface from Existing Methods
- Extracting a Superclass to Consolidate Common Methods
- Changing References to Use a Supertype
- Unnesting Classes
- Tracking Notes to Yourself in Your Code
- Comparing Differences Between Two Files
- Splitting the Source Editor
- Maximizing Space for the Source Editor
- Changing Source Editor Keyboard Shortcuts
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
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