anchor.diff:  		    refac_syntax:operator_name(Op) == '!';
   		_ -> false
   	    end;
  -	_ -> false
  -    end.
  -
  -
  -
  -trim_callgraph(DirList) ->
  -    Files = refac_util:expand_files(DirList, ".erl"),
  -    CallGraph = refac_util:build_callgraph(Files, []),
  -    #callgraph{scc_order = Sccs, external_calls = _E} = refac_callgraph:construct(CallGraph),
  -    CallerCallee = lists:map(fun({{Caller, _CallerDef}, Callee}) ->
  -					{Caller, Callee} end, CallGraph),
  -    Res = trim_scc(Sccs, CallerCallee, [], []),
  -    %% Sccs1 =[[Fun||{Fun, _FunDef}<-Scc]||Scc<-Res],
  -    Res.
  +	application -> Op = refac_syntax:application_operator(Tree),
  +		       Ann = refac_syntax:get_ann(Op),
  +		       case lists:keysearch(fun_def,1, Ann) of 
  +			   {value, {fun_def, {erlang, send, 2, _Pos1, _Pos2}}} -> true;
  +			   _ -> false
  +		       end;
  + 	_ ->false
       
  -
  -trim_scc([], _CallerCallee, _PFunAcc, Acc) -> lists:reverse(Acc);
  -trim_scc([Scc|Sccs], CallerCallee, PFunAcc, Acc) ->
  -    SccFuns = lists:map(fun({Fun, _FunDef}) -> Fun end, Scc),
  -    IsProcessScc = lists:any(fun({_Fun, FunDef}) ->is_process_related_fun(FunDef) end, Scc),
  -    CalledFuns = lists:usort(lists:flatmap(fun(Fun) ->
  -						   case lists:keysearch(Fun, 1, CallerCallee) of 
  -						       {value, {Fun, Called}} ->
  -							   Called;
  -						       _ -> []
  -						   end
  -					   end, SccFuns)),
  -    PFunsCalled = length(lists:subtract(CalledFuns, PFunAcc))<length(CalledFuns),
  -    case  IsProcessScc orelse PFunsCalled of 
  -	true ->
  -	    trim_scc(Sccs, CallerCallee,SccFuns++PFunAcc,  [Scc|Acc]);
  -	_ -> trim_scc(Sccs, CallerCallee, PFunAcc, Acc)
  -    end. 
  -
  -is_process_related_fun(FunDef) ->
  -    ProcessFuns = [{erlang, register, 2}, {erlang, self, 0}, {erlang, spawn, 1}, {erlang, spawn,2}, {erlang, spawn, 3},
  -		   {erlang, spawn, 4}, {erlang, spawn_link, 1}, {erlang, spawn_link, 2}, {erlang, spawn_link, 3},
  -		   {erlang, spawn_link, 4}],
  -    F = fun(Node, _Others) ->
  -		case refac_syntax:type(Node) of
  -		    infix_expr->
  -			case is_send_expr(Node) of
  -			    true -> {true, true};
  -			    _ -> {[], false}
  -			end;
  -		    receive_expr ->
  -			{true, true};
  -		    application ->
  -			Operator = refac_syntax:application_operator(Node),
  -			Arity = length(refac_syntax:application_arguments(Node)),
  -			case refac_syntax:type(Operator) of 
  -			    atom ->
  -				Op = refac_syntax:atom_value(Operator),
  -				{value, {fun_def, {M, Op, A, _, _}}} = lists:keysearch(fun_def,1, refac_syntax:get_ann(Operator)),
  -				case lists:member({M, Op, A}, ProcessFuns) of 
  -				    true -> {true, true};
  -				    _ -> {[], false}
  -				end;
  -			    module_qualifier ->
  -				Mod = refac_syntax:module_qualifier_argument(Operator),
  -				Body = refac_syntax:module_qualifier_body(Operator),
  -				case {refac_syntax:type(Mod), refac_syntax:type(Body)} of 
  -				    {atom, atom} ->
  -					M = refac_syntax:atom_value(Mod),
  -					Op = refac_syntax:atom_value(Body),
  -					case  lists:member({M, Op, Arity}, ProcessFuns) of 
  -					    true -> {true, true};
  -					    _ -> {[], false}
  -					end;
  -				    _ -> {[], false}
  -				end;
  -			    _ -> {[], false}
  -			end;
  -		    _ -> {[], false}
  -		end
  -	end,
  -    case refac_util:once_tdTU(F, FunDef, []) of 
  -	{_, false} ->
  -	    false;
  -	{_R, true}  -> 
  -	    true
  -    end.
  -		    
  -
  -send_expr_to_region(FileName, _ModName, FunName, Arity, Index) ->
  -
  -    F1 = fun(Node, Acc) ->
  -		case is_send_expr(Node) of 
  -		    true -> Acc++[Node];
  -		    _ -> Acc
  -		end
  -	 end,
  -    F = fun(Node, _Others) ->
  -	   case refac_syntax:type(Node) of 
  -	       function ->
  -		   FunName1 = refac_syntax:data(refac_syntax:function_name(Node)),
  -		   Arity1 = refac_syntax:function_arity(Node),
  -		   case {FunName1, Arity1} of 
  -		       {FunName, Arity} -> SendExprs = refac_syntax_lib:fold(F1, [], Node),
  -					   SendExpr = lists:nth(Index, SendExprs),
  -					   {{Line1, Col1},{Line2, Col2}} = refac_util:get_range(SendExpr),
  -					   {{Line1, Col1, Line2, Col2}, true};
  -		       _ -> {[], false}
  -		   end;
  -	       _ -> {[], false}
  -	   end
  -	end,
  -    case refac_util:parse_annotate_file(FileName, true, []) of   %% SearchPaths temporally empty; Need to be modifed.
  -	{ok, {AnnAST, _Info}} -> case refac_util:once_tdTU(F, AnnAST, []) of
  - 				    {Res, true} -> {ok, Res};
  -				    {_, false} -> {error, "Send expression not found!"}
  -				end;
  -	{error, Reason} -> {error, Reason}
  -    end.
  -
  -do_add_a_tag(AnnAST, Tag, ModName, InitialFuns,ReceiveFuns,Trace) ->
  -    refac_util:stop_tdTP(fun do_add_a_tag_1/2, AnnAST, {refac_syntax:atom(Tag), ModName, InitialFuns, ReceiveFuns, Trace}).
  -
  -do_add_a_tag_1(Node, {Tag, ModName, InitialFuns, ReceiveFuns, Trace}) ->
  -    case refac_syntax:type(Node) of 
  -	function ->
  -	    FunName = refac_syntax:data(refac_syntax:function_name(Node)),
  -	    Arity = refac_syntax:function_arity(Node),
  -	    Node1 = refac_util:full_buTP(fun do_add_a_tag_2/2, Node, 
  - 				 {Tag,lists:member({ModName, FunName, Arity}, ReceiveFuns)}),
  -	    Pid = start_counter_process(),
  -	    Res = refac_util:stop_tdTP(fun do_add_a_tag_3/2, Node1, {{ModName, FunName, Arity}, Tag, InitialFuns, Pid,Trace}),
  -	    Pid ! stop,
  -	    Res;
  -	_ -> {Node, false}
  -    end.
  -				 
  -do_add_a_tag_2(Node, {Tag, AffectedReceiveFun}) ->
  -    F = fun(C) ->
  -		P = refac_util:ghead("do_add_a_tag_2", refac_syntax:clause_patterns(C)),
  -		G = refac_syntax:clause_guard(C),
  -		B = refac_syntax:clause_body(C),
  -		P1 = case refac_syntax:type(P) of 			 
  -			 tuple -> 
  -			     Es=[Tag|refac_syntax:tuple_elements(P)],
  -			     refac_syntax:tuple(Es);
  -			 _ -> refac_syntax:tuple([Tag, P]) %%WHEN THE MESSAGE IS NOT A TUPLE.
  -		     end,
  -		refac_syntax:clause([P1], G, B)
  -	end,
  -    case refac_syntax:type(Node) of 
  -	receive_expr ->
  -	    if AffectedReceiveFun 
  -	       -> Cs = refac_syntax:receive_expr_clauses(Node),
  -		  Cs1 = lists:map(F, Cs),
  -		  refac_syntax:receive_expr(Cs1);
  -	       true -> Node
  -	    end;
  -	_ -> Node
  -    end. 
  -
  -do_add_a_tag_3(Node, {{ModName, FunName, Arity}, Tag, InitialFuns, Pid, Trace}) ->		    
  -    case refac_syntax:type(Node) of
  -	infix_expr ->
  -	    case is_send_expr(Node) of 
  -		true ->
  -		    Pid ! {self(), next},
  -		    receive
  -			{Pid, N} -> N
  -		    end,
  -		    Fs = get_initial_funs({ModName, FunName, Arity, N}, Trace),
  -		    case Fs of 
  -			[] ->  %% WARNING: NOT COVERED BY THE TRACE INFO.
  -			    send_collector ! {add, {ModName, FunName, Arity, N}},
  -			    {Node, true};
  -			_ -> case length(Fs) > length(lists:subtract(Fs, InitialFuns)) of 
  -				 true ->  %% Covered by trace, and IS affected by the refactoring.
  -				     ReceiverPid = refac_syntax:infix_expr_left(Node),
  -				     Msg = refac_syntax:infix_expr_right(Node),
  -				     Op  = refac_syntax:infix_expr_operator(Node),
  -				     Msg1 = case refac_syntax:type(Msg) of 
  -						tuple ->
  -						    refac_syntax:tuple([Tag | refac_syntax:tuple_elements(Msg)]);
  -						_ -> refac_syntax:tuple([Tag, Msg])
  -					    end,
  -				     {refac_syntax:infix_expr(ReceiverPid, Op, Msg1), true};
  -				 false -> {Node, true}   %% Covered by trace, but is not affected by the refactoring.
  -			     end
  -		    end;  
  -		_ -> 
  -		    {Node, false}
  -	    end;
  -	_ ->
  -	    {Node, false}
  -    end.
  -
  -get_reached_receive_funs_1(Inits, InitReceivers) ->
  -    F = fun({Int, Receivers}) ->
  -		case Int of 
  -		    {Mod, Fun, Arity} ->
  -			case lists:member({Mod, Fun, Arity}, Inits) of 
  -			    true -> Receivers;
  -			    _ -> []
  -			end;
  -		    {Mod, Fun, Arity, Index, _Def} ->
  -			case lists:member({Mod, Fun, Arity, Index}, Inits) of
  -			    true -> Receivers;
  -			    _ -> []
  -			end
  -		end
  -	end,
  -     lists:usort(lists:flatmap(F, InitReceivers)).
  -
  -process_trace_info(CacheFile) ->
  -    F = fun(E, Spawns) ->
  -		Pids = lists:map(fun(S) ->element(3,S) end, Spawns),
  -		case E of 
  -		    {send, CurrentFun, ReceiverPid, {initial_call, {erlang, apply,2}}, ReceiverCurrentFun} ->
  -			case lists:member(ReceiverPid, Pids) of 
  -			    true -> 
  -				case lists:keysearch(ReceiverPid, 3, Spawns) of
  -				    {value, {spawn, Initial, ReceiverPid}} ->
  -					[{send, CurrentFun, ReceiverPid, {initial_call, Initial}, ReceiverCurrentFun}];
  -				    false -> [E]
  -				end;
  -			    false -> [E]
  -			end;
  -		    {spawn, _, _} -> [];
  -		    _ -> [E]
  -		end
  -	end,
  -    case dets:open_file(CacheFile) of
  -      {ok, Tab} ->
  -	    Trace = lists:append(dets:match(Tab, '$1')),
  -	    dets:close(Tab),
  -	    Spawns = lists:filter(fun(E) -> element(1, E) == spawn end, Trace),
  -	    lists:concat(lists:map(fun(E) -> F(E, Spawns) end, Trace));					      
  -      {error, Reason} -> erlang:error(Reason)
  -    end.
  -
  -get_initial_funs(Send, Trace) ->
  -    Res = lists:filter(fun(T) -> element(2, T) == Send end, Trace),
  -    lists:flatmap(fun({_, _, _, {initial_call, F1}, {current_function, F2}}) 
  -		 -> [F1, F2] end, Res).
  -		       
  -
  -get_affected_funs_from_send(Trace, AffectedInitials, ReceiveFuns) ->
  -    GroupedTrace = group_by(2, Trace),
  -    Res = get_affected_funs_from_send_1(GroupedTrace, AffectedInitials, ReceiveFuns),
  -    case Res == AffectedInitials of 
  -	true ->
  -	    Res;
  -	%% otherwise, repeat until a fix-point has been reached.
  -	_ -> get_affected_funs_from_send(Trace, Res, ReceiveFuns)
  -    end.
  -
  -get_affected_funs_from_send_1([], AffectedInitials, _ReceiveFuns) ->
  -    AffectedInitials;
  -get_affected_funs_from_send_1([G|Gs], AffectedInitials, ReceiveFuns) ->
  -   F = fun({send, _, _, {initial_call, F1}, {current_function, F2}}) ->
  -	       case F1 of 
  -		   {erlang, apply, 2} ->
  -		       case lists:member(F2, ReceiveFuns) of 
  -			   true ->
  -			       [F2];
  -			   _  -> []
  -		       end;
  -		   _ -> [F1]
  -	       end
  -       end,
  -   Funs =lists:usort(lists:flatmap(F, G)),
  -   Len = length(lists:subtract(Funs, AffectedInitials)),
  -   case (Len <  length(Funs)) andalso (0<Len)  of 
  -       true -> get_affected_funs_from_send_1(Gs, lists:usort(Funs++AffectedInitials), ReceiveFuns);
  -       _  -> get_affected_funs_from_send_1(Gs, AffectedInitials, ReceiveFuns)
  -   end.
  -
  -
  -group_by(N, TupleList) ->
  -    group_by_1(N, lists:keysort(N, TupleList)).
  -
  -group_by_1(_N, []) -> [];
  -group_by_1(N, TupleList=[E|_Es])->
  -    NthEle = element(N, E),
  -    {E1,E2} = lists:splitwith(fun(T) -> element(N,T) == NthEle end, TupleList),
  -    [E1 | group_by_1(N, E2)].
  -    
  -pos_to_receive_fun(AnnAST, Pos) ->
  -    case refac_util:pos_to_fun_def(AnnAST, Pos) of 
  -	{ok, FunDef} ->
  -	    case has_receive_expr(FunDef) of 
  -		true -> {ok, FunDef};
  -		_ -> {error, none}
  -	    end;	    
  -	_  -> {error, none}
  -    end.
  -
  -has_receive_expr(Node) ->
  -    case refac_util:once_tdTU(fun has_receive_expr/2, Node, []) of 
  -	{_, false} ->
  -	     false;
  -	{_R, true} -> true
  -    end.
  -
  -has_receive_expr(Node, []) ->
  -    case refac_syntax:type(Node) of 
  -	receive_expr ->
  -	    {Node, true};
  -	_  ->{[], false}
  -    end.
  -
  -
  -collect_receive_funs(AnnAST, Info) ->
  -    {value, {module, ModName}} = lists:keysearch(module, 1, Info),
  -    F = fun(T, Acc) ->
  -		case refac_syntax:type(T) of 
  -		    function ->
  -			case has_receive_expr(T) of 
  -			    true ->  FunName = refac_syntax:data(refac_syntax:function_name(T)),
  -				     Arity = refac_syntax:function_arity(T),
  -				     [{ModName, FunName, Arity}|Acc];
  -			    _ -> Acc
  -			end;
  -		    _ -> Acc
  -		end
  -	end,
  -    refac_syntax_lib:fold(F, [], AnnAST).
  -
  -collect_process_initial_funs(AnnAST, Info) ->  %% TODO: THINK ABOUT MULTIPLE MODULES.
  -    {value, {module, ModName}} = lists:keysearch(module, 1, Info),
  -    HandleSpecialFuns = fun(Arguments) ->
  -				case Arguments of
  -				    [M, F, A] ->
  -				           ModName = refac_syntax:atom_value(M),
  -					    FunName = refac_syntax:atom_value(F),
  -					    Arity = refac_syntax:list_length(A),
  -					    {ModName, FunName, Arity};
  -				    [_N, M, F, A] ->
  -				            ModName = refac_syntax:atom_value(M),
  -					    FunName = refac_syntax:atom_value(F),
  -					    Arity = refac_syntax:list_length(A),
  -					    {ModName, FunName, Arity}	   
  -				    end
  -			end,
  -    Fun= fun(Node, Acc) ->			       
  -		 case refac_syntax:type(Node) of 
  -		     function ->
  -			 FunName = refac_syntax:data(refac_syntax:function_name(Node)),
  -			 FunArity = refac_syntax:function_arity(Node),
  -			 Pid = start_counter_process(),
  -			 F = fun(T, S) ->
  -				     case refac_syntax:type(T) of
  -					 application ->
  -					     Operator = refac_syntax:application_operator(T),
  -					     Arguments = refac_syntax:application_arguments(T),
  -					     Arity = length(Arguments),
  -					     case refac_syntax:type(Operator) of 
  -						 atom ->
  -						     Op = refac_syntax:atom_value(Operator),  % Todo: Need to think about user-defined spawn.
  -						     case {Op, Arity} of                      %%TODO: ADD OTHER VARIANTS OF SPAWN.
  -							 {spawn, 1} -> Pid ! {self(), next},
  -								       receive 
  -									   {Pid, N} -> N
  -								       end,
  -								       [{ModName, FunName, FunArity, N,hd(Arguments)}| S];
  -							 {spawn, 3} ->  [HandleSpecialFuns(Arguments)|S];
  -							 _ -> S
  -						     end;
  -						 _ -> S
  -					     end;
  -					 _ -> S
  -				     end
  -			     end,
  -			 Res = refac_syntax_lib:fold(F, [],  Node),
  -			 Pid ! stop,
  -			 lists:usort(Res ++ Acc);
  -		     _ -> Acc
  -		 end
  -	 end,
  -    refac_syntax_lib:fold(Fun, [], AnnAST).
  -		 
  -
  -start_fun_typesig_process(Funs)->
  -    spawn_link(refac_add_a_tag, fun_typesig, [Funs]).
  -
  -
  -fun_typesig(Funs) ->
  -    InitialEnv = lists:map(fun({Mod, Fun, Arity}) ->
  -				   {{Mod, Fun, Arity}, {lists:duplicate(Arity, any), any}} end, Funs), 
  -    fun_typesig_loop(InitialEnv).
  -
  -fun_typesig_loop(Env) ->
  -    F = fun(T1, T2) ->
  -		case T1 of 
  -		    any -> T2;
  -		    {process, V1} ->
  -			case T2 of 
  -			    any -> T1;
  -			    {process, V2} ->
  -				{process, lists:usort(V1++V2)}
  -			end
  -		end
  -	end,
  -    receive
  -	{From, get, Fun} ->
  -	    case  lists:keysearch(Fun,1, Env) of 
  -		{value, {Fun, TypeSig}} ->
  -		    From! {self(), value, TypeSig};
  -		false  -> From!{self(), false}
  -	    end,
  -	    fun_typesig_loop(Env);
  -	{add, {Fun, {Args, Ret}}} ->
  -	    case lists:keysearch(Fun, 1, Env) of 
  -		{value, {Fun, {Args1, Ret1}}} ->
  -		    NewArgs = lists:map(fun({S, S1}) ->
  -					F(S, S1)
  -					end, lists:zip(Args, Args1)),
  -		    NewEnv=lists:keyreplace(Fun,1, Env, {Fun, {NewArgs, F(Ret, Ret1)}}),
  -		    fun_typesig_loop(NewEnv);
  -		false ->
  -		    fun_typesig_loop(Env)
  -	    end;
  -	{From, getenv} ->
  -	    From ! {self(), Env},
  -	    fun_typesig_loop(Env);
  -	stop ->
  -	    io:format("Types:\n~p\n", [Env]),
  -	    ok
  -    end.
  -	    
  -	      
  -
  -
  -start_env_process() ->
  -     spawn_link(refac_add_a_tag, env, []).
  -
  -env() ->
  -     env_loop([]).
  -
  -env_loop(Env) ->
  -    receive
  -	{From, get, Key} ->
  -	    case lists:keysearch(Key, 1, Env) of 
  -		{value, {Key, Value}} -> From!{self(), value, Value};
  -		false -> From!{self(), false}
  -	    end,
  -	    env_loop(Env);
  -	{add, {Key, Value}} ->
  -	    case lists:keysearch(Key, 1, Env) of 
  -		{value, {Key, _}} ->
  -		    lists:keyreplace(Key,1, Env, {Key, Value}),
  -		    env_loop(Env);
  -		false ->
  -		    env_loop([{Key, Value} | Env])
  -	    end;   
  -	stop ->
  -	   %%io:format("EnvP:\n~p\n", [Env]),
  -	    ok
  -    end.
  -
  -
  -start_counter_process() ->
  -     spawn_link(refac_add_a_tag, counter, []).
  -
  -counter() ->
  -     loop(1).
  -
  -loop(N) ->
  -    receive
  -	{From, next} ->
  -	    From ! {self(), N},
  -	    loop(N+1);
  -	stop ->
  -	    ok
  -    end.
  -
  -start_collector_process() ->
  -    register(send_collector, spawn(refac_add_a_tag, collector, [])).
  -    
  -
  -collector() ->
  -    collector_loop([]).
  -
  -collector_loop(S) ->
  -    receive
  -	{add, E} ->
  -	    collector_loop([E|S]);
  -	{get, From} ->
  -	    From ! {collector, S},
  -	    collector_loop(S);
  -	stop ->
  -	    ok
  -    end.
  -    
  -	    
  -
  -remove_spawn_pars(Node) ->   
  -    refac_util:stop_tdTP(fun do_remove_spawn_pars/2, Node, []).
  -
  -do_remove_spawn_pars(Node, []) ->
  -    case refac_syntax:type(Node) of 
  -	application ->
  -	    Operator = refac_syntax:application_operator(Node),
  -	    case refac_syntax:type(Operator) of
  -		atom ->
  -		    case refac_syntax:atom_value(Operator) of 
  -			spawn ->
  -			    Node1 = refac_syntax:application(Operator, []),
  -			    {Node1, true};
  -			_ -> {Node, false}
  -		    end;
  -		_ -> {Node, false}
  -	    end;
  -	_ -> {Node, false}
  -    end.
  -		    
  -
  -    
  -   
  -reached_receive_funs([], _Callgraph, _ReceiveFuns, _Info) -> [];
  -reached_receive_funs(InitialFuns, CallGraph, ReceiveFuns, Info) ->
  -    {value, {module, ModName}} = lists:keysearch(module, 1, Info),
  -     Inscope_Funs = [{erlang, Fun, Arity} || {Fun, Arity} <- refac_util:auto_imported_bifs()] ++
  -		     refac_util:inscope_funs(Info),  %% NOTE: orders matters here.
  -     F2 = fun (T, S) ->
  -		 case refac_syntax:type(T) of
  -		   application ->
  -		       Operator = refac_syntax:application_operator(T),
  -		       Arguments = refac_syntax:application_arguments(T),
  -		       Arity = length(Arguments),
  -		       case refac_syntax:type(Operator) of
  -			 atom ->
  -			     Op = refac_syntax:atom_value(Operator),
  -			     R = lists:filter(fun ({_M, F, A}) -> (F == Op) and (A == Arity) end, Inscope_Funs),
  -			     if R == [] ->
  -				    ordsets:add_element({unknown, Op, Arity},
  -							S);  %% Should we give an error message here?
  -				true ->
  -				    {M, Op, Arity} = hd(R),
  -				     ordsets:add_element({M, Op, Arity}, S)
  -				end;
  -			   module_qualifier ->
  -			       Mod = refac_syntax:module_qualifier_argument(Operator),
  -			       Body = refac_syntax:module_qualifier_body(Operator),
  -			       case {refac_syntax:type(Mod), refac_syntax:type(Body)} of
  -				   {atom, atom} ->
  -				       Mod1 = refac_syntax:atom_value(Mod),
  -				       Op = refac_syntax:atom_value(Body),
  -				       ordsets:add_element({Mod1, Op, Arity}, S);
  -				   _ -> S
  -			       end
  -			   end;
  -		     arity_qualifier ->
  -			 Fun = refac_syntax:arity_qualifier_body(T),
  -			 A = refac_syntax:arity_qualifier_argument(T),
  -			 case {refac_syntax:type(Fun), refac_syntax:type(A)} of
  -			     {atom, integer} ->
  -				 FunName = refac_syntax:atom_value(Fun),
  -				 Arity = refac_syntax:integer_value(A),
  -				 ordsets:add_element({ModName, FunName, Arity}, S);
  -			     _ -> S
  -			 end;
  -		     _ -> S
  -		 end
  -	  end,
  -    F  = fun(InitialFun) ->
  -		 case InitialFun of 
  -		     {Mod, Fun, Arity} -> [{Mod,Fun, Arity}];
  -		     {_Mod, _Fun, _Arity, _Index, FunExpr} ->
  -			 lists:usort(refac_syntax_lib:fold(F2, [], FunExpr))
  -		 end
  -	 end,		 
  -    ReachedFuns = lists:zip(InitialFuns, lists:map(fun(InitialFun) -> 
  -							   reached_funs(CallGraph, F(InitialFun)) end, 
  -						   InitialFuns)),
  -
  -    FunsReachedFromInitials=lists:map(fun({Initial, Reached}) -> 
  -					      {Initial, lists:subtract(ReceiveFuns, lists:subtract(ReceiveFuns, Reached))} end, ReachedFuns),
  -    StandAloneReceivers  = lists:subtract(ReceiveFuns, lists:concat(lists:map(fun({_Initial, Receivers})->
  -										       Receivers end, FunsReachedFromInitials))),
  -    ReachedByStandAlones =  lists:zip(StandAloneReceivers, lists:map(fun(InitialFun) -> 
  -							   lists:usort([InitialFun |reached_funs(CallGraph, F(InitialFun))]) end, 
  -						   StandAloneReceivers)),
  -    ReachedByStandAlones1=lists:map(fun({Initial, Reached}) -> 
  -					      {Initial, lists:subtract(ReceiveFuns, lists:subtract(ReceiveFuns, Reached))} end, ReachedByStandAlones),
  -    FunsReachedFromInitials++ReachedByStandAlones1.
  -
  -
  - 
  -reached_funs(CallGraph, Acc) ->
  -    Res = lists:usort(lists:concat(lists:map(fun({Mod, Fun, Args}) ->
  -					 case lists:keysearch({Mod, Fun, Args}, 1, CallGraph) of 
  -					     {value, {{Mod, Fun, Args}, CalledFuns}} ->
  -						 CalledFuns;
  -					     _ ->[]
  -					 end
  -				 end, Acc))),
  -     case lists:usort(Res++Acc) == Acc of 
  -	true -> Res;
  -	_ -> reached_funs(CallGraph, lists:usort(Res++Acc)) 
  -    end.
  -		       
  -get_affected_initials(ReachInfo, {ModName, FunName, Arity}) ->
  -    Initials = lists:filter(fun({_Entry, Receivers}) ->
  -			 lists:member({ModName, FunName, Arity}, Receivers) end, ReachInfo),
  -    lists:map(fun(I) ->
  -		      case I of 
  -			 {{M, F, A, Index, _Def}, _Receivers} ->
  -			       {M, F, A, Index};
  -			  {{M, F, A}, _Receivers} -> 
  -			      {M, F, A}
  -		      end
  -	      end, Initials).
  -   
  -			
  -
  -callgraph(AnnAST, Info, FileName) ->
  -    {AnnAST1,_} = remove_spawn_pars(AnnAST),
  -    CallGraph = build_callgraph(AnnAST1, Info, FileName),
  -    lists:map(fun({{Caller,_CallerDef}, Called})->
  -		      {Caller, Called} end, CallGraph).
  -
  -    
  -build_callgraph(Node, Info, _FileName) ->
  -    {value, {module, ModName}} = lists:keysearch(module, 1, Info),
  -    Inscope_Funs = [{erlang, Fun, Arity} || {Fun, Arity} <- refac_util:auto_imported_bifs()] ++
  -		     refac_util:inscope_funs(Info),  %% NOTE: orders matters here.
  -    HandleSpecialFuns = fun (Arguments, S) ->
  -				case Arguments of
  -				  [F, A] ->
  -				      case {refac_syntax:type(F), refac_syntax:type(A)} of
  -					{atom, list} ->
  -					    FunName = refac_syntax:atom_value(F),
  -					    Arity = refac_syntax:list_length(A),
  -					    ordsets:add_element({ModName, FunName, Arity}, S);
  -					_ -> S
  -				      end;
  -				  [M, F, A] ->
  -				      case {refac_syntax:type(M), refac_syntax:type(F), refac_syntax:type(A)} of
  -					{atom, atom, list} ->
  -					    ModName = refac_syntax:atom_value(M),
  -					    FunName = refac_syntax:atom_value(F),
  -					    Arity = refac_syntax:list_length(A),
  -					    ordsets:add_element({ModName, FunName, Arity}, S);
  -					_ -> S
  -				      end;
  -				  [_N, M, F, A] ->
  -				      case {refac_syntax:type(M), refac_syntax:type(F), refac_syntax:type(A)} of
  -					{atom, atom, list} ->
  -					    ModName = refac_syntax:atom_value(M),
  -					    FunName = refac_syntax:atom_value(F),
  -					    Arity = refac_syntax:list_length(A),
  -					    ordsets:add_element({ModName, FunName, Arity}, S);
  -					_ -> S
  -				      end
  -				end
  -			end,
  -    F2 = fun (T, S) ->
  -		 case refac_syntax:type(T) of
  -		   application ->
  -		       Operator = refac_syntax:application_operator(T),
  -		       Arguments = refac_syntax:application_arguments(T),
  -		       Arity = length(Arguments),
  -		       case refac_syntax:type(Operator) of
  -			 atom ->
  -			     Op = refac_syntax:atom_value(Operator),
  -			     R = lists:filter(fun ({_M, F, A}) -> (F == Op) and (A == Arity) end, Inscope_Funs),
  -			     if R == [] ->
  -				    ordsets:add_element({unknown, Op, Arity},
  -							S);  %% Should we give an error message here?
  -				true ->
  -				    {M, Op, Arity} = hd(R),
  -				    S1 = ordsets:add_element({M, Op, Arity}, S),
  -				    case {Op, Arity} of
  -				      {apply, 2} -> HandleSpecialFuns(Arguments, S1);
  -				      {apply, 3} -> HandleSpecialFuns(Arguments, S1);
  -				      _ -> S1
  -				    end
  -			     end;
  -			 module_qualifier ->
  -			     Mod = refac_syntax:module_qualifier_argument(Operator),
  -			     Body = refac_syntax:module_qualifier_body(Operator),
  -			     case {refac_syntax:type(Mod), refac_syntax:type(Body)} of
  -			       {atom, atom} ->
  -				   Mod1 = refac_syntax:atom_value(Mod),
  -				   Op = refac_syntax:atom_value(Body),
  -				   S1 = ordsets:add_element({Mod1, Op, Arity}, S),
  -				   case {Mod1, Op, Arity} of
  -				     {erlang, apply, 2} -> HandleSpecialFuns(Arguments, S1);
  -				     {erlang, apply, 3} -> HandleSpecialFuns(Arguments, S1);
  -				     _ -> S1
  -				   end;
  -			       _ -> S
  -			     end;
  -			 _ -> S
  -		       end;
  -		   arity_qualifier ->
  -		       Fun = refac_syntax:arity_qualifier_body(T),
  -		       A = refac_syntax:arity_qualifier_argument(T),
  -		       case {refac_syntax:type(Fun), refac_syntax:type(A)} of
  -			 {atom, integer} ->
  -			     FunName = refac_syntax:atom_value(Fun),
  -			     Arity = refac_syntax:integer_value(A),
  -			     ordsets:add_element({ModName, FunName, Arity}, S);
  -			 _ -> S
  -		       end;
  -		   _ -> S
  -		 end
  -	 end,
  -    F1 = fun (T, S) ->
  -		 case refac_syntax:type(T) of
  -		   function ->
  -		       FunName = refac_syntax:data(refac_syntax:function_name(T)),
  -		       Arity = refac_syntax:function_arity(T),
  -		       Caller = {{ModName, FunName, Arity}, T},
  -		       CalledFuns = lists:usort(refac_syntax_lib:fold(F2, [], T)),
  -		       ordsets:add_element({Caller, CalledFuns}, S);
  -		   _ -> S
  -		 end
  -	 end,
  -    lists:usort(refac_syntax_lib:fold(F1, [], Node)).
  -
  -
  -    
  +    end.
  +
  +
  +is_spawn_expr(Tree) ->
  +    SpawnFuns1 = [{erlang, spawn, 1}, {erlang, spawn, 2}, {erlang, spawn, 3}, {erlang, spawn, 4},
  +		  {erlang, spawn_link, 1}, {erlang, spawn_link, 2}, {erlang, spawn_link, 3}, {erlang, spawn_link, 4},
  +		  {erlang, spawn_opt, 3}, {erlang, spawn_opt, 5}],
  +    SpawnFuns2 = [{erlang, spawn_monitor, 1}, {erlang, spawn_monitor, 3}, {erlang, spawn_opt, 2},
  + 		  {erlang, spawn_opt, 4}],  %% These funs return more than a single Pid.
  +    case refac_syntax:type(Tree) of
  +      application ->
  +	  Operator = refac_syntax:application_operator(Tree),
  +	  Ann = refac_syntax:get_ann(Operator),
  +	  case lists:keysearch(fun_def, 1, Ann) of
  +	    {value, {fun_def, {Mod, Fun, Arity, _, _}}} 
  +	      -> lists:member({Mod, Fun, Arity}, SpawnFuns1) orelse 
  +		     lists:member({Mod, Fun, Arity}, SpawnFuns2);
  +	      _ -> false
  +	  end;
  +      _ -> false
  +    end.
  +
  +
  +
  +%% Qn: is it possible to get more static infomration? How to balance the usages of staic and dynamic info?
  +%% How do we know the existing trace info is uptodate?
  +%% what about the spawn expression has receive expressions?
  +
  +%% Is theory, it is possible that a  receiver function is shared by different processes (processse with different 
  +%% entries); it practice, this rarely happen. We ignore this case for now.
  +
  
positive.code: 
  %% ============================================================================================
  %% Refactoring: Instrument the program to trace process communication information.
  %%
  %% Copyright (C) 2006-2008  Huiqing Li, Simon Thompson
  
  
negative.code: %% Author contact: hl@kent.ac.uk, sjt@kent.ac.uk
  %% 
  %% =============================================================================================
  %% Notes: 
  %% 1) The current implementation of this refactoring solely depends on the information inferred
  %% by static analysis, and no trace information is used yet.
  %% 2) To perform this refactoring, selected  a function containing the receive expression, then Wrangler
  %% will prompt the tag name.
  %% 3) limitations:
  %%    a). the current implementation only handles processes spawned using spawn or spawn_link;
  %% =============================================================================================
  -module(refac_add_a_tag).
  
  -export([add_a_tag/5]).
  
  -include("../hrl/wrangler.hrl").
  
  %% =============================================================================================
  -spec(add_a_tag/5::(filename(), integer(), integer(), string(), [dir()]) ->{ok, [filename()]} | {error, string()}).	     
  add_a_tag(FileName, Line, Col, Tag, SearchPaths) ->
      io:format("\n[CMD: add_a_tag, ~p, ~p, ~p, ~p,~p]\n", [FileName, Line, Col, Tag, SearchPaths]),
      case refac_util:parse_annotate_file(FileName, true, SearchPaths) of 
  	{ok, {AnnAST1, _Info1}} ->
  	    case pos_to_receive_fun(AnnAST1, {Line, Col}) of 
  		{ok, _FunDef} ->
  		    _Res=refac_annotate_pid:ann_pid_info(SearchPaths),
  		    {ok, {AnnAST, Info}} = refac_util:parse_annotate_file(FileName, true, SearchPaths),
  		    {ok, FunDef} = pos_to_receive_fun(AnnAST, {Line, Col}),
  		    {value, {module, ModName}} = lists:keysearch(module, 1, Info),
  		    case pre_cond_check(AnnAST,  ModName, FunDef, SearchPaths) of 
  			{ok, AffectedInitialFuns} ->
  			    Results = do_add_a_tag(FileName, {AnnAST, Info}, list_to_atom(Tag), AffectedInitialFuns, SearchPaths),
  			    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;
  		{error, Reason} -> {error, Reason}
  	    end;
  	{error, Reason} -> {error, Reason}
      end.
  	
  
  
  pre_cond_check(_AnnAST, ModName, CurrentFunDef,  SearchPaths) ->
      FunName = refac_syntax:data(refac_syntax:function_name(CurrentFunDef)),
      Arity = refac_syntax:function_arity(CurrentFunDef),
      InitialFuns = collect_process_initial_funs(SearchPaths),
      AffectedInitialFuns = get_affected_initial_funs(InitialFuns, {ModName, FunName, Arity}, SearchPaths),
      io:format("InitialFuns:\n~p\n", [AffectedInitialFuns]),
      case AffectedInitialFuns of 
  	[] -> {error, "Sorry, but Wrangler could not figure out where the process is spawned."};
  	[_H|T]-> case T of 
  		    [] -> {ok, AffectedInitialFuns};
  		    _ ->  case length(lists:usort(lists:map(fun({_InitialFun, ReceiveFuns}) -> ReceiveFuns end, AffectedInitialFuns))) of
  			      1 -> {ok, AffectedInitialFuns};
  			      _ -> {error, "The selected receive function is shared by processes with different set of receive expressions."}
  			  end
  		end
      end.
     
  
  get_affected_initial_funs(InitialFuns, {ModName, FunName, Arity}, SearchPaths) ->
      ReachedReceiveFuns = reached_receive_funs(InitialFuns, SearchPaths),
      io:format("ReachedReceiveFuns:\n~p\n", [ReachedReceiveFuns]),
      lists:filter(fun({_InitialFun, Fs}) ->
  					    lists:member({ModName, FunName, Arity}, Fs) end, ReachedReceiveFuns).
  
  
  collect_process_initial_funs_1({AnnAST, Info}, _SearchPaths) ->  
      {value, {module, ModName}} = lists:keysearch(module, 1, Info),
      HandleSpecialFuns = fun(Node) ->
  				{{Ln, _}, _} = refac_util:get_range(Node),
  				Op = refac_syntax:application_operator(Node),
  				Arguments = refac_syntax:application_arguments(Node),
  				Ann = refac_syntax:get_ann(Op),
  				{value, {fun_def, {erlang, FunName, _Arity, _, _}}}=lists:keysearch(fun_def, 1, Ann),
  				case lists:member(FunName, [spawn, spawn_link]) of 
  				    true ->
  					{value, {pid, PidInfo}} = lists:keysearch(pid, 1, refac_syntax:get_ann(Node)),
  					case Arguments of 
  					    [FunExpr] -> 
  						{PidInfo, {FunExpr, {ModName, Ln}}};   %%Question: what about if the FunExpr contains free variables?
  					    [_N, FunExpr] -> {PidInfo, FunExpr};
  					    [M, F, A] -> 
  						case {refac_syntax:type(M), refac_syntax:type(F), refac_syntax:type(A)} of
  						    {atom, atom, list} ->
  							{PidInfo, {refac_syntax:atom_value(M),   %%TODO: need to use backward slice
  								   refac_syntax:atom_value(F), 
  								   refac_syntax:list_length(A)}};    
  						    _ -> io:format("\n*************************************Warning****************************************\n"),
  							 io:format("Wrangler could not handle the spawn expression used in module ~p at line ~p\n", [ModName,Ln])
  						end;
  					    [_N, M, F, A] ->
  						case {refac_syntax:type(M), refac_syntax:type(F), refac_syntax:type(A)} of
  						    {atom, atom, list} ->
  							{PidInfo, {refac_syntax:atom_value(M),   %%TODO: need to use backward slice
  								   refac_syntax:atom_value(F), 
  								   refac_syntax:list_length(A)}};    
  						    _ -> io:format("\n*************************************Warning****************************************\n"),
  							 io:format("Wrangler could not handle the spawn expression used in module ~p at line ~p\n", [ModName,Ln])
  						end
  					    end;
  				    _ ->
  					io:format("\n*************************************Warning****************************************\n"),
  					io:format("Wrangler could not handle the spawn expression used in module ~p at line ~p\n", [ModName,Ln]),
  					[]   
  				end
  			end, 
      Fun= fun(Node, Acc) ->			       
  		 case refac_syntax:type(Node) of 
  		     function ->
  			 F = fun(T, S) ->
  				     case is_spawn_expr(T) of 
  					 true -> [HandleSpecialFuns(T)|S];
  					 _ -> S
  				     end
  			     end,
  			 Res = refac_syntax_lib:fold(F, [],  Node),
  			 lists:usort(Res ++ Acc);
  		     _ -> Acc
  		 end
  	 end,
      refac_syntax_lib:fold(Fun, [], AnnAST).
  		 
  do_add_a_tag(FileName, {AnnAST, Info}, Tag, AffectedInitialFuns, SearchPaths) ->
      {value, {module, ModName}} = lists:keysearch(module, 1, Info),
      {InitialFuns1, ReceiveFuns1} = lists:unzip(AffectedInitialFuns),
      InitialFuns = lists:usort(lists:flatmap(fun({Init, _}) -> Init end, InitialFuns1)),
      ReceiveFuns = lists:usort(lists:append(ReceiveFuns1)),
      io:format("The current file under refactoring is:\n~p\n", [FileName]),
      {AnnAST1, _Changed} =refac_util:stop_tdTP(fun do_add_a_tag_1/2, AnnAST, {ModName, Tag, InitialFuns, ReceiveFuns}),
      OtherFiles = refac_util:expand_files(SearchPaths, ".erl") -- [FileName],
      Results = do_add_a_tag_in_other_modules(OtherFiles, Tag, InitialFuns, ReceiveFuns, SearchPaths),    
      [{{FileName, FileName}, AnnAST1} | Results].
  
  do_add_a_tag_in_other_modules(Files, Tag, InitialFuns, ReceiveFuns, SearchPaths) ->
      case Files of
  	[] ->
  	    [];
  	[F |Fs] ->
  	    io:format("The current file under refactoring is:\n~p\n", [F]),
  	    {ok, {AnnAST, Info}} = refac_util:parse_annotate_file(F, true, SearchPaths),
  	    {value, {module, ModName}} = lists:keysearch(module, 1, Info),
  	    {AnnAST1, Changed} = refac_util:stop_tdTP(fun do_add_a_tag_1/2, AnnAST, {ModName, Tag, InitialFuns, ReceiveFuns}),
  	    if Changed ->
  		    [{{F, F}, AnnAST1} | do_add_a_tag_in_other_modules(Fs, Tag, InitialFuns, ReceiveFuns, SearchPaths)];
  		true -> do_add_a_tag_in_other_modules(Fs, Tag, InitialFuns, ReceiveFuns, SearchPaths)
  	    end
      end.
  do_add_a_tag_1(Node, {ModName,Tag, InitialFuns, ReceiveFuns}) ->
      case refac_syntax:type(Node) of 
  	function ->
  	    {value, {fun_def, {M, F, A, _, _}}} = lists:keysearch(fun_def,1, refac_syntax:get_ann(Node)),
  	    case lists:member({M, F, A}, ReceiveFuns) of 
  		true ->
  		    Node1 = refac_util:full_buTP(fun do_add_tag_to_receive_exprs/2, Node,  Tag),
  		    {Node2, _} = refac_util:stop_tdTP(fun do_add_tag_to_send_exprs/2, Node1, {ModName,Tag, InitialFuns}),
  		    {Node2, true};
  		false ->
  		   refac_util:stop_tdTP(fun do_add_tag_to_send_exprs/2, Node, {ModName, Tag, InitialFuns})
  	    end;
  	_ ->
  	    {Node, false}
      end.
  
  do_add_tag_to_receive_exprs(Node, Tag) ->
      F = fun(C) ->
  		P = refac_util:ghead("do_add_tag_to_receive_exprs", refac_syntax:clause_patterns(C)), %%
  		G = refac_syntax:clause_guard(C),
  		B = refac_syntax:clause_body(C),
  		P1 =case refac_syntax:type(P) of 
  			tuple ->
  			    Es = [refac_syntax:atom(Tag)| refac_syntax:tuple_elements(P)],
  			    refac_syntax:tuple(Es);
  			_-> refac_syntax:tuple([refac_syntax:atom(Tag), P])
  		    end,		
  		refac_syntax:copy_attrs(C, refac_syntax:clause([P1], G, B))
  	end,	
      case refac_syntax:type(Node) of 
  	receive_expr ->
  	    Cs = refac_syntax:receive_expr_clauses(Node),
  	    Cs1 = lists:map(F, Cs),
  	    refac_syntax:copy_attrs(Node, refac_syntax:receive_expr(Cs1));
  	_ -> Node
      end.
  
  do_add_tag_to_send_exprs(Node, {ModName, Tag, AffectedInitialFuns}) ->
       case refac_syntax:type(Node) of
  	infix_expr ->
  	    case is_send_expr(Node) of 
  		true ->{{Ln, _},_} = refac_util:get_range(Node), 
  		        Dest = refac_syntax:infix_expr_left(Node),
  			Msg = refac_syntax:infix_expr_right(Node),
  			Ann = refac_syntax:get_ann(Dest),
  			Op  = refac_syntax:infix_expr_operator(Node),
  			InitialFuns = case lists:keysearch(pid,1, Ann) of 
  					  {value, {pid, InitialFuns1}} ->
  					      InitialFuns1;
  					  _ -> case lists:keysearch(pname, 1, Ann) of 
  						   {value, {pname, InitialFuns2}} ->
  						       InitialFuns2;
  						   _ -> []
  					       end
  				      end,						   
  			case InitialFuns of 
  			    [] -> io:format("\n*************************************Warning****************************************\n"),
  				  io:format("Wrangler could not identify the recipent process of the send expression in module ~p at line ~p\n", [ModName,Ln]),
  				{Node, false};
  			    _ -> case InitialFuns -- AffectedInitialFuns of 
  				     [] ->
  					 Msg1 = case refac_syntax:type(Msg) of 
  						    tuple ->
  							refac_syntax:tuple([refac_syntax:atom(Tag) | refac_syntax:tuple_elements(Msg)]);
  						    _ -> refac_syntax:tuple([refac_syntax:atom(Tag), Msg])
  						end,
  					 Node1 = refac_syntax:copy_attrs(Node, refac_syntax:infix_expr(Dest, Op, Msg1)), 
  					 {Node1, true};
  				     InitialFuns -> 
  					 {Node, false};  
  				     _ -> %% io:format("\n*************************************Warning****************************************\n"),
  %% 					  io:format("The recipent process of the send expression in module ~p at line ~p could refer to multiple processes. \n", [ModName,Ln]),
  					  {Node, false}
  				 end
  			end;
  		_ -> {Node, false}
  	    end;
  	application ->
  	    case is_send_expr(Node) of 
  		true -> [ReceiverPid, Msg] = refac_syntax:application_arguments(Node),
  			Operator = refac_syntax:application_operator(Node),
  			Ann = refac_syntax:get_ann(ReceiverPid),
  			case lists:keysearch(pid,1, Ann) of 
  			    {value, {pid, InitialFuns}} ->
  				io:format("IntialFuns:\n~p\n", [InitialFuns]),
  				case InitialFuns of 
  				    [] -> {Node, false};
  				    _ -> case InitialFuns -- AffectedInitialFuns of 
  					     [] ->
  						 Msg1 = case refac_syntax:type(Msg) of 
  							    tuple ->
  								refac_syntax:tuple([Tag | refac_syntax:tuple_elements(Msg)]);
  							    _ -> refac_syntax:tuple([Tag, Msg])
  							end,
  						 Node1 = refac_syntax:copy_attrs(Node, refac_syntax:application(Operator, [ReceiverPid, Msg1])), 
  						 {Node1, true};
  					     InitialFuns -> 
  						 {Node, false};
  					     _ -> io:format("Node:\n~p\n", [Node]),%% TODO: Undicidables;
  						  {Node, false}
  					 end
  				end;
  			    _ -> {Node, false}  %%TODO: undicicabels.
  			end;	
  		false -> {Node, false}
  	    end;	
  	_ -> {Node, false}
      end.
  				
  		    
  pos_to_receive_fun(AnnAST, Pos) ->
      case refac_util:pos_to_fun_def(AnnAST, Pos) of 
  	{ok, FunDef} ->
  	    case has_receive_expr(FunDef) of 
  		true -> {ok, FunDef};
  		_ -> {error, "You have not selected a receive expression!"}
  	    end;	    
  	_  -> {error, "You have not selected a receive expression!"}
      end.
  
  has_receive_expr(Node) ->
      case refac_util:once_tdTU(fun has_receive_expr/2, Node, []) of 
  	{_, false} ->
  	     false;
  	{_R, true} -> true
      end.
  
  has_receive_expr(Node, []) ->
      case refac_syntax:type(Node) of 
  	receive_expr ->
  	    {Node, true};
  	_  ->{[], false}
      end.
  
  
  
  collect_process_initial_funs(SearchPaths) ->
      Files = refac_util:expand_files(SearchPaths, ".erl"),
      lists:flatmap(fun(F)-> {ok, {AnnAST, Info}} = refac_util:parse_annotate_file(F, true, SearchPaths),
  			   collect_process_initial_funs_1({AnnAST, Info}, SearchPaths)
  		  end, Files).
  			  
  collect_fun_apps(Expr, {ModName, Ln}) ->
      Fun = fun (T, S) ->
  		 case refac_syntax:type(T) of
  		     application ->
  			 Operator = refac_syntax:application_operator(T),
  			 case lists:keysearch(fun_def,1,refac_syntax:get_ann(Operator)) of
  			     {value, {fun_def, {M, F, A, _, _}}}-> lists:keysearch(fun_def,1, refac_syntax:get_ann(Operator)),
  								   ordsets:add_element({M,F, A},S);
  			     
  			     _ -> io:format("\n*************************************Warning****************************************\n"),
  				  io:format("Wrangler could not handle the spawn expression used in module ~p at line ~p\n", [ModName,Ln])
  			 end;
  		     arity_qualifier -> 
  			 {value, {fun_def, {M, F, A, _, _}}} = lists:keysearch(fun_def,1, refac_syntax:get_ann(T)),
  			 ordsets:add_element({M,F,A}, S);
  		     _ -> S
  		 end
  	  end,
      lists:usort(refac_syntax_lib:fold(Fun, [], Expr)). 
      
  
  get_fun_def({M, F, A}, SearchPaths) ->  
      Fun=fun(Node, {M1, F1, A1}) ->
  	      case refac_syntax:type(Node) of
  		  function ->
  		      Ann  = refac_syntax:get_ann(Node),
  		      case lists:keysearch(fun_def,1, Ann) of 
  			  {value, {fun_def, {M1,F1, A1, _, _}}} ->
  			      {Node, true};
  			  _ -> {[], false}
  		      end;
  		  _ -> {[], false}
  	      end
        end,		      
      Files =refac_util:expand_files(SearchPaths, ".erl"),
      FileNames =lists:filter(fun(F1) -> list_to_atom(filename:basename(F1, ".erl"))==M end, Files),
      case FileNames of 
  	[] ->
  	     {error, no_source_file};
  	_ ->
  	    FileName = hd(FileNames),
  	    {ok, {AnnAST, _Info}} = refac_util:parse_annotate_file(FileName, true, SearchPaths),
  	    case refac_util:once_tdTU(Fun, AnnAST, {M, F, A}) of 
  		{_, false} ->
  		    {error, "Wrangler could not find the definition of "++ atom_to_list(M)++":"++atom_to_list(F)++"/"++integer_to_list(A)};
  		{R, true} -> {ok, R}
  	    end
      end.     
  
  
  reached_receive_funs([], _SearchPaths) -> [];
  reached_receive_funs(InitialFuns, SearchPaths) ->
      F  = fun(InitialFun) ->
   		 case InitialFun of 
   		     {Mod, Fun, Arity} -> [{Mod,Fun, Arity}];
   		     {FunExpr, {ModName, Ln}} -> collect_fun_apps(FunExpr, {ModName, Ln})
  		 end
  	 end,	
      {CallerCallee, _, _} = refac_callgraph_server:get_callgraph(SearchPaths),  %% should remove spawn pars before calcuate callgraph.
      ReachedFuns = lists:zip(InitialFuns, lists:map(fun({_SpawnExpr, InitialF}) -> 
  							   reached_receive_funs_1(CallerCallee, F(InitialF), SearchPaths) end, 
  						   InitialFuns)),
      ReachedFuns.
     
  
  reached_receive_funs_1(CallerCallee, InitialAcc, SearchPaths) ->
      io:format("InitialAcc:\n~p\n", [InitialAcc]),
      Funs =reached_funs_1(CallerCallee, InitialAcc),
      io:format("Funs:\n~p\n", [Funs]),
      ReceiveFuns = lists:filter(fun(MFA) ->
  				      case get_fun_def(MFA, SearchPaths) of 
  					  {error, no_source_file} -> false;
  					  {error, Reason} ->erlang:exit(Reason);
  					  {ok, FunDef} -> has_receive_expr(FunDef)
  				      end
  			       end, Funs),
      ReceiveFuns.
  			       
  
  reached_funs_1(CallerCallee, Acc) ->
      Res = lists:usort(lists:concat(lists:map(fun({Mod, Fun, Args}) ->
  					 case lists:keysearch({Mod, Fun, Args}, 1, CallerCallee) of 
  					     {value, {{Mod, Fun, Args}, CalledFuns}} ->
  						 CalledFuns;
  					     _ ->[]
  					 end
  				 end, Acc))),
       case lists:usort(Res++Acc) == Acc of 
  	true -> Res;
  	_ -> reached_funs_1(CallerCallee, lists:usort(Res++Acc)) 
      end.
  		       
     
  is_send_expr(Tree) ->
      case refac_syntax:type(Tree) of 
  	infix_expr ->
  