wiki:RefactoringSteps/RenameRecord

Rename record

This refactoring renames records in modules or header files. After the transformation, the old name will be replaced by the new name in the record definition and in every reference to the given record (e.g. record field access or field update expressions). The condition of the renaming is that there is no name conflict with another record in the file (which contains the given record), in its includes, or where it is included (the latter is only possible when we are renaming in a header file).

Renaming record "person" to "member":

-record(person, {name, age}).

rename(Arg, New) ->
   #person{name=Name} = Arg,
   io:format("%s", [Name]),
   Arg#person{name=New}.

Result:

-record(member, {name, age}).

rename(Arg, New) ->
   #member{name=Name} = Arg,
   io:format("%s", [Name]),
   Arg#member{name=New}.

Side conditions

  • There must be no record with the new name
    • in the file that contains the record,
    • in files which are included by this file,
    • in files which include this file.
  • If one of the above conditions fails, the transformation starts an interaction to ask for a new record name.
  • If the user does not specify a record, the transformation starts an interaction to ask the user to specify a record.

Transformation steps and compensations

  1. The record name is changed to the new name in the definition of the record and in every record expression that refers the record.
Last modified 13 years ago Last modified on Feb 15, 2012, 2:19:46 PM