Method Extract¶
Method extract helps you to extract a number of lines in your code and extract these into a new method (function or procedure)
How to use¶
The way it works is to first select the lines you want to extract from your current method.
Then go to the menu: "Source" -> "Code Refactoring" -> "Method extract"
This will then popup a dialog that has the code you just selected, but it is surrounded by procedure MyMethod
and a number of parameters.
When you look at this code then you'll notice that it has comments above it that list all the relevant variables from the lines that you selected.
It shows how these variables are used. If it has "IN" in front of the variable name then the variable is used in the selected line as input for another variable. If it has "OUT" then the variable was used to write some data to.
The Hammer parses the whole method from which you extract these lines and tests the lines before and after the extraction to make an educated guess on what variables should be passed as a variable and what variables are only used locally.
It then defines it as such.
As this is very complex to get right, you might want to make some changes.
Luckily you can. You are free to adjust the method type: procedure
or function
, the method name and any of the parameters. You can also determine if those parameters are passed by reference or not.
After adjusting the method declaration press "update" and the logic will make the adjustments. Declare variables no longer passed as parameters and such.
When you press the "OK" button the extracted code will be inserted as a method just above the method you are extracting the code from. The code will be cut and The Hammer will insert the method invocation at the point of removal.