anchor.diff:  		      case lists:keysearch(pid, 1, Ann) of 
   			  {value, PidInfo} ->
   			      Node1 = refac_syntax:infix_expr(refac_syntax:atom(RegName), Op, Msg),
  -			      refac_syntax:copy_attrs(Node, Node1);
  -			  _ -> Node
  +			      {refac_syntax:copy_attrs(Node, Node1), true};
  +			  _ -> {Node, false}
   		      end;
   	application -> Operator = refac_syntax:application_operator(Node),
   		       Ann = refac_syntax:get_ann(Operator),
  
positive.code:    
  
  
  do_register(AnnAST, MatchExpr, Pid, RegName) ->
      Ann = refac_syntax:get_ann(Pid),
     {value, PidInfo} = lists:keysearch(pid, 1, Ann),
     {AnnAST1, Modified} = add_register_expr(AnnAST, MatchExpr, RegName),
     case Modified of 
         true ->  Res = refactor_send_exprs(AnnAST1, PidInfo, RegName),
  	       {ok, Res};	    
         _ -> {error, "Wrangler failed to add the registration expression."}
     end.
   
  
  
  refactor_send_exprs(AnnAST, PidInfo, RegName) ->
      refac_util:full_buTP(fun do_refactor_send_exprs/2, AnnAST, {PidInfo, RegName}).
  
  do_refactor_send_exprs(Node, {PidInfo, RegName}) ->
      case refac_syntax:type(Node) of 
  	infix_expr -> Dest = refac_syntax:infix_expr_left(Node),
  		      Op = refac_syntax:infix_expr_operator(Node),
  		      Msg = refac_syntax:infix_expr_right(Node),
  
negative.code: %%
  %% =====================================================================
  %%
  %% @doc This refactoring register a process id, Pid say, with a name, regname say, and replace
  %% the uses of Pid ! Msg with  regname ! Msg if possible. To initiate this refactoring, the 
  %% user should select a match expression whose left-hand side is a process indentifier, and right-hand 
  %% side is a spawn expression.
  %%
  %% Rationale for this refactoring: 
  %% If we want to send a message to a process, then we need to know its PID. This is often inconvenient 
  %% since the PID has to be sent to all the processes in the system that want to comminicate with this process. 
  %% Registering a process with a name allows any process in the system to communicate with this process 
  %% without knowing its PID.
  %%
  %% Side-conditions:
  %%  1. The process name provided by the user should be lexically valid.
  %%  2. The name provided by the user should not have been used as a process name. 
  %%  3. The process under consideration should not have been registered.
  %%  4. Only one process spawned by the spawn expression selected should exist anytime during the running of the system.
  %% 
  %% Transformation:
  %% To perform the transformation, Wrangler needs to know, for each Pid!Msg expression, where the Pid is spawned. 
  %% A Pid is replacable only if Wrangler is sure that it is only associated with the spawn expression selected.
  %% @end
  
  -module(refac_register_pid).
  
  -export([register_pid/5, register_pid_eclipse/5, register_pid_1/8, register_pid_2/7]).
  
  -include("../hrl/wrangler.hrl").
  
  %% ==============================================================================================================
  %% @spec register_pid(FileName::filename(), Start::Pos, End::Pos, RegName::string(),SearchPaths::[dir()])-> term()
  %% @doc This function associates a name, which must be an atom, with a pid, and replaces the uses of this pid in 
  %% send expressions with the name.
  
  -spec(register_pid(FileName::filename(), Start::pos(), End::pos(), RegName::string(),SearchPaths::[dir()])-> 
  	     {error, string()} |{ok, [filename()]}).
  register_pid(FName, Start, End, RegName,  SearchPaths) ->
      register_pid(FName, Start, End, RegName, SearchPaths, emacs).
  
  
  -spec(register_pid_eclipse(FileName::filename(), Start::pos(), End::pos(), RegName::string(),SearchPaths::[dir()])
        -> {error, string()} |{ok, [{filename(), filename(), string()}]}).
  register_pid_eclipse(FName, Start, End, RegName, SearchPaths) ->
      register_pid(FName, Start, End, RegName, SearchPaths, eclipse).
  
  register_pid(FName, Start={Line1, Col1}, End={Line2, Col2}, RegName, SearchPaths, Editor) ->
      io:format("\nCMD: ~p:register_pid(~p, {~p,~p}, {~p,~p}, ~p,~p]\n",  [?MODULE, FName, Line1, Col1, Line2, Col2, RegName, SearchPaths]),
      case refac_util:is_fun_name(RegName) of
  	true ->	{ok, {AnnAST,Info}}= refac_util:parse_annotate_file(FName, true, SearchPaths), 
  		case pos_to_spawn_match_expr(AnnAST, Start, End) of
  		    {ok, _MatchExpr1} ->
  			{value, {module, ModName}} = lists:keysearch(module, 1, Info),
  			RegName1 = list_to_atom(RegName), 
  			ok=refac_annotate_pid:ann_pid_info(SearchPaths),
  			%% get the AST with pid information.
  			{ok, {AnnAST1,_Info}}= refac_util:parse_annotate_file(FName, true, SearchPaths), 
  			{ok, MatchExpr} = pos_to_spawn_match_expr(AnnAST1, Start, End),
  			case pre_cond_check(ModName,AnnAST1, Start, MatchExpr, RegName1, Info, SearchPaths) of 
  			    ok -> 
  				Pid = refac_syntax:match_expr_pattern(MatchExpr),
  				case do_register(FName, AnnAST1, MatchExpr, Pid, RegName1, SearchPaths) of 
  				    {ok, Results} ->
  					case Editor of 
  					    emacs ->
  						refac_util:write_refactored_files(Results),
  						ChangedFiles = lists:map(fun ({{F, _F}, _AST}) -> F end, Results),
  						io:format("The following files have been changed by this refactoring:\n~p\n",
  							  [ChangedFiles]),
  						{ok, ChangedFiles};
  					    eclipse ->
  						 Res = lists:map(fun({{OldFName, NewFName}, AST}) -> 
  									 {OldFName, NewFName, refac_prettypr:print_ast(AST)} end, Results),
  						{ok, Res}
  					end;
  				    {error, Reason} -> {error, Reason}
  				end;	
  			    {unknown_pnames, _UnKnownPNames, RegPids} -> {unknown_pnames, RegPids};
  			    {unknown_pids, UnKnownPids} ->{unknown_pids, UnKnownPids};
  			    {error, Reason} -> {error, Reason}
  			end;
  		    {error, Reason} -> {error, Reason} 
  		end;
  	false -> {error, "Invalid process name."}
      end.
  
  
  -spec(register_pid_1(FName::filename(), StartLine::integer(), StartCol::integer(),EndLine::integer(), EndCol::integer(), 
  		     RegName::string(), RegPids::[{{atom(), atom(), integer()}, syntaxTree()}],
  		     SearchPaths::[dir()])-> {error, string()} |{ok, [filename()]} | {unknown_pids, [{{atom(),atom(),atom()},syntaxTree()}]}).
  register_pid_1(FName, StartLine, StartCol, EndLine, EndCol, RegName, RegPids, SearchPaths) ->
      {Start, End} = {{StartLine, StartCol}, {EndLine, EndCol}},
      {ok, {AnnAST, _Info}} = refac_util:parse_annotate_file(FName, true, SearchPaths),
      {ok, MatchExpr} = pos_to_spawn_match_expr(AnnAST, Start, End),
      Pid = refac_syntax:match_expr_pattern(MatchExpr),
      RegName1 = list_to_atom(RegName), 
      Res = check_registration(MatchExpr, SearchPaths, RegPids), 
      case Res of 
   	 ok ->  case do_register(FName, AnnAST, MatchExpr, Pid, RegName1, SearchPaths) of 
  		    {ok, Results} ->
  			ChangedFiles = lists:map(fun ({{F, _F}, _AST}) -> F end, Results),
  			io:format("The following files have been changed by this refactoring:\n~p\n",
  				  [ChangedFiles]),
  			{ok, ChangedFiles};
  		    {error, Reason} -> {error, Reason}
  		end;
    	{registered, RegExpr} -> {{Line,_Col}, _} = refac_util:get_range(RegExpr),
   				 {error, "The selected process is already registered at line "++ integer_to_list(Line)};
   	{unknown_pids, RegExprs} ->
   	    io:format("\nWrangler could not decide the process(s) registered by the following expression(s), please check!\n"),
  	    lists:foreach(fun({{M, F, A},PidExpr}) -> {{Ln,_},_} = refac_util:get_range(PidExpr),
   				  io:format("Location: module:~p, function: ~p/~p, line: ~p\n ", [M, F, A, Ln]),
   				  io:format(refac_prettypr:format(PidExpr)++"\n") 
  		      end, RegExprs),
   	    {unknown_pids, RegExprs}
      end.
  
  -spec(register_pid_2(FName::filename(), StartLine::integer(), StartCol::integer(), EndLine::integer(),EndCol::integer(), RegName::string(),
  		     SearchPaths::[dir()])-> {error, string()} |{ok, [filename()]}).    
  register_pid_2(FName, StartLine, StartCol, EndLine, EndCol, RegName, SearchPaths) ->
      {Start, End} = {{StartLine, StartCol}, {EndLine, EndCol}},
      {ok, {AnnAST, _Info}} = refac_util:parse_annotate_file(FName, true, SearchPaths),
      {ok, MatchExpr} = pos_to_spawn_match_expr(AnnAST, Start, End),
      Pid = refac_syntax:match_expr_pattern(MatchExpr),
      RegName1 = list_to_atom(RegName),
      case do_register(FName,AnnAST, MatchExpr, Pid, RegName1, SearchPaths) of 
  	{ok, Results} ->
  	    refac_util:write_refactored_files(Results),
  	    ChangedFiles = lists:map(fun ({{F, _F}, _AST}) -> F end, Results),
  	    io:format("The following files have been changed by this refactoring:\n~p\n",
  		      [ChangedFiles]),
  	    {ok, ChangedFiles};
  	{error, Reason} -> {error, Reason}
      end.
  
  
  
  %% 3. At any time during the running of the system, only one process can be associated with a particular process name.  Since statically we 
  %% cannot decide when a process starts/dies, we use a rather stronger condition, that is the function containing the registration is only 
  