wiki:RefactoringSteps/RenameHeader

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

--

Rename header

The rename header refactoring renames the header file to the given new name, and makes changes in those files in which it is referred to. If the new name of the header file contains a path and this path is not equal to the original one, the transformation moves the header file to its new place and renames it. In the example the header1.hrl is renamed to newname. The file and all of its references are also renamed to newname.

Renaming header file header1.hrl to newname:

%%header1.hrl

-define(MacroFromHeader,
                    ok).

-define(Add(X, Y),
           X + Y).                                 
-module(refmod1).
-include("header1.hrl").

-export([func1/2,func2/2]).

func1(A, B) ->
   ?Add(A, B).

func2() ->
   ?MacroFromHeader.

Result:

%%newname

-define(MacroFromHeader,
                    ok).

-define(Add(X, Y),
           X + Y).                                 
-module(refmod1).
-include("newname").

-export([func1/2,func2/2]).

func1(A, B) ->
   ?Add(A, B).

func2() ->
   ?MacroFromHeader.

Side conditions

  • The type of the file has to be a header file. If the pointed file is a module, the transformation will fail.
  • The directory must not contain a file having the same name as new name given. If it contains, the transformation starts an interaction to ask for a new name.

Transformation steps and compensations

  1. Rename the header file name to the new name on the graph.
  1. Rename the references to the header file in the include forms. (Actually, the include form will be deleted and recreated with a new path and file name).
  1. Rename or move and rename the file to the new name.