| | 1 | = Rename module = |
| | 2 | |
| | 3 | The rename module refactoring renames a module with the given new name. Renames the file and make changes in other file where this module is referenced. In the example the {{{mod1}}} module is renamed to {{{newmod}}}. The file is also renamed to {{{newmod.erl}}}. |
| | 4 | |
| | 5 | Renaming module {{{mod1}}} to {{{newmod}}}: |
| | 6 | |
| | 7 | {{{ |
| | 8 | -module(mod1). |
| | 9 | |
| | 10 | -export([add/2]). |
| | 11 | |
| | 12 | add(A,B) -> A + B. |
| | 13 | }}} |
| | 14 | |
| | 15 | {{{ |
| | 16 | -module(mod2). |
| | 17 | |
| | 18 | -export([add/1]). |
| | 19 | |
| | 20 | add([]) -> []; |
| | 21 | add[{A,B}|Tail]) -> |
| | 22 | [mod1:add(A,B) |
| | 23 | |add(Tail)]. |
| | 24 | }}} |
| | 25 | |
| | 26 | Result: |
| | 27 | |
| | 28 | {{{ |
| | 29 | -module(newmod). |
| | 30 | |
| | 31 | -export([add/2]). |
| | 32 | |
| | 33 | add(A,B) -> A + B. |
| | 34 | }}} |
| | 35 | |
| | 36 | {{{ |
| | 37 | -module(mod2). |
| | 38 | |
| | 39 | -export([add/1]). |
| | 40 | |
| | 41 | add([]) -> []; |
| | 42 | add[{A,B}|Tail]) -> |
| | 43 | [newmod:add(A,B) |
| | 44 | |add(Tail)]. |
| | 45 | }}} |
| | 46 | |
| | 47 | == Side conditions == |
| | 48 | |
| | 49 | * The given new name should be a legal file name. |
| | 50 | |
| | 51 | * There must not exist another module with the given new name in the graph. |
| | 52 | |
| | 53 | * There must not exist another file with the given new name in the directory of the module to be renamed. |
| | 54 | |
| | 55 | * If one of the above conditions fails, the transformation starts an interaction to ask for a new module name. |
| | 56 | |
| | 57 | == Transformation steps and compensations == |
| | 58 | |
| | 59 | 1. Rename the current module name to the new name. |
| | 60 | |
| | 61 | 2. Rename the collected module qualifiers to the given new name. |
| | 62 | |
| | 63 | 3. Rename the references to the module in the import lists. |
| | 64 | |
| | 65 | 4. Rename the file to the new name. |