- 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
Creating a Method from Existing Statements
As your code evolves, you might find it desirable to break some methods up into multiple methods. You can use the Extract Method command to simplify this process. The Extract Method command does the following:
- Creates a new method and moves the selected statements to that method.
- Adds a call to the new method in the location from where the statements were moved.
To extract a method from existing statements:
- In the Source Editor, select the statements that you want to be extracted into the new method.
- Right-click the selection and choose Refactor | Extract Method.
- In the Extract Method dialog box, enter a name for the method and select an access level.
- If you want the method to be static, select the Static checkbox.
-
Click Next.
If you left the Preview All Changes checkbox clear, the method is immediately extracted.
If you have selected the Preview All Changes checkbox, the changes to be made to your code are listed in the Refactoring window. After verifying the changes, click Do Refactoring to complete the method extraction.
If you later find that the refactoring has had some consequences that you would like to reverse, you can choose Refactor | Undo.