Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 08, 2011
@alipiec Add functionality needed by eclipse integration
- API for handling user-defined refactorings
- extend run refactoring by adding 'Editor' parameter
- functions that enable loading new refactoring modules onto internal node
e33f21b
@alipiec Remove '[]' from SearchPath argument b866026
View
21 src/gen_refac.erl
@@ -132,6 +132,7 @@
-module(gen_refac).
-export([run_refac/2,
+ run_refac/3,
input_par_prompts/1,
apply_changes/3
]).
@@ -207,10 +208,19 @@ apply_changes(Module, Args, CandsNotToChange) ->
-spec(run_refac(Module::module()|string()|tuple(), Args::[term()])->
{ok, string()} | {change_set, [{string(), string()}], module(), #args{}}|
{error, term()}).
+run_refac(ModName, Args) ->
+ run_refac(ModName, Args, emacs).
+
+%%@doc The interface function for invoking a refactoring defined
+%% in module `ModName'.
+-spec(run_refac(Module::module()|string()|tuple(), Args::[term()], Editor::atom())->
+ {ok, string()} | {ok, [{filename(), filename(), string()}]} |
+ {change_set, [{string(), string()}], module(), #args{}}|
+ {error, term()}).
run_refac(ModName, Args=[CurFileName, [Line,Col],
[[StartLine, StartCol],
[EndLn, EndCol]], UserInputs,
- SearchPaths, TabWidth]) ->
+ SearchPaths, TabWidth], Editor) ->
?wrangler_io("\nCMD: ~p:run_refac(~p,~p).\n",
[?MODULE, ModName, Args]),
Module = if is_list(ModName) ->
@@ -230,7 +240,12 @@ run_refac(ModName, Args=[CurFileName, [Line,Col],
Args1 = Args0#args{focus_sel=Sel},
case check_pre_cond(Module, Args1) of
ok ->
- Selective=selective(Module),
+ Selective = case Editor of
+ eclipse ->
+ false;
+ _ ->
+ selective(Module)
+ end,
wrangler_gen_refac_server:set_flag({self(), Selective}),
Args2 = Args1#args{selective=Selective},
if is_boolean(Selective) ->
@@ -248,7 +263,7 @@ run_refac(ModName, Args=[CurFileName, [Line,Col],
case apply(Module, transform, [Args2]) of
{ok, Res} ->
wrangler_gen_refac_server:delete_flag(self()),
- wrangler_write_file:write_refactored_files(Res,emacs,TabWidth,"");
+ wrangler_write_file:write_refactored_files(Res,Editor,TabWidth,"");
{error, Reason} ->
wrangler_gen_refac_server:delete_flag(self()),
{error, Reason}
View
2 src/gen_refacs/refac_apply_to_remote_call.erl
@@ -34,7 +34,7 @@ transform(_Args=#args{search_paths=SearchPaths})->
?FULL_TD_TP([rule(),
rule1(),
rule2()
- ], [SearchPaths]).
+ ], SearchPaths).
rule() ->
?RULE(?T("Op@(N@@, M@, F@, [Args@@])"),
View
2 src/gen_refacs/refac_keysearch_to_keyfind.erl
@@ -32,7 +32,7 @@ selective() ->
-spec (transform/1::(#args{}) -> {ok, [{filename(), filename(), syntaxTree()}]}).
transform(_Args=#args{search_paths=SearchPaths})->
- ?STOP_TD_TP([rule_keysearch_to_keyfind()], [SearchPaths]).
+ ?STOP_TD_TP([rule_keysearch_to_keyfind()], SearchPaths).
rule_keysearch_to_keyfind() ->
?RULE(?T("case lists:keysearch(Key@, N@, TupleList@) of
View
128 src/wrangler_refacs.erl
@@ -123,7 +123,12 @@
gen_fsm_to_record_eclipse/3,gen_fsm_to_record_1_eclipse/7,
partition_exports_eclipse/4, intro_new_var_eclipse/6,
inline_var_eclipse/5, inline_var_eclipse_1/6,
- get_var_name_eclipse/5, get_fun_name_eclipse/5
+ get_var_name_eclipse/5, get_fun_name_eclipse/5,
+ run_refac_eclipse/2, input_par_prompts_eclipse/1,
+ apply_changes_eclipse/3, load_callback_mod_eclipse/2,
+ input_par_prompts_c_eclipse/1, init_composite_refac_eclipse/2,
+ get_next_command_eclipse/1,
+ get_user_refactorings/1, load_user_refactorings/1
]).
-export([try_refac/3, get_log_msg/0]).
@@ -135,6 +140,127 @@
-type(context():: emacs | composite_emacs).
%% ====================================================================================================
+%% @doc get all user refactoring modules (gen_refac and gen_composite_refac)
+
+get_user_refactorings(Modules) ->
+ Refacs = lists:foldl(fun(Module, Acc) ->
+ Attrs = proplists:get_value(attributes, apply(list_to_atom(Module), module_info, [])),
+ Behs = case proplists:get_value(behaviour, Attrs) of
+ undefined ->
+ case proplists:get_value(behavior, Attrs) of
+ undefined ->
+ undefined;
+ Beh ->
+ Beh
+ end;
+ Beh ->
+ Beh
+ end,
+ case Behs of
+ undefined ->
+ Acc;
+ _ ->
+ case { lists:member(gen_refac, Behs), lists:member(gen_composite_refac, Behs)} of
+ {true, _} ->
+ [{gen_refac, list_to_atom(Module)} |Acc];
+ {_, true} ->
+ [{gen_composite_refac, list_to_atom(Module)} | Acc];
+ _ ->
+ Acc
+ end
+ end
+ end, [], Modules),
+ [{gen_refac, proplists:append_values(gen_refac, Refacs)},
+ {gen_composite_refac, proplists:append_values(gen_composite_refac, Refacs)}].
+
+
+%% ====================================================================================================
+%% @doc gen_refac refactorings - delegate functions in order to achieve more clear API (especially for Eclipse)
+-spec(apply_changes_eclipse(Module::module(), Args::[term()], CandsNotToChange::[term()]) ->
+ {ok, [{filename(), filename(), syntaxTree()}]} |
+ {error, term()}).
+apply_changes_eclipse(Module, Args, CandsNotToChange) ->
+ gen_refac:apply_changes(Module, Args, CandsNotToChange).
+
+-spec(run_refac_eclipse(Module::module()|string()|tuple(), Args::[term()])->
+ {ok, string()} | {change_set, [{string(), string()}], module(), tuple()}|
+ {error, term()}).
+run_refac_eclipse(ModName, Args) ->
+ gen_refac:run_refac(ModName,Args, eclipse).
+
+-spec(input_par_prompts_eclipse(CallBackMod::module()) -> [string()]).
+input_par_prompts_eclipse(CallBackMod) ->
+ gen_refac:input_par_prompts(CallBackMod).
+
+%% ====================================================================================================
+%% @doc gen_composite_refac refactorings - delegate functions in order to achieve more clear API (especially for Eclipse)
+-spec(input_par_prompts_c_eclipse(CallBackMod::module()) -> [string()]).
+input_par_prompts_c_eclipse(CallBackMod) ->
+ gen_composite_refac:input_par_prompts(CallBackMod).
+
+-spec(init_composite_refac_eclipse(Module::module()|string()|tuple(), Args::[term()])->
+ {ok,pid()} | ignore |{error, term()}).
+init_composite_refac_eclipse(ModName, Args) ->
+ gen_composite_refac:init_composite_refac(ModName, Args).
+
+get_next_command_eclipse(PrevResult) ->
+ case gen_composite_refac:get_next_command(PrevResult) of
+ {ok, none, _ChangedFiles, [error, Reason]} ->
+ %revert buffers
+ {error, io_lib:format("Composite refactoring failed: %s", Reason)};
+ {ok, none, ChangedFiles, _Msg} ->
+ {ok, ChangedFiles}; % do sth with them
+ {ok, Command} ->
+ {next, Command};
+ {error, Reason} ->
+ {error, io_lib:format("Refactoring failed: %s", Reason)};
+ {badrpc, Reason} ->
+ {error, io_lib:format("Refactoring failed: %s", Reason)};
+ Reasult ->
+ {error, io_lib:format("Unexpectedd result: %s", Reasult)}
+ end.
+
+
+%% ====================================================================================================
+%% @doc user defined refactorings - common
+%%
+%% @doc load new callback module (ad hoc refactorings)
+-spec(load_callback_mod_eclipse(Module::module(), Path::string()) ->
+ ok | {error, Reason::term()}).
+load_callback_mod_eclipse(Module, Path) ->
+ code:add_patha(Path),
+ code:purge(list_to_atom(Module)),
+ case code:load_file(list_to_atom(Module)) of
+ {module, Module} ->
+ ok;
+ Error ->
+ Error
+ end.
+
+%% @doc load user's own refactorings from my_gen_refac
+-spec(load_user_refactorings(Path::string()) -> ok).
+load_user_refactorings(Path) ->
+ MyRefacs = filename:join(Path, "my_gen_refac"),
+ MyCRefacs = filename:join(Path, "my_gen_composite_refac"),
+ code:add_patha(MyRefacs),
+ code:add_patha(MyCRefacs),
+ load_from_dir(MyRefacs),
+ load_from_dir(MyCRefacs),
+ [MyRefacs, MyCRefacs].
+
+-spec(load_from_dir(Dir::string()) -> ok).
+load_from_dir(Dir) ->
+ case file:list_dir(Dir) of
+ {ok, Filenames} ->
+ lists:foreach(fun(Name) ->
+ code:load_file(list_to_atom(filename:basename(Name, ".beam")))
+ end, Filenames);
+ _ ->
+ ok
+ end.
+
+
+%% ====================================================================================================
%% @doc Rename a variable.
%% <p> This refactoring has a local effect, i.e., it only affects the function clause in which the refactoring is initialized.
%% </p>

No commit comments for this range

Something went wrong with that request. Please try again.