wiki:RefactoringSteps/RenameRecordField

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

--

Rename record field

The rename record field transformation supports renaming the specified field of a record. The name of the field is replaced in the definition form and in every referrer expression and token to the given new name. To the field belongs a semantic field object linked to the record, it stores the field name. The data of this object is updated too.

Renaming field name to id:

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

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

Result:

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

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

Side conditions

  • The record must have no field with the same name as the given new field name. If it has, the transformation starts an interaction to ask for a new record field name.
  • If the user does not specify a record field, then the transformation starts an interaction to ask the user to specify one.

Transformation steps and compensations

  1. The field name is changed to the new name in the definition of the record and in every record expression that refers the field.