DVT SystemVerilog IDE User Guide
Rev. 24.1.5, 13 March 2024

8.7 Extract to Method

You can easily move a code fragment to a separate new method. This is called extract method refactoring. It helps keeping methods shorter and easier to understand.

Select a block of actions and press Ctrl+1, select Extract to task or Extract to function from the list of quick assist proposals and press Enter.

A new method is created containing the selected code fragment, and the selection is replaced with a method call.

Note: 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

  • inout for arguments that are both read and written in the selected block of actions

Tip: You may change the extracted method name in the edit box, right after the extract action is completed.

Tip: You can change the method signature by editing the Method_Code_Templates

Tip: You can also right-click in the editor and go to Refactor > Extract to Task or Extract to Function.