Project

General

Profile

TH3-Method Extract » History » Version 1

Wil van Antwerpen, 06/03/2019 01:48 AM

1 1 Wil van Antwerpen
# Method Extract
2 1 Wil van Antwerpen
3 1 Wil van Antwerpen
Method extract helps you to extract a number of lines in your code and extract these into a new method (function or procedure)
4 1 Wil van Antwerpen
5 1 Wil van Antwerpen
## How to use
6 1 Wil van Antwerpen
The way it works is to first select the lines you want to extract from your current method.
7 1 Wil van Antwerpen
8 1 Wil van Antwerpen
Then go to the menu: "Source" -> "Code Refactoring" -> "Method extract"
9 1 Wil van Antwerpen
10 1 Wil van Antwerpen
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.
11 1 Wil van Antwerpen
12 1 Wil van Antwerpen
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.
13 1 Wil van Antwerpen
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.
14 1 Wil van Antwerpen
15 1 Wil van Antwerpen
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.
16 1 Wil van Antwerpen
It then defines it as such.
17 1 Wil van Antwerpen
18 1 Wil van Antwerpen
As this is very complex to get right, you might want to make some changes.
19 1 Wil van Antwerpen
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.
20 1 Wil van Antwerpen
21 1 Wil van Antwerpen
After adjusting the method declaration press "update" and the logic will make the adjustments. Declare variables no longer passed as parameters and such.
22 1 Wil van Antwerpen
23 1 Wil van Antwerpen
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.