wiki:RefactoringSteps/IntroduceImport

Introduce import

This refactoring imports the functions of the selected module that are used in the current file and removes the module qualifiers from the function calls of this module.

Import the sort/1 function from the lists module:

-export([my_sort/1]).

my_sort(A)->
   lists:sort(A).

Result:

-export([my_sort/1]).

-import(lists, [sort/1]).

my_sort(A)->
   sort(A).

Side conditions

  • No local function of the file has the same name and arity as the functions of the module that are used or imported in the file.
  • No imported function in the file has the same name and arity as functions of the module that are used in the file.
  • If there is a problem with the given module name which functions will be imported, the transformation asks for a new module. It gives a list to the user to specify a module. The list contains the modules from where the source module has already imported functions.

Transformation steps and compensations

  1. In case there is no import list of the module in the file a new import list containing the functions of the module that are used in the file is added to the file.
  1. In case there is only one import list of the module in the file the rest of the functions used in the file are added to this list.
  1. In case there is more then one import list of the module, the contents of this list will be merged in one, and the rest of the functions used in the file are added to this list.
  1. The module qualifiers of the module are removed from the corresponding functions.
Last modified 12 years ago Last modified on Feb 19, 2012, 11:03:07 PM