wiki:RefactoringSteps/MoveRecord

Move record

This transformation moves record definitions between two files. Source and target files can be either modules or header files, the conditions are slightly different in every case. The goal of the transformation is to make the moved record definitions available in every place where they are used.

Move record example:

%%client.hrl

-record(conn, {ip, port=80}).
-record(msg, {sender, text}).
%%messages.hrl

-record(dmsg, {date, text}).
%%client.erl

-include("client.hrl").

sendmessage(Msg) ->
   ?SERVER ! #msg{text=Msg}.

Result:

%%client.hrl

-record(conn, {ip, port=80}).
%%messages.hrl

-record(dmsg, {date, text}).
-record(msg, {sender, text}).
%%client.erl

-include("client.hrl").
-include("messages.hrl").

sendmessage(Msg) ->
   ?SERVER ! #msg{text=Msg}.

Side conditions

  • The names of the records to be moved do not clash with existing record names
    • in the target file,
    • in files that are included in target and
    • in files where the target file is included.
  • If the user does not specify the records to be moved, the transformation starts an interaction to ask the user to specify records. The user has to select the records to be moved from a checkbox list.
  • Moving records from a header file to a module file is only permitted if no other modules include the header file and use some of the records to be moved.
  • If a file inclusion has to be introduced during the transformation, this inclusion must not cause inconsistency at the place of the inclusion.

Transformation steps and compensations

  1. The record definitions are removed from the source file.
  1. If the target is a header file that does not exist, the file is created.
  1. The record definitions are placed at the end of the target header file, or before the first function of the target module file.
  1. If a record is moved into a header file, then every module that uses the record is changed to include the target header file. This is not an issue when the target is a module file.
Last modified 12 years ago Last modified on Feb 17, 2012, 10:28:53 PM