anchor.diff:  	end,
       lists:usort(refac_syntax_lib:fold(F,[], FunDef)).
   		
  -			
  +do_transformation(FileName, {AnnAST, Info}, {TargetAnnAST, Info1}, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid) ->
  +    Forms = refac_syntax:form_list_elements(AnnAST),
  +    FormsToBeMoved = [F || F <- Forms, defines(F,{ModName, FunName, Arity}) orelse
  +			       type_specifies(F, {FunName, Arity})],
  +    FunToBeMoved = hd([F || F <- FormsToBeMoved, refac_syntax:type(F) == function]),
  +    SpecToBeMove = [F || F <- FormsToBeMoved, refac_syntax:type(F) == attribute],
  +    FunsToBeExported = local_funs_to_be_exported(FunToBeMoved, {ModName, FunName, Arity}, Info),
  +    InScopeFunsInTargetMod = refac_util:inscope_funs(Info1),
  +    FunToBeMoved1 = transform_fun(FileName, FunToBeMoved, {ModName, FunName, Arity}, TargetModName, InScopeFunsInTargetMod, SearchPaths, TabWidth, Pid),
  +    {AnnAST1, FunIsUsed} = do_remove_fun(FileName, AnnAST, {ModName, FunName, Arity}, FunsToBeExported, TargetModName, SearchPaths, TabWidth, Pid),
  +    IsExported = refac_util:is_exported({FunName, Arity}, Info),
  +    Export = FunIsUsed or IsExported,
  +    TargetAnnAST1 = do_add_fun(FileName, {TargetAnnAST, Info1}, SpecToBeMove ++ [FunToBeMoved1],
  +			       {ModName, FunName, Arity}, TargetModName, Export, SearchPaths, TabWidth, Pid),
  +    {AnnAST1, TargetAnnAST1}.
  +
  +type_specifies(F, {FunName, Arity}) ->
  +    case refac_syntax:type(F) of
  +	attribute ->
  +	    Name = refac_syntax:attribute_name(F),
  +	    case refac_syntax:type(Name) of
  +		atom -> case refac_syntax:atom_value(Name) of
  +			    'spec' ->
  +				FA = hd(refac_syntax:attribute_arguments(F)),
  +				case refac_syntax:type(FA) of
  +				    tuple ->
  +					case refac_syntax:tuple_elements(FA) of
  +					    [_M1, F1, A1] -> 
  +						{FunName, Arity}=={refac_syntax:atom_value(F1),
  +								   refac_syntax:integer_value(A1)};						
  +					    [F1, A1] -> 
  +						{FunName, Arity}=={refac_syntax:atom_value(F1),
  +								   refac_syntax:integer_value(A1)};
  +					    _ -> false
  +					end;
  +				    _ -> false
  +				end;
  +			    _ -> false
  +			end;
  +		_ -> false
  +	    end;
  +	_ -> false
  +    end.
  +
  +%%==============================================================================
  +%% Functions defined in the current module, but used by the function to be moved.
  +%%===============================================================================
  +local_funs_to_be_exported(Node, {ModName, FunName, Arity}, ModInfo) ->
  +    Exports=case lists:keysearch(exports, 1, ModInfo) of
  +		{value, {exports, ExportList}} ->
  +		    ExportList;
  +		_ -> []
  +	    end,
  +    CalledFuns = refac_util:called_funs(ModName, Node),
  +    CalledLocalFuns=lists:flatmap(fun({M, F, A})->
  +					  case (M==ModName) andalso {F, A} =/={FunName, Arity} of 
  +					      true -> [{F, A}];
  +					      _ -> []
  +					  end
  +				  end, CalledFuns),
  +    lists:usort(CalledLocalFuns) -- Exports.
  +
  +%%======================================================================================
  +%% Transform the function to be moved.
  +%%======================================================================================
  +transform_fun(FileName, Form, {ModName, FunName, Arity}, TargetModName, InScopeFunsInTargetMod, SearchPaths, TabWidth, Pid) -> 
  +    element(1,refac_util:full_tdTP(fun do_transform_fun/2, Form, 
  +				   {FileName,{ModName, FunName, Arity},
  +				    TargetModName, InScopeFunsInTargetMod, 
  +				    SearchPaths, TabWidth, Pid})).
  +  
  +do_transform_fun(Node, {FileName,{ModName, FunName, Arity},TargetModName, InScopeFunsInTargetMod, SearchPaths, TabWidth, Pid}) ->
  +    case refac_syntax:type(Node) of 
  +	application ->
  +	    Op = refac_syntax:application_operator(Node),
  +	    Args = refac_syntax:application_arguments(Node),
  +	    case lists:keysearch(fun_def, 1, refac_syntax:get_ann(Op)) of
  +		{value, {fun_def, {M, F, A, _, _}}} ->
  +		    case refac_syntax:type(Op) of 
  +			atom ->
  +			    case lists:member({M, F, A}, InScopeFunsInTargetMod) orelse 
  +				{M, F, A} == {ModName, FunName, Arity} of
  +				true ->
  +				    {Node, false};
  +				_ -> 
  +				    {copy_pos_attrs(Node, refac_syntax:application(
  +							    copy_pos_attrs(Op, refac_syntax:module_qualifier(refac_syntax:atom(M), Op)), Args)),
  +				     true}
  +			    end;
  +			_ ->
  +			    {Node,false}
  +		    end;
  +		_ ->{Node, false}
  +	    end;
  +	implicit_fun->
  +	    Name = refac_syntax:implicit_fun_name(Node),
  +	    case refac_syntax:type(Name) of
  +		arity_qualifier -> 
  +		    Body = refac_syntax:arity_qualifier_body(Name),
  +		    A = refac_syntax:arity_qualifier_argument(Name),
  +		    case {refac_syntax:type(Body), refac_syntax:type(A)} of
  +			{atom, integer} ->
  +			    case {refac_syntax:atom_value(Body), refac_syntax:integer_value(A)} of
  +				{FunName, Arity} -> {Node, false};
  +				_ -> {copy_pos_attrs(Node, refac_syntax:implicit_fun(copy_pos_attrs(Name, 
  +					     refac_syntax:module_qualifier(refac_syntax:atom(ModName), Name)))), true}
  +			    end;
  +			_ ->{Node, false}
  +		    end;
  +		module_qualifier ->
  +		    Name = refac_syntax:implicit_fun_name(Node),
  +		    Mod = refac_syntax:module_qualifier_argument(Name),
  +		    Body = refac_syntax:module_qualifier_body(Name),
  +		    case refac_syntax:type(Mod) of 
  +			atom ->
  +			    case refac_syntax:atom_value(Mod) of 
  +				ModName -> 
  +				    B = refac_syntax:arity_qualifier_body(Body),
  +				    A = refac_syntax:arity_qualifier_argument(Body),
  +				    case {refac_syntax:type(B), refac_syntax:type(A)} of
  +					{atom, integer} ->
  +					    case {refac_syntax:atom_value(B), refac_syntax:integer_value(A)} of
  +						{FunName, Arity} -> 
  +						    {copy_pos_attrs(Node, 
  +								    refac_syntax:implicit_fun(copy_pos_attrs(Name, 
  +								     refac_syntax:module_qualifier(copy_pos_attrs(Mod, 
  +								      refac_syntax:atom(TargetModName)), Body)))), true};
  +						_ -> {Node, false}
  +					    end;
  +					_ ->{Node, false}
  +				    end;
  +				_ -> {Node, false}
  +			    end;
  +			_ -> {Node, false}
  +		    end;
  +		_ -> {Node, false}
  +	    end;
  +	tuple -> do_rename_fun_in_tuples(Node, {FileName, SearchPaths, ModName, FunName, TargetModName, Arity, Pid, TabWidth});
  +	_ -> {Node, false}
  +    end.
  +				
  +
  +%%=========================================================================
  +%% Remove the function from the current module. 
  +%%=========================================================================
  +do_remove_fun(FileName, AnnAST, {ModName, FunName, Arity}, FunsToBeExported, TargetModName, SearchPaths, TabWidth, Pid) ->
  +    Forms  = refac_syntax:form_list_elements(AnnAST),
  +    {Forms1, C}= lists:unzip(lists:map(fun(Form) ->
  +					       process_a_form_in_original_mod(FileName, Form, {ModName, FunName, Arity}, 
  +									      TargetModName, SearchPaths, TabWidth, Pid)
  +				       end, Forms)),
  +    Forms2 = lists:append(Forms1),
  +    Fun_is_Used = lists:member(true, C),
  +    NewForms = case FunsToBeExported of 
  +		   [] -> Forms2;
  +		   [_H|_T] ->  Export = make_export(FunsToBeExported),
  +			       {Forms11, Forms12} = lists:splitwith(fun(F) -> refac_syntax:type(F)==attribute 
  +										  orelse refac_syntax:type(F) == comment end, Forms2),
  +			       Forms11++Export++Forms12
  +	       end,
  +    {copy_pos_attrs(AnnAST, refac_syntax:form_list(NewForms)), Fun_is_Used}.
  +
  +%%=======================================================================
  +%% Add the function to the target module.
  +%%=======================================================================
  +do_add_fun(FileName,{TargetAnnAST, Info}, FunToBeMoved, {ModName, FunName, Arity}, TargetModName, ToBeExported, SearchPaths, TabWidth, Pid) ->
  +    Forms = refac_syntax:form_list_elements(TargetAnnAST),
  +    FunWithSameName = [F || F <- Forms, defines(F, {TargetModName, FunName, Arity})],
  +    NewFun = case FunWithSameName of
  +		 [] -> FunToBeMoved;
  +		 _ -> []
  +	     end,
  +    Forms1 = lists:append([process_a_form_in_target_module(FileName, Form, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid) 
  +			   || Form <- Forms]),
  +    IsExported = refac_util:is_exported({FunName, Arity}, Info),
  +    NewForms = case ToBeExported andalso (not IsExported) of
  +		   false -> Forms1 ++ NewFun;
  +		   true -> Export = make_export([{FunName, Arity}]),
  +			   {Forms11, Forms12} = lists:splitwith(fun (F) -> refac_syntax:type(F) == attribute
  +									       orelse refac_syntax:type(F) == comment
  +								end, Forms1),
  +			   Forms11 ++ Export ++ Forms12 ++ NewFun
  +	       end,
  +    copy_pos_attrs(TargetAnnAST, refac_syntax:form_list(NewForms)).
  +
  +%%=========================================================================
  +%% Refacotoring in the current module. 
  +%%========================================================================
  +process_a_form_in_original_mod(FileName,Form, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid) ->
  +    case refac_syntax:type(Form) of 
  +	function -> 
  +	    As = refac_syntax:get_ann(Form),
  +	    case lists:keysearch(fun_def,1, As) of 
  +		{value, {fun_def, {ModName, FunName, Arity, _, _}}} ->
  +		    {[], false};
  +		_ ->
  +		    {Form1, C}=add_change_module_qualifier(FileName, Form, {ModName, FunName, Arity}, 
  +							   TargetModName, SearchPaths, TabWidth, Pid),
  +		    {[Form1],C}
  +	    end;		    
  +	attribute -> Name = refac_syntax:attribute_name(Form),
  +		     case refac_syntax:type(Name) of 
  +			 atom ->case refac_syntax:atom_value(Name) of
  +				    export -> [L] = refac_syntax:attribute_arguments(Form),
  +					      Es = refac_syntax:list_elements(L),
  +					      Es1 =[E  || E<-Es, 
  +							  {refac_syntax:atom_value(refac_syntax:arity_qualifier_body(E)),
  +							   refac_syntax:integer_value(refac_syntax:arity_qualifier_argument(E))}
  +							      =/={FunName, Arity}],
  +					      case length(Es1) == 0 of
  +						  true -> 
  +						      {[],false} ;
  +						  false -> 
  +						      case length(Es1) == length(Es) of 
  +							  true -> {[Form], false};
  +							  _ -> {[copy_pos_attrs(Form,refac_syntax:attribute(Name,[refac_syntax:list(Es1)]))], true}
  +						      end
  +					      end;
  +				    spec -> FA = hd(refac_syntax:attribute_arguments(Form)),
  +					    case refac_syntax:type(FA) of
  +						tuple ->
  +						    case refac_syntax:tuple_elements(FA) of 
  +							[_M1, F1, A1] ->case {refac_syntax:atom_value(F1), refac_syntax:integer_value(A1)} of
  +									    {FunName, Arity} -> {[],true};
  +									    _ -> {[Form], false}
  +									    end;
  +							[F1, A1] ->case {refac_syntax:atom_value(F1), refac_syntax:integer_value(A1)} of
  +								       {FunName, Arity} -> {[],true};
  +								       _ -> {[Form],false}
  +								   end;
  +							_ -> {[Form],false}
  +						    end;
  +						_ ->{[Form], false}
  +					    end;
  +				    _  -> {[Form], false}
  +				end;
  +			 _  -> {[Form], false}
  +		     end;
  +	_-> {[Form], false}
  +    end.
  +
  +%%============================================================================
  +%% Refactoring in the target module.
  +%%============================================================================
  +process_a_form_in_target_module(FileName, Form, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid) ->
  +    case refac_syntax:type(Form) of
  +	function -> [remove_module_qualifier(FileName, Form, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid)];
  +	attribute -> Name = refac_syntax:attribute_name(Form),
  +		     case refac_syntax:type(Name) of
  +			 atom -> case refac_syntax:atom_value(Name) of
  +				     import ->
  +					 [H, L] = refac_syntax:attribute_arguments(Form),
  +					 case refac_syntax:atom_value(H) of 
  +					     ModName ->
  +						 Es = refac_syntax:list_elements(L),
  +						 Es1 = [E || E <- Es,
  +							     {refac_syntax:atom_value(refac_syntax:arity_qualifier_body(E)),
  +							      refac_syntax:integer_value(refac_syntax:arity_qualifier_argument(E))}
  +								 =/= {FunName, Arity}],
  +						 case length(Es1) == 0 of
  +						     true -> [];
  +						     _ -> [copy_pos_attrs(Form,refac_syntax:attribute(Name, [H, refac_syntax:list(Es1)]))]
  +						 end;
  +					     _ -> [Form]
  +					 end;
  +				     _ -> [Form]
  +				 end;
  +			 _ -> [Form]
  +		     end;
  +	_ -> [Form]
  +    end.
  +
  +%%============================================================================
  +%% Add/remove module qualifier.
  +%%============================================================================
  +remove_module_qualifier(FileName,Form, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth,Pid) ->    
  +    element(1,refac_util:full_tdTP(fun do_remove_module_qualifier/2, Form, 
  +				   {FileName, {ModName, FunName, Arity}, 
  +				    TargetModName, SearchPaths, TabWidth, Pid})).
  +  
  +
  +do_remove_module_qualifier(Node, {FileName, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid}) ->
  +    case refac_syntax:type(Node) of
  +      application ->
  +	  Op = refac_syntax:application_operator(Node),
  +	  Args = refac_syntax:application_arguments(Node),
  +	  case application_info(Node) of
  +	    {{none, FunName}, Arity} -> {Node, true};
  +	    {{ModName, FunName}, Arity} -> Op1 = copy_pos_attrs(Op, refac_syntax:atom(FunName)),
  +					   Node1 = copy_pos_attrs(Node, refac_syntax:application(Op1, Args)),
  +					   {Node1, true};
  +	    {{Mod1, Fun1}, Ari1} ->
  +		case lists:keysearch({Mod1, Fun1, Ari1}, 1, refac_rename_fun:apply_style_funs()) of
  +		  {value, _} ->
  +		      transform_apply_style_calls(FileName, Node, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth);
  +		  false -> {Node, false}
  +		end;
  +	    _ -> {Node, false}
  +	  end;
  +      implicit_fun -> process_implicit_fun(Node, ModName, FunName, Arity, TargetModName);
  +      tuple -> do_rename_fun_in_tuples(Node, {FileName, SearchPaths, ModName, FunName, TargetModName, Arity, Pid, TabWidth});
  +      _ -> {Node, false}
  +    end.
  +
  +process_implicit_fun(Node, ModName, FunName, Arity, TargetModName) ->
  +    Name = refac_syntax:implicit_fun_name(Node),
  +    case refac_syntax:type(Name) of
  +      arity_qualifier ->
  +	  {Node, false};
  +      module_qualifier ->
  +	  Mod = refac_syntax:module_qualifier_argument(Name),
  +	  Body = refac_syntax:module_qualifier_body(Name),
  +	  case refac_syntax:type(Mod) of
  +	    atom ->
  +		case refac_syntax:atom_value(Mod) of
  +		  ModName ->
  +		      B = refac_syntax:arity_qualifier_body(Body),
  +		      A = refac_syntax:arity_qualifier_argument(Body),
  +		      case {refac_syntax:type(B), refac_syntax:type(A)} of
  +			{atom, integer} ->
  +			    case
  +			      {refac_syntax:atom_value(B), refac_syntax:integer_value(A)}
  +				of
  +			      {FunName, Arity} ->
  +				  {copy_pos_attrs(Node,
  +					 refac_syntax:implicit_fun(copy_pos_attrs(Name,
  +					  refac_syntax:module_qualifier(copy_pos_attrs(Mod,
  +					  refac_syntax:atom(TargetModName)), Body)))), true};
  +			      _ -> {Node, false}
  +			    end;
  +			_ -> {Node, false}
  +		      end;
  +		  _ -> {Node, false}
  +		end
  +	  end
  +    end.
  +	    
  +add_change_module_qualifier(FileName, Form, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid) ->
  +    refac_util:full_tdTP(fun do_add_change_module_qualifier/2,
  +			 Form, {FileName, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid}).
  +
  +do_add_change_module_qualifier(Node, {FileName, {ModName, FunName, Arity}, TargetModName,SearchPaths, TabWidth, Pid}) ->
  +    MakeApp = fun (Node1, Operator1, Arguments1,TargetModName1, FunName1) ->
  + 		      Operator2 =copy_pos_attrs(Operator1,refac_syntax:module_qualifier(refac_syntax:atom(TargetModName1),
  + 											refac_syntax:atom(FunName1))),
  + 		      Node2= copy_pos_attrs(Node1, refac_syntax:application(Operator2,Arguments1)),
  + 		      {Node2, true}
  + 	      end,
  +    case refac_syntax:type(Node) of 
  +	application ->
  +	    Operator = refac_syntax:application_operator(Node),
  +	    Args = refac_syntax:application_arguments(Node),
  +	    case lists:keysearch(fun_def, 1, refac_syntax:get_ann(Operator)) of 
  +		{value, {fun_def, {Mod1, Fun1, Ari1, _, _}}} ->
  +		    case lists:keysearch({Mod1, Fun1, Ari1}, 1, refac_rename_fun:apply_style_funs()) of
  +			{value, _} ->
  +			    transform_apply_style_calls(FileName, Node, {ModName, FunName, Arity}, TargetModName, SearchPaths, 8);  %% To Change
  +			false ->
  +			    case {Mod1, Fun1, Ari1} of
  +				{ModName, FunName, Arity} ->
  +				    MakeApp(Node, Operator, Args, TargetModName, FunName);
  +				_ ->{Node, false}
  +			    end
  +		    end;
  +		_ ->{Node, false}
  +	    end;
  +	implicit_fun ->
  +	    Name = refac_syntax:implicit_fun_name(Node),
  +	    case refac_syntax:type(Name) of 
  +		arity_qualifier ->
  +		    Body = refac_syntax:arity_qualifier_body(Name),
  +		    A = refac_syntax:integer_value(refac_syntax:arity_qualifier_argument(Name)),
  +		    case refac_syntax:type(Body) of 
  +			atom -> B = refac_syntax:atom_value(Body),
  +				case {B, A} of
  +				    {FunName, Arity} ->
  +				   	FunName1 = copy_pos_attrs(Name, refac_syntax:module_qualifier(copy_pos_attrs(Name, 
  +									 refac_syntax:atom(TargetModName)),Name)),
  +					{copy_pos_attrs(Node, refac_syntax:implicit_fun(FunName1)),true};
  +				    _ -> {Node, false}
  +				end;
  +			_ -> {Node, false}
  +		    end;
  +		module_qualifier ->
  +		    Mod = refac_syntax:module_qualifier_argument(Name),
  +		    Body = refac_syntax:module_qualifier_body(Name),
  +		    case refac_syntax:type(Mod) of 
  +			atom ->
  +			    case refac_syntax:atom_value(Mod) of 
  +				ModName -> 
  +				    B = refac_syntax:arity_qualifier_body(Body),
  +				    A = refac_syntax:arity_qualifier_argument(Body),
  +				    case {refac_syntax:type(B), refac_syntax:type(A)} of
  +					{atom, integer} ->
  +					    case {refac_syntax:atom_value(B), refac_syntax:integer_value(A)} of
  +						{FunName, Arity} -> 
  +						    {copy_pos_attrs(Node, 
  +								    refac_syntax:implicit_fun(copy_pos_attrs(Name, 
  +								     refac_syntax:module_qualifier(copy_pos_attrs(Mod, 
  +								      refac_syntax:atom(TargetModName)), Body)))), true};
  +						_ -> {Node, false}
  +					    end;
  +					_ ->{Node, false}
  +				    end;
  +				_ -> {Node, false}
  +			    end
  +		    end		
  +	    end;
  +	tuple -> do_rename_fun_in_tuples(Node, {FileName, SearchPaths, ModName, FunName, TargetModName, Arity, Pid, TabWidth});
  +	_ ->{Node, false}	    
  +    end. 		    
  +  
  +
  +%% ====================================================================================
  +%%  Processing Client modules.
  +%%====================================================================================
  +
  +refactor_in_client_modules(ClientFiles,{ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid) ->
  +    case ClientFiles of 
  +	[] -> [];
  +	[F | Fs] ->
  +	    ?wrangler_io("The current file under refactoring is:\n~p\n", [F]),
  +	    {ok, {AnnAST, Info}} =refac_util:parse_annotate_file(F,true, SearchPaths, TabWidth),     
  +	    {AnnAST1, Changed} = refactor_in_client_module_1(F, {AnnAST, Info}, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid),
  +	    check_atoms(F, AnnAST1, [FunName], Pid),
  +	    if Changed ->
  +		    [{{F,F}, AnnAST1} | refactor_in_client_modules(Fs, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid)];
  +	       true -> refactor_in_client_modules(Fs, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid)
  +	    end
  +    end.
  +refactor_in_client_module_1(FileName,{AnnAST, _Info}, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth,Pid) ->
  +    Forms  = refac_syntax:form_list_elements(AnnAST),
  +    {Forms1, C} = lists:unzip([process_in_client_module(FileName, Form, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid)||Form <-Forms]),
  +    Forms2 = lists:append(Forms1),
  +    {copy_pos_attrs(AnnAST, refac_syntax:form_list(Forms2)), lists:member(true, C)}.
  +
  +process_in_client_module(FileName, Form, {ModName, FunName, Arity}, TargetModName,SearchPaths, TabWidth, Pid) ->
  +     NewImport = refac_syntax:attribute(refac_syntax:atom('import'),
  +					[refac_syntax:atom(TargetModName),
  +					 refac_syntax:list([refac_syntax:arity_qualifier(refac_syntax:atom(FunName),
  +								       refac_syntax:integer(Arity))])]),
  +    case refac_syntax:type(Form) of
  +	function -> {Form1, C} =change_module_qualifier(FileName, Form, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid),
  +		    {[Form1], C};
  +	attribute -> Name = refac_syntax:attribute_name(Form),
  +		     case refac_syntax:type(Name) of
  +			 atom -> case refac_syntax:atom_value(Name) of
  +				     import ->
  +					 [H, L] = refac_syntax:attribute_arguments(Form),
  +					 case refac_syntax:atom_value(H) of 
  +					     ModName ->
  +						 Es = refac_syntax:list_elements(L),
  +						 Es1 = [E || E <- Es,
  +							     {refac_syntax:atom_value(refac_syntax:arity_qualifier_body(E)),
  +							      refac_syntax:integer_value(refac_syntax:arity_qualifier_argument(E))}
  +								 =/= {FunName, Arity}],
  +						 case length(Es1) of 
  +						     0 ->
  +							 {[NewImport], true};
  +						     _ -> case length(Es) == length(Es1) of 
  +							      true -> {[Form], false};
  +							      _ ->
  +								  {[copy_pos_attrs(Form, refac_syntax:attribute(Name, [H, refac_syntax:list(Es1)])),
  +								    NewImport],true}
  +							  end
  +						 end;
  +					     _ -> {[Form], false}
  +					 end;
  +				     _ -> {[Form], false}
  +				 end;
  +			 _ -> {[Form], false}
  +		     end;
  +	_ -> {[Form], false}
  +    end.
  +
  +
  +change_module_qualifier(FileName, Form, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid) ->
  +    refac_util:full_tdTP(fun do_change_module_qualifier/2,
  +			 Form, {FileName, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid}).
  +
  +do_change_module_qualifier(Node, {FileName, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth, Pid}) ->
  +    MakeApp = fun (Node1, Operator1, Arguments1, TargetModName1, FunName1) ->
  +		      Operator2 = copy_pos_attrs(Operator1, refac_syntax:module_qualifier(refac_syntax:atom(TargetModName1),
  +											  refac_syntax:atom(FunName1))),
  +		      Node2 = copy_pos_attrs(Node1, refac_syntax:application(Operator2, Arguments1)),
  +		      {Node2, true}
  +	      end,
  +    case refac_syntax:type(Node) of
  +      application ->
  +	  Operator = refac_syntax:application_operator(Node),
  +	  Args = refac_syntax:application_arguments(Node),
  +	  case lists:keysearch(fun_def, 1, refac_syntax:get_ann(Operator)) of
  +	    {value, {fun_def, {Mod1, Fun1, Ari1, _, _}}} ->
  +		case lists:keysearch({Mod1, Fun1, Ari1}, 1, refac_rename_fun:apply_style_funs()) of
  +		  {value, _} ->
  +		      transform_apply_style_calls(FileName, Node, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth);
  +		  false ->
  +		      case {Mod1, Fun1, Ari1} of
  +			{ModName, FunName, Arity} ->
  +			    case refac_syntax:type(Operator) of
  +			      module_qualifier ->
  +				  MakeApp(Node, Operator, Args, TargetModName, FunName);
  +			      _ -> {Node, false}
  +			    end;
  +			_ -> {Node, false}
  +		      end
  +		end;
  +	    _ -> {Node, false}
  +	  end;
  +      implicit_fun -> process_implicit_fun(Node, ModName, FunName, Arity, TargetModName);
  +      tuple -> do_rename_fun_in_tuples(Node, {FileName, SearchPaths, ModName, FunName, TargetModName, Arity, Pid, TabWidth});
  +      _ -> {Node, false}
  +    end.
  +  
  +%%================================================================================
  +%%              Some Utility Functions 
  +%%================================================================================
  +
  +make_export(Names) ->
  +    Es = [refac_syntax:arity_qualifier(refac_syntax:atom(F),refac_syntax:integer(A))
  +	  || {F, A} <- Names],
  +    [refac_syntax:attribute(refac_syntax:atom('export'), [refac_syntax:list(Es)])].
  +
  +copy_pos_attrs(E1, E2) ->
  +    refac_syntax:copy_pos(E1, refac_syntax:copy_attrs(E1, E2)).    
  +    
  +%% =====================================================================
  +%% @spec application_info(Tree::syntaxTree())->term()
  +%% ====================================================================       
  +application_info(Node) ->
  +    case refac_syntax:type(Node) of 
  +	application ->
  +	    Operator = refac_syntax:application_operator(Node),
  +	    Arguments = refac_syntax:application_arguments(Node),
  +	    Arity = length(Arguments),
  +	    case refac_syntax:type(Operator) of 
  +		atom -> Op = refac_syntax:atom_value(Operator),
  +			{{none,Op}, Arity}; 
  +		module_qualifier ->
  +		        Mod = refac_syntax:module_qualifier_argument(Operator),
  +		        Fun = refac_syntax:module_qualifier_body(Operator),
  +		        T1 = refac_syntax:type(Mod), 
  +		        T2 = refac_syntax:type(Fun),
  +		        case T1 of 
  +		  	    atom -> 
  +				Mod1 = refac_syntax:atom_value(Mod),
  +				case T2 of 
  +					atom -> Fun1 = refac_syntax:atom_value(Fun),
  +						{{Mod1, Fun1}, Arity};
  +				        _ ->{{Mod1, expressionfunname}, Arity}
  +					end;
  +			    _ -> case T2 of 
  +				     atom -> Fun1 = refac_syntax:atom_value(Fun),
  +					     {{expressionmodname, Fun1}, Arity};
  +				     _ -> {{expressionmodname,expressionfunname}, Arity}
  +				 end
  +			    end;
  +		_  -> {{none,expressionoperator}, Arity}
  +	    end;
  +	_ -> erlang:error(bagarg)
  +    end.
  +
  +transform_apply_style_calls(FileName, Node, {ModName, FunName, Arity}, NewModName, SearchPaths, TabWidth) ->
  +    Operator = refac_syntax:application_operator(Node),
  +    Arguments = refac_syntax:application_arguments(Node),
  +    [N1, N2, Mod, Fun, Args] = case length(Arguments) of 
  +				   5 -> Arguments;
  +				   4 -> [none | Arguments];
  +				   3 -> [none , none| Arguments]
  +			       end,					
  +    Mod1 = refac_rename_fun:try_eval(FileName, Mod, SearchPaths, TabWidth),
  +    Fun1 = refac_rename_fun:try_eval(FileName, Fun, SearchPaths, TabWidth),
  +    case Fun1 of
  +	{value, FunName} ->
  +	    case Mod1 of
  +		{value, ModName} ->
  +		    case ((refac_syntax:type(Args)==list) andalso (refac_syntax:list_length(Args)==Arity)) orelse
  +			((refac_syntax:type(Args)==nil) andalso Arity==0) of 
  +			true ->
  +			    Mod2 = copy_pos_attrs(Mod, refac_syntax:atom(NewModName)),
  +			    App = case length(Arguments) of
  +				      5 -> refac_syntax:application(Operator, [N1,N2, Mod2, Fun, Args]);
  +				      4 -> refac_syntax:application(Operator, [N2, Mod2, Fun, Args]);
  +				      3 -> refac_syntax:application(Operator, [Mod2, Fun, Args])
  +				  end,
  +			    {copy_pos_attrs(Node, App), true};
  +			false -> {Node, false}
  +		    end;
  +		_ ->
  +		    {Node, false}
  +	    end;
  +	_ -> {Node, false}	
  +    end.
  +
  +
   reset_attrs(Node, {M, F, A}) ->
       Fun = fun(T) -> 
   		  T1 = case refac_syntax:type(T) of 
  
positive.code: 		  case lists:keysearch(fun_def,1,refac_syntax:get_ann(T1)) of
  		      {value, {fun_def, {ModName, FunName, Arity, _, _}}} ->
  			  case {ModName, FunName, Arity} of 
  			      {M, F, A} -> set_default_ann(T1);
  			      _ -> refac_syntax:set_pos(
  				     refac_syntax:remove_comments(
  				       refac_syntax:set_ann(T1, 
  							    [{fun_def, {ModName, FunName, Arity, {0,0},{0,0}}}])),{0,0})
  			  end;	      
  		      _ -> set_default_ann(T1)
  		  end
  	  end,
      refac_syntax_lib:map(Fun, Node).
  				       
  set_default_ann(Node) ->
      refac_syntax:set_pos(refac_syntax:remove_comments(refac_syntax:set_ann(Node, [])), {0,0}).
  
  
  has_implicit_fun_call(Tree) ->    
      F=fun(T,S) ->
  	      case refac_syntax:type(T) of 
  		  arity_qualifier-> S++[true];
  		  _  -> S
  	      end
        end,
      R = refac_syntax_lib:fold(F, [], Tree),
      lists:member(true, R).
  
  do_transformation({AnnAST, Info}, {TargetAnnAST, Info1}, {ModName, FunName, Arity}, TargetModName) ->
      Forms = refac_syntax:form_list_elements(AnnAST),
      FunToBeMoved = hd([F || F <- Forms, not is_not_the_fun(F, {ModName, FunName, Arity})]),
      FunsToBeExported = local_funs_to_be_exported(FunToBeMoved, {ModName, FunName, Arity}, Info),
      InScopeFunsInTargetMod = refac_util:inscope_funs(Info1),
      FunToBeMoved1 = transform_fun(FunToBeMoved, {ModName, FunName, Arity}, TargetModName, InScopeFunsInTargetMod),
      {AnnAST1, FunIsUsed} = do_remove_fun(AnnAST, {ModName, FunName, Arity}, FunsToBeExported, TargetModName),
      IsExported = refac_util:is_exported({FunName, Arity}, Info),
      Export = FunIsUsed or IsExported,
      TargetAnnAST1 = do_add_fun({TargetAnnAST, Info1}, FunToBeMoved1, {ModName, FunName, Arity}, TargetModName, Export),
      {AnnAST1, TargetAnnAST1}.
  
  %%==============================================================================
  %% Functions defined in the current module, but used by the function to be moved.
  %%===============================================================================
  local_funs_to_be_exported(Node, {ModName, FunName, Arity}, Info) ->
      Funs = fun (T, S) ->
  		   case refac_syntax:type(T) of
  		     application ->
  			 Operator = refac_syntax:application_operator(T),
  			 case application_info(T) of
  			   {{none, F}, A} ->
  			       case get_fun_def_info(Operator) of
  				 {ModName, F, A, _P} when {F, A} =/= {FunName, Arity} ->
  				     ordsets:add_element({F, A}, S);
  				 _ -> S
  			       end;
  			   _ -> S
  			 end;
  		     _ -> S
  		   end
  	   end,
      Fs = refac_syntax_lib:fold(Funs, ordsets:new(), Node),
      [F || F <- Fs, not refac_util:is_exported(F, Info)].
  
  
  %%======================================================================================
  %% Transform the function to be moved.
  %%======================================================================================
  transform_fun(Form, {ModName, FunName, Arity}, TargetModName, InScopeFunsInTargetMod) -> 
        {Form1, _} =refac_util:stop_tdTP(fun do_transform_fun/2, Form, {{ModName, FunName, Arity},
  							  TargetModName, InScopeFunsInTargetMod}),
        Form1.
  
  do_transform_fun(Node, {{ModName, FunName, Arity}, TargetModName, InScopeFunsInTargetMod}) ->
      MakeApp = fun (Node1, Operator1, Arguments1,ModName1, FunName1) ->
   		     Operator2 =refac_syntax:copy_attrs(Operator1,
   					     refac_syntax:module_qualifier(refac_syntax:atom(ModName1),
   									   refac_syntax:atom(FunName1))),
   		     Node2= refac_syntax:copy_attrs(Node1,
   						     refac_syntax:application(Operator2,Arguments1)),
   		     {Node2, false}
   	     end,
      case refac_syntax:type(Node) of 
   	  application ->
  	    Operator = refac_syntax:application_operator(Node),
  	    Arguments = refac_syntax:application_arguments(Node),
  	    case application_info(Node) of 
  		  {{none, F}, A} ->
    		      case {F, A} == {FunName, Arity} of 
    			  true -> {Node, false};
    			  false ->  case refac_syntax:type(Operator) of 
  				       atom ->{M, F, A, _P} = get_fun_def_info(Operator),
  					       case lists:member({M, F, A}, InScopeFunsInTargetMod) of 
  						  true -> {Node, false};
  						  _  ->MakeApp(Node, Operator, Arguments, M, F)
  					      end;
  				       _ -> {Node, false}
  				   end				   
    		      end;
   	 	  {{ModName, FunName}, Arity} ->MakeApp(Node,Operator, Arguments, TargetModName, FunName);
  		  _ -> {Node, false}
   	      end;
          _  -> {Node, false}
      end.
  
  
  %%=========================================================================
  %% Remove the function from the current module. 
  %%=========================================================================
  do_remove_fun(AnnAST, {ModName, FunName, Arity}, FunsToBeExported, TargetModName) ->
      Forms  = refac_syntax:form_list_elements(AnnAST),
      Res = [process(Form, {ModName, FunName, Arity}, TargetModName)||Form <-Forms, 
  								       is_not_the_fun(Form, {ModName, FunName, Arity})],
      Forms1 = lists:map(fun({F, _M}) -> F end, Res),
      Fun_is_Used = lists:member(true, lists:map(fun({_F, M}) -> M end, Res)),
      NewForms = case FunsToBeExported of 
  		   [] -> Forms1;
  		   [_H|_T] ->  Export = make_export(FunsToBeExported),
  			       {Forms11, Forms12} = lists:splitwith(fun(F) -> refac_syntax:type(F)==attribute 
  								  orelse refac_syntax:type(F) == comment end, Forms1),
  			       Forms11++Export++Forms12
  	       end,
      {refac_syntax:copy_attrs(AnnAST, refac_syntax:form_list(NewForms)), Fun_is_Used}.
  
  %%=======================================================================
  %% Add the function to the target module.
  %%=======================================================================
  do_add_fun({TargetAnnAST, Info}, FunToBeMoved, {ModName, FunName, Arity}, TargetModName, ToBeExported) ->
      Forms = refac_syntax:form_list_elements(TargetAnnAST),
      FunWithSameName = [F || F <- Forms, not is_not_the_fun(F, {list_to_atom(TargetModName), FunName, Arity})],
      NewFun = case FunWithSameName of
  	       [] -> [FunToBeMoved];
  	       _ -> []
  	     end,
      Forms1 = [process_forms_in_target_module(Form, {ModName, FunName, Arity}, TargetModName) || Form <- Forms],
      IsExported = refac_util:is_exported({FunName, Arity}, Info),
      NewForms = case ToBeExported andalso not IsExported of
  		 false -> Forms1 ++ NewFun;
  		 true -> Export = make_export([{FunName, Arity}]),
  			 {Forms11, Forms12} = lists:splitwith(fun (F) -> refac_syntax:type(F) == attribute
  									   orelse refac_syntax:type(F) == comment
  							      end, Forms1),
  			 Forms11 ++ Export ++ Forms12 ++ NewFun
  	       end,
      refac_syntax:copy_attrs(TargetAnnAST, refac_syntax:form_list(NewForms)).
  
  %%=========================================================================
  %% Refacotoring in the current module. 
  %%========================================================================
  process(Form, {ModName, FunName, Arity}, TargetModName) ->
      case refac_syntax:type(Form) of 
  	function -> add_change_module_qualifier(Form, {ModName, FunName, Arity}, TargetModName);
  	attribute -> Name = refac_syntax:attribute_name(Form),
  		     case refac_syntax:type(Name) of 
  			 atom ->case refac_syntax:atom_value(Name) of
  				    export -> [L] = refac_syntax:attribute_arguments(Form),
  					      Es = refac_syntax:list_elements(L),
  					      Es1 =[E  || E<-Es, 
  						  {refac_syntax:atom_value(refac_syntax:arity_qualifier_body(E)),
  						   refac_syntax:integer_value(refac_syntax:arity_qualifier_argument(E))}
  						   =/={FunName, Arity}],
  					      case length(Es1) == 0  of
  						  true -> {comment([""]), false};
  						  _ ->
  						      {refac_syntax:copy_attrs(Form, 
  							  refac_syntax:attribute(Name,[refac_syntax:list(Es1)])), false}
  						  end;
  				    _  -> {Form, false}
  				end;
  			 _  -> {Form,false}
  		     end;
  	_-> {Form,false}
      end.
  
  %%============================================================================
  %% Refactoring in the target module.
  %%============================================================================
  process_forms_in_target_module(Form, {ModName, FunName, Arity}, TargetModName) ->
      case refac_syntax:type(Form) of
        function -> remove_module_qualifier(Form, {ModName, FunName, Arity}, TargetModName);
        attribute -> Name = refac_syntax:attribute_name(Form),
  		   case refac_syntax:type(Name) of
  		     atom -> case refac_syntax:atom_value(Name) of
  			       import ->
  				   [H, L] = refac_syntax:attribute_arguments(Form),
  				   Es = refac_syntax:list_elements(L),
  				   Es1 = [E || E <- Es,
  					       {refac_syntax:atom_value(refac_syntax:arity_qualifier_body(E)),
  						refac_syntax:integer_value(refac_syntax:arity_qualifier_argument(E))}
  						 =/= {FunName, Arity}],
  				   case length(Es1) == 0 of
  				     true -> comment([""]);
  				     _ -> refac_syntax:copy_attrs(Form,
  								  refac_syntax:attribute(Name, [H, refac_syntax:list(Es1)]))
  				   end;
  			       _ -> Form
  			     end;
  		     _ -> Form
  		   end;
        _ -> Form
      end.
  
  %%============================================================================
  %% Add/remove module qualifier.
  %%============================================================================
  remove_module_qualifier(Form, {ModName, FunName, Arity}, TargetModName) ->    
      {Form1, _} = refac_util:stop_tdTP(fun do_remove_module_qualifier/2, Form, {{ModName, FunName, Arity}, TargetModName}),
      Form1.
  
  do_remove_module_qualifier(Node, {{ModName, FunName, Arity}, TargetModName}) ->
      case refac_syntax:type(Node) of 
  	application ->
  	    Op = refac_syntax:application_operator(Node),
  	    Args =refac_syntax:application_arguments(Node),
  	    case application_info(Node) of 
  		{{none, FunName}, Arity} -> {Node, true};
  		{{ModName, FunName}, Arity} -> Op1 = refac_syntax:copy_attrs(Op,refac_syntax:atom(FunName)),
  					       Node1 = refac_syntax:copy_attrs(Node, refac_syntax:application(Op1, Args)),
  					       {Node1, true};
  		{{_, apply},2} -> transform_apply_call(Node,{ModName, FunName, Arity}, TargetModName);
  		{{_, apply},3} -> transform_apply_call(Node, {ModName, FunName, Arity}, TargetModName);
  		{{_, spawn}, 3} ->transform_spawn_call(Node, {ModName, FunName, Arity}, TargetModName);
  		{{_, spawn}, 4} -> transform_spawn_call(Node, {ModName, FunName, Arity}, TargetModName); 
  		{{_, spawn_link}, 3} ->transform_spawn_call(Node, {ModName, FunName, Arity}, TargetModName);
  		{{_, spawn_link}, 4} ->transform_spawn_call(Node, {ModName, FunName, Arity}, TargetModName);
  		_ -> {Node, true}
  	    end;		
  	_ ->{Node, false}
      end.
  	    
  add_change_module_qualifier(Form, {ModName, FunName, Arity}, TargetModName) ->
      refac_util:full_tdTP(fun do_add_change_module_qualifier/2,
  			 Form, {{ModName, FunName, Arity}, TargetModName}).
     
  
  do_add_module_qualifier(Node, {{ModName, FunName, Arity}, TargetModName}) ->
     MakeApp = fun (Node1, Operator1, Arguments1,TargetModName1, FunName1) ->
  		     Operator2 =refac_syntax:copy_attrs(Operator1,
  							refac_syntax:module_qualifier(refac_syntax:atom(TargetModName1),
  										      refac_syntax:atom(FunName1))),
  		     Node2= refac_syntax:copy_attrs(Node1, refac_syntax:application(Operator2,Arguments1)),
  		     {Node2, false}
  	     end,
      case refac_syntax:type(Node) of 
  	application ->
  	    Operator = refac_syntax:application_operator(Node),
  	    Arguments = refac_syntax:application_arguments(Node),
  	    As = refac_syntax:get_ann(Op),
  	    case lists:keysearch(fun_def, 1, As)) of 
  	       {value, {fun_def, {Mod1, Fun1, Ari1, _}}} ->
  		 case lists:keysearch({Mod1, Fun1, Ari1}, 1, apply_style_funs()) of 
  
  
  
  		   
  %% 	      case application_info(Node) of 
  %% 		  {{none, FunName}, Arity} -> MakeApp(Node, Operator, Arguments, TargetModName, FunName);	      
  %% 		  {{ModName, FunName}, Arity} ->MakeApp(Node,Operator, Arguments, TargetModName, FunName);
  %% 		  {{_, apply},2} -> transform_apply_call(Node,{ModName, FunName, Arity}, TargetModName);
  %% 		  {{_, apply},3} -> transform_apply_call(Node, {ModName, FunName, Arity}, TargetModName);
  %% 		  {{_, spawn}, 3} ->transform_spawn_call(Node, {ModName, FunName, Arity}, TargetModName);
  %% 		  {{_, spawn}, 4} -> transform_spawn_call(Node, {ModName, FunName, Arity}, TargetModName); 
  %% 		  {{_, spawn_link}, 3} ->transform_spawn_call(Node, {ModName, FunName, Arity}, TargetModName);
  %% 		  {{_, spawn_link}, 4} ->transform_spawn_call(Node, {ModName, FunName, Arity}, TargetModName);
  %% 		   _ -> {Node, false}
  %% 	      end;
  %%        implicit_fun ->
  %% 	   Name = refac_syntax:implicit_fun_name(Node),
  %% 	   B = refac_syntax:atom_value(refac_syntax:arity_qualifier_body(Name)),
  %% 	   A = refac_syntax:integer_value(refac_syntax:arity_qualifier_argument(Name)),
  %% 	   case {B, A} of
  %% 	       {FunName, Arity} ->
  %% 		   FunName1 = refac_syntax:module_qualifier(refac_syntax:atom(TargetModName),
  %% 							    refac_syntax:atom(FunName)),
  %% 		   Node1 = refac_syntax:implicit_fun(FunName1, refac_syntax:arity_qualifier_argument(Name)),
  %% 		   {refac_syntax:copy_attrs(Node, Node1), true};
  %% 	       _ -> {Node, false}
  %% 	   end;
  %%        _  -> {Node, false}
  %%    end.
  %% ====================================================================================
  %%  Processing Client modules.
  %%====================================================================================
  
  refactor_in_client_modules(ClientFiles,{ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth) ->
      case ClientFiles of 
  	[] -> [];
  	[F | Fs] ->
  	    ?wrangler_io("The current file under refactoring is:\n~p\n", [F]),
  	    {ok, {AnnAST, Info}} =refac_util:parse_annotate_file(F,true, SearchPaths, TabWidth),      %% level=1
  	    {AnnAST1, Changed} = 
  				refactor_in_client_module_1({AnnAST, Info}, {ModName, FunName, Arity}, TargetModName),
  		if Changed ->
  		    [{{F,F}, AnnAST1} | refactor_in_client_modules(Fs, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth)];
  	       true -> refactor_in_client_modules(Fs, {ModName, FunName, Arity}, TargetModName, SearchPaths, TabWidth)
  	    end
  	end.
  refactor_in_client_module_1({AnnAST, _Info}, {ModName, FunName, Arity}, TargetModName) ->
      Forms  = refac_syntax:form_list_elements(AnnAST),
      Res = [process_in_client_module(Form, {ModName, FunName, Arity}, TargetModName)||Form <-Forms],
      Forms1 = lists:map(fun({F, _M}) -> F end, Res),
      Changed = lists:member(true, lists:map(fun({_F, M}) -> M end, Res)),
      {refac_syntax:copy_attrs(AnnAST, refac_syntax:form_list(Forms1)), Changed}.
  
  process_in_client_module(Form, {ModName, FunName, Arity}, TargetModName) ->
      case refac_syntax:type(Form) of
        function -> add_module_qualifier(Form, {ModName, FunName, Arity}, TargetModName);
        attribute -> Name = refac_syntax:attribute_name(Form),
  		   case refac_syntax:type(Name) of
  		     atom -> case refac_syntax:atom_value(Name) of
  			       import ->
  				   [H, L] = refac_syntax:attribute_arguments(Form),
  				   Es = refac_syntax:list_elements(L),
  				   Es1 = [E || E <- Es,
  					       {refac_syntax:atom_value(refac_syntax:arity_qualifier_body(E)),
  						refac_syntax:integer_value(refac_syntax:arity_qualifier_argument(E))}
  						 =/= {FunName, Arity}],
  				   {refac_syntax:copy_attrs(Form,
  							    refac_syntax:attribute(Name, [H, refac_syntax:list(Es1)])),
  				    length(Es) =/= length(Es1)};
  			       _ -> {Form, false}
  			     end;
  		     _ -> {Form, false}
  		   end;
        _ -> {Form, false}
      end.
       
  %%================================================================================
  %%              Some Utility Functions 
  %%================================================================================
  
  make_export(Names) ->
      Es = [refac_syntax:arity_qualifier(refac_syntax:atom(F),
  				       refac_syntax:integer(A))
  	  || {F, A} <- Names],
     %% comment(["** The following export is added by Wrangler. **"]),
      [erl_syntax:attribute(erl_syntax:atom('export'), [erl_syntax:list(Es)])].
  
  is_not_the_fun(Form, {ModName, FunName, Arity}) ->
      case refac_syntax:type(Form) of 
  	function -> 
  	    As = refac_syntax:get_ann(Form),
  	    case lists:keysearch(fun_def,1,As) of 
  		{value, {fun_def, {ModName, FunName, Arity, _Pos1, _Pos2}}} ->
  		    false;
  		_ -> true
  	    end;	    
  	_ -> true
      end.
  
  transform_apply_call(Node, {ModName, FunName, Arity}, TargetModName) ->
      Message = fun
  		(Pos) -> ?wrangler_io("WARNING: function ***apply*** is used at location({line, col}):~p, and wrangler "
  				      "could not decide whether this site should be refactored, please check!!!\n",
  				      [Pos])
  	      end,
      Operator = refac_syntax:application_operator(Node),
      Arguments = refac_syntax:application_arguments(Node),
      case Arguments of
        [Fun, Args] ->
  	  case refac_syntax:type(Fun) of
  	    implicit_fun ->
  		Name = refac_syntax:implicit_fun_name(Fun),
  		B = refac_syntax:atom_value(refac_syntax:arity_qualifier_body(Name)),
  		A = refac_syntax:integer_value(refac_syntax:arity_qualifier_argument(Name)),
  		case {B, A} of
  		  {FunName, Arity} ->
  		      FunName1 = refac_syntax:module_qualifier(refac_syntax:atom(TargetModName),
  							       refac_syntax:atom(FunName)),
  		      Fun1 = refac_syntax:implicit_fun(FunName1, refac_syntax:arity_qualifier_argument(Name)),
  		      {refac_syntax:copy_attrs(Node, refac_syntax:application(Operator, [Fun1, Args])), true};
  		  _ -> {Node, false}
  		end;
  	    _ -> {Node, false}
  	  end;
        [Mod, Fun, Args] ->
  	  Mod1 = refac_util:try_evaluation([refac_syntax:revert(Mod)]),
  	  Fun1 = refac_util:try_evaluation([refac_syntax:revert(Fun)]),
  	  Pos = refac_syntax:get_pos(Node),
  	  case Fun1 of
  	    {value, FunName} ->
  		case Mod1 of
  		  {value, ModName} ->
  		      case refac_syntax:type(Args) of
  			list ->
  			    case refac_syntax:list_length(Args) of
  			      Arity ->
  				  Mod2 = refac_syntax:atom(TargetModName),
  				  {refac_syntax:copy_pos(Node, refac_syntax:copy_attrs(Node,
  										       refac_syntax:application(Operator, [Mod2, Fun, Args]))), true};
  			      _ -> {Node, false}
  			    end;
  			nil -> if Arity == 0 ->
  				      Mod2 = refac_syntax:atom(TargetModName),
  				      {refac_syntax:copy_pos(Node, refac_syntax:copy_attrs(Node,
  											   refac_syntax:application(Operator, [Mod2, Fun, Args]))), true};
  				  true -> {Node, false}
  			       end;
  			_ -> Message(Pos),
  			     {Node, false}
  		      end;
  		  {value, _} -> {Node, false};
  		  {error, _Reason} ->
  		      case refac_syntax:type(Args) of
  			list -> case refac_syntax:list_length(Args) of
  				  Arity -> Message(Pos),
  					   {Node, false};
  				  _ -> {Node, false}
  				end;
  			_ -> Message(Pos),
  			     {Node, false}
  		      end
  		end;
  	    {value, _} -> {Node, false};
  	    {error, _Reason} ->
  		case Mod1 of
  		  {value, ModName} ->
  		      case refac_syntax:type(Args) of
  			list -> case refac_syntax:list_length(Args) of
  				  Arity -> Message(Pos),
  					   {Node, false};
  				  _ -> {Node, false}
  				end;
  			_ -> Message(Pos),
  			     {Node, false}
  		      end;
  		  {value, _} -> {Node, false};
  		  {error, _Reason} -> case refac_syntax:type(Args) of
  					list -> case refac_syntax:list_length(Args) of
  						  Arity -> Message(Pos),
  							   {Node, false};
  						  _ -> {Node, false}
  						end;
  					_ -> Message(Pos),
  					     {Node, false}
  				      end
  		end
  	  end;
        _ -> {Node, false}
      end.
  
  transform_spawn_call(Node, {ModName, FunName, Arity}, TargetModName) ->
      Message = fun
  		(Pos) -> ?wrangler_io("WARNING: function ***spawn*** is used at location({line, col}):~p, and wrangler "
  				      "could not decide whether this site should be refactored, please check!!!\n",
  				      [Pos])
  	      end,
      Operator = refac_syntax:application_operator(Node),
      Arguments = refac_syntax:application_arguments(Node),
      [N, Mod, Fun, Args] = if length(Arguments) == 4 -> Arguments;
  			     true -> [none] ++ Arguments
  			  end,
      Mod1 = refac_util:try_evaluation([refac_syntax:revert(Mod)]),
      Fun1 = refac_util:try_evaluation([refac_syntax:revert(Fun)]),
      Pos = refac_syntax:get_pos(Node),
      case Fun1 of
        {value, FunName} ->
  	  case Mod1 of
  	    {value, ModName} ->
  		case refac_syntax:type(Args) of
  		  list ->
  		      case refac_syntax:list_length(Args) of
  			Arity ->
  			    Mod2 = refac_syntax:atom(TargetModName),
  			    App = if length(Arguments) == 4 ->
  					 refac_syntax:application(Operator, [N, Mod2, Fun, Args]);
  				     true -> refac_syntax:application(Operator, [Mod2, Fun, Args])
  				  end,
  			    {refac_syntax:copy_pos(Node, refac_syntax:copy_attrs(Node, App)), true};
  			_ -> {Node, false}
  		      end;
  		  nil -> if Arity == 0 ->
  				Mod2 = refac_syntax:atom(TargetModName),
  				App = if length(Arguments) == 4 ->
  					     refac_syntax:application(Operator, [N, Mod2, Fun, Args]);
  					 true -> refac_syntax:application(Operator, [Mod2, Fun, Args])
  				      end,
  				{refac_syntax:copy_pos(Node, refac_syntax:copy_attrs(Node, App)), true};
  			    true -> {Node, false}
  			 end;
  		  _ -> Message(Pos),
  		       {Node, false}
  		end;
  	    {value, _} -> {Node, false};
  	    {error, _Reason} ->
  		case refac_syntax:type(Args) of
  		  list -> case refac_syntax:list_length(Args) of
  			    Arity -> Message(Pos),
  				     {Node, false};
  			    _ -> {Node, false}
  			  end;
  		  _ -> Message(Pos),
  		       {Node, false}
  		end
  	  end;
        {value, _} -> {Node, false};
        {error, _Reason} ->
  	  case Mod1 of
  	    {value, ModName} ->
  		case refac_syntax:type(Args) of
  		  list -> case refac_syntax:list_length(Args) of
  			    Arity -> Message(Pos),
  				     {Node, false};
  			    _ -> {Node, false}
  			  end;
  		  _ -> Message(Pos),
  		       {Node, false}
  		end;
  	    {value, _} -> {Node, false};
  	    {error, _Reason} -> case refac_syntax:type(Args) of
  				  list -> case refac_syntax:list_length(Args) of
  					    Arity -> Message(Pos),
  						     {Node, false};
  					    _ -> {Node, false}
  					  end;
  				  _ -> Message(Pos),
  				       {Node, false}
  				end
  	  end
      end.
  
  get_fun_def_info(Node) ->
      As = refac_syntax:get_ann(Node),
      case lists:keysearch(fun_def, 1, As) of
        {value,
         {fun_def, {Mod, FunName, Arity, _UsePos, DefinePos}}} ->
  	  {Mod, FunName, Arity, DefinePos};
        _ -> false
      end.
  
  
  is_mod_name(A) ->
      refac_util:is_fun_name(A).
  
  
  comment(Txt) ->
      comment(Txt, ?COMMENT_PREFIX).
  
  comment(Txt, Prefix) ->
      erl_syntax:comment(prefix_lines(split_lines(Txt), Prefix)).
  
  prefix_lines([L | Ls], Prefix) ->
      [Prefix ++ L | prefix_lines(Ls, Prefix)];
  prefix_lines([], _) ->
      [].
  
  split_lines(Ls) ->
      split_lines(Ls, []).
  
  split_lines([L | Ls], Ls1) ->
      split_lines(Ls, split_lines(L, [], Ls1));
  split_lines([], Ls1) ->
      lists:reverse(Ls1).
  
  %% split_lines([$\r, $\n | Cs], Cs1, Ls) ->
  %%     split_lines_1(Cs, Cs1, Ls);
  %% split_lines([$\r | Cs], Cs1, Ls) ->
  %%     split_lines_1(Cs, Cs1, Ls);
  %% split_lines([$\n | Cs], Cs1, Ls) ->
  %%     split_lines_1(Cs, Cs1, Ls);
  %% split_lines([C | Cs], Cs1, Ls) ->
  %%     split_lines(Cs, [C | Cs1], Ls);
  split_lines([], Cs, Ls) ->
      [lists:reverse(Cs) | Ls].
  
  %% split_lines_1(Cs, Cs1, Ls) ->
  %%     split_lines(Cs, [], [lists:reverse(Cs1) | Ls]).
  
negative.code: 
  -export([move_fun/7, move_fun_eclipse/7]).
  
  -import(refac_rename_fun, [check_atoms/4, start_atom_process/0,output_atom_warning_msg/3, stop_atom_process/1]).
  
  -include("../include/wrangler.hrl").
  
  %==========================================================================================
  -spec(move_fun/7::(filename(),integer(),integer(), string(), atom(),[dir()], integer())->
           {ok, [filename()]} | {error, string()}).
  %%==========================================================================================
  move_fun(FName, Line, Col, TargetModorFileName, CreateNewFile, SearchPaths, TabWidth) ->
      move_fun(FName, Line, Col, TargetModorFileName, CreateNewFile, SearchPaths, TabWidth, emacs).
  
  -spec(move_fun_eclipse/7::(filename(),integer(),integer(), string(), atom(),[dir()], integer())
          ->  {ok, [{filename(), filename(), string()}]} | {error, string()}).
  