wiki:RefactoringSteps/RenameModule

Version 1 (modified by manualwiki, 13 years ago) (diff)

--

Rename module

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.

Renaming module mod1 to newmod:

-module(mod1).

-export([add/2]).

add(A,B) -> A + B.
-module(mod2).

-export([add/1]).

add([]) -> []; 
add[{A,B}|Tail]) -> 
   [mod1:add(A,B) 
    |add(Tail)].

Result:

-module(newmod).

-export([add/2]).

add(A,B) -> A + B.                                  
-module(mod2).

-export([add/1]).

add([]) -> []; 
add[{A,B}|Tail]) -> 
   [newmod:add(A,B) 
    |add(Tail)].

Side conditions

  • The given new name should be a legal file name.
  • There must not exist another module with the given new name in the graph.
  • There must not exist another file with the given new name in the directory of the module to be renamed.
  • If one of the above conditions fails, the transformation starts an interaction to ask for a new module name.

Transformation steps and compensations

  1. Rename the current module name to the new name.
  1. Rename the collected module qualifiers to the given new name.
  1. Rename the references to the module in the import lists.
  1. Rename the file to the new name.