Refactoring in the DVT Eclipse IDE - How To Perform Extract To Method Refactoring
Overview
This video from shows you how to extract a block of actions to a separate new method. This way you keep methods shorter and easier to understand. Just select a code fragment and press Ctrl+1 - a new method with adequate arguments is created, and the selection is replaced with a method call.
Explore the design and verification tools: https://www.dvteclipse.com
Or request a license: https://www.dvteclipse.com/request-license
Details
Introduction
You can easily move a code fragment to a separate new method. This is called Extract Method Refactoring. It helps keep methods shorter and easier to understand.
How to Perform Extract Method Refactoring
- Select several statements from a task or function and press
CTRL+1
. - Use the up and down arrows to pick a proposal and then press
ENTER
to apply it. - The selected code fragment is replaced with a method call.
- You can give it a meaningful name.
- The newly created method contains the code fragment you initially selected.
Understanding Method Arguments After Refactoring
The newly created method arguments are computed automatically. Any local variables declared prior to the code fragment you extracted become arguments of the newly created method. Each argument direction is computed accordingly:
- Input for arguments that are only read
- Output for arguments that are only written
- In-out for arguments that are both read and written in the selected block of actions.