<commit_before>-module(new_fun).

-behaviour(gen_refac).

-export([input_pars/0, select_focus/1, 
         pre_cond_check/1, selective/0,
         transform/1]).

-include("../include/gen_refac.hrl").

%% The Emacs mini-buffer prompts for the user input parameters. 
-spec (input_pars/0::() -> [string()]).                           
input_pars()->
    ["New function name:"].

%% Select the focus of interest. If no selection is neeeded, 
%% then return {ok, none}.
-spec (select_focus/1::(#args{}) -> {ok, syntaxTree()}|{ok, none}).  
                           
select_focus(Args=#args{current_file_name=File}) ->
    Sel =interface_api:pos_to_expr_list(File, Args#args.highlight_range),
    {ok, Sel}.

%% Pre-condition checking to ensure that the refactoring preserves the 
%% behaviour of the program.
-spec (pre_cond_check/1::(#args{}) -> ok).  
pre_cond_check(_Args=#args{current_file_name=File, focus_sel=Exprs, 
                          user_inputs=[NewFunName]}) ->
    check_selection(Exprs),
    check_function_name(NewFunName),    
    check_name_conflict(File, Exprs, list_to_atom(NewFunName)),
    check_funcall_replaceable(Exprs).
   

check_selection(Exprs) when Exprs==[] ->
    throw({error, "You have not selected any expressions"});
check_selection(_Exprs) ->
    ok.

check_function_name(NewFunName) ->
    case refac_api:is_fun_name(NewFunName) of 
        true ->
            ok;
        false ->
            throw({error, "Invalide function name!"})<commit_msg>renamed some callback functions following the changes made to gen_refac.<commit_after>-module(new_fun).

-behaviour(gen_refac).

-export([input_par_prompts/0, select_focus/1,
         check_pre_cond/1, selective/0,
         transform/1]).

-include("../include/wrangler.hrl").

%% The Emacs mini-buffer prompts for the user input parameters. 
-spec (input_par_prompts/0::() -> [string()]).                           
input_par_prompts() ->
    ["New function name:"].

%% Select the focus of interest. If no selection is neeeded, 
%% then return {ok, none}.
-spec (select_focus/1::(#args{}) -> {ok, syntaxTree()}|{ok, none}).  
                           
select_focus(Args=#args{current_file_name=File}) ->
    Sel =interface_api:pos_to_expr_list(File, Args#args.highlight_range),
    {ok, Sel}.

%% Pre-condition checking to ensure that the refactoring preserves the 
%% behaviour of the program.
-spec (check_pre_cond/1::(#args{}) -> ok).  
check_pre_cond(_Args=#args{current_file_name=File, focus_sel=Exprs,
                          user_inputs=[NewFunName]}) ->
    check_selection(Exprs),
    check_function_name(NewFunName),    
    check_name_conflict(File, Exprs, list_to_atom(NewFunName)),
    check_funcall_replaceable(Exprs).
   

check_selection(Exprs) when Exprs==[] ->
    throw({error, "You have not selected any expressions"});
check_selection(_Exprs) ->
    ok.

check_function_name(NewFunName) ->
    case refac_api:is_fun_name(NewFunName) of 
        true ->
            ok;
        false ->
            throw({error, "Invalide function name!"})
{'fraction_non_alphanumeric': 0.13916175507531106, 'fraction_numerical': 0.005239030779305829, 'mean_word_length': 3.1283783783783785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2706498', 'n_tokens_mistral': 1007, 'n_tokens_neox': 982, 'n_words': 202}