| 1 | = Introduce import = |
| 2 | |
| 3 | This refactoring imports the functions of the selected module that are used in the current file and removes the module qualifiers from the function calls of this module. |
| 4 | |
| 5 | Import the {{{sort/1}}} function from the lists module: |
| 6 | |
| 7 | {{{ |
| 8 | -export([my_sort/1]). |
| 9 | |
| 10 | my_sort(A)-> |
| 11 | lists:sort(A). |
| 12 | }}} |
| 13 | |
| 14 | Result: |
| 15 | |
| 16 | {{{ |
| 17 | -export([my_sort/1]). |
| 18 | |
| 19 | -import(lists, [sort/1]). |
| 20 | |
| 21 | my_sort(A)-> |
| 22 | sort(A). |
| 23 | }}} |
| 24 | |
| 25 | |
| 26 | == Side conditions == |
| 27 | |
| 28 | * No local function of the file has the same name and arity as the functions of the module that are used or imported in the file. |
| 29 | |
| 30 | * No imported function in the file has the same name and arity as functions of the module that are used in the file. |
| 31 | |
| 32 | * If there is a problem with the given module name which functions will be imported, the transformation asks for a new module. It gives a list to the user to specify a module. The list contains the modules from where the source module has already imported functions. |
| 33 | |
| 34 | |
| 35 | == Transformation steps and compensations == |
| 36 | |
| 37 | 1. In case there is no import list of the module in the file a new import list containing the functions of the module that are used in the file is added to the file. |
| 38 | |
| 39 | 2. In case there is only one import list of the module in the file the rest of the functions used in the file are added to this list. |
| 40 | |
| 41 | 3. In case there is more then one import list of the module, the contents of this list will be merged in one, and the rest of the functions used in the file are added to this list. |
| 42 | |
| 43 | 4. The module qualifiers of the module are removed from the corresponding functions. |