- 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
Generating Code Snippets without Leaving the Keyboard
The Source Editor has several features for reducing the keystrokes needed for typing code. And you can access many of these features without using the mouse, having to use menus, or remembering scores of keyboard shortcuts.
Arguably the most important mechanisms for generating code are the following:
- Ctrl-spacebar keyboard shortcut. This shortcut opens the code completion box, as shown in Figure 5-1. The code completion box contains a context-sensitive list of ways you can complete the statement you are currently typing and of other code snippets you might want to insert in your code.
Figure 5-1 Code completion box
- Multi-keystroke abbreviations for longer snippets of code called code templates. These abbreviations are expanded into the full code snippet after you press the spacebar.
- Alt-Enter keyboard shortcut. You can use this shortcut to display suggestions the IDE has regarding missing code and then have the IDE insert that code. The IDE notifies you that it has a suggestion by displaying a lightbulb ( ) icon in the left margin of the line you are typing.
In addition to saving keystrokes and use of the mouse, these features might prevent typos and also help you find the right class and method names.
The following several sections illustrate how to get the most out of these features. These topics concentrate on features for Java files, but many of the features (such as code completion and word matching) are also available for other types of files, such as JSP and HTML files.