// ******@Uses: This is a small visitor created to extract variable name and
  // count****************//
  // *********************** from a given try block ********************************************//
  // ***********************************************************************************************//
  public void VariableVisitor_try(String content) {
    ASTParser metparse = ASTParser.newParser(AST.JLS3);
    metparse.setSource(content.toCharArray());
    metparse.setKind(ASTParser.K_STATEMENTS);
    Block block = (Block) metparse.createAST(null);

    block.accept(
        new ASTVisitor() {
          public boolean visit(VariableDeclarationFragment var) {
            // debug("met.var", var.getName().getFullyQualifiedName());
            variables_in_try = variables_in_try + " " + var.getName().getFullyQualifiedName();
            variables_count_try = variables_count_try + 1;

            System.out.println("Vriables in try:" + variables_in_try);
            // interupt();
            return true;
          }
        });
  }
  public void methodVisitor(String content) {
    ASTParser metparse = ASTParser.newParser(AST.JLS3);
    metparse.setSource(content.toCharArray());
    metparse.setKind(ASTParser.K_STATEMENTS);
    Block block = (Block) metparse.createAST(null);

    block.accept(
        new ASTVisitor() {
          public boolean visit(VariableDeclarationFragment var) {
            // debug("met.var", var.getName().getFullyQualifiedName());
            // System.out.println("dec");
            return true;
          }

          public boolean visit(SimpleName node) {
            // System.out.println(" Simple Node="+node.toString());
            // System.out.println("Node");
            return true;
          }

          public boolean visit(ForStatement myfor) {
            // System.out.println("myfor="+myfor.toString());
            // System.out.println("for");
            return true;
          }

          public boolean visit(SwitchStatement myswitch) {
            // System.out.println("myswitch="+myswitch.toString());
            return true;
          }

          public boolean visit(DoStatement mydo) {
            // System.out.println("mydo="+mydo.toString());
            return true;
          }

          public boolean visit(WhileStatement mywhile) {
            // System.out.println("mywhile="+mywhile.toString());
            return true;
          }

          public boolean visit(IfStatement myif) {

            return true;
          }

          public boolean visit(TryStatement mytry) {
            reset_try_flags();
            util3_met utm = new util3_met();
            log_level_interface tli = new log_level_interface();
            method_name_and_count mnc_try = new method_name_and_count();
            operator_and_operator_count oaoc_try = new operator_and_operator_count();

            // object for method
            method_name_and_count mnc_till_try = new method_name_and_count();
            operator_and_operator_count oaoc_till_try = new operator_and_operator_count();
            log_level_interface tli_till_try = new log_level_interface();

            try_id++;
            catch_id = 0;

            // Contextualfeaturess
            is_method_have_param = utm.check_method_parameter(method_parameter);
            method_param_as_string_original = method_parameter.toString();
            method_param_as_string_original =
                utm.replace_quotes_string(method_param_as_string_original);
            method_param_as_string = method_param_as_string_original;
            method_param_as_string = utm.clean_method_params(method_param_as_string);
            method_param_count = utm.get_param_count(method_parameter);

            method_param_type = utm.get_method_param_type(method_parameter);
            method_param_type = utm.clean_method_params(method_param_type);

            method_param_name = utm.get_method_param_name(method_parameter);
            method_param_name = utm.clean_method_params(method_param_name);

            String try_con = mytry.getBody().toString();
            /*try_con = try_con.replace("\"", "\\\"");
            try_con= try_con.replace("\'", " ");
            try_con = try_con.replace("\\\\", " ");*/

            /*try_con = try_con.replace("\"", " ");
            try_con= try_con.replace("\'", " ");
            try_con = try_con.replace("\\", " "); */
            System.out.println("Content of Try Block=" + try_con.toString());

            //	try_loc = utm.get_try_loc_count(try_con);// old method @not comment
            try_loc = utm.get_new_try_sloc(try_con);

            tli = utm.find_and_set_logging_level(try_con, tli);
            is_try_logged = tli.logged;
            try_log_count = tli.log_count;
            try_log_levels = tli.log_levels_combined;
            is_return_in_try = utm.check_return(try_con);
            is_thread_sleep_try = utm.check_thread_sleep(try_con);
            throw_throws_try = utm.check_thorw_throws(try_con);
            if_in_try = utm.check_if(try_con);
            if_count_in_try = utm.get_if_count(try_con);
            is_assert_try = utm.check_assert(try_con);

            mnc_try = utm.get_method_call_name(try_con, mnc_try);
            method_call_names_try = mnc_try.method_names;
            method_call_count_try = mnc_try.method_count;

            oaoc_try = utm.get_operators_and_count(try_con, oaoc_try);
            operators_in_try = oaoc_try.operator;
            operators_count_try = oaoc_try.operator_count;

            // @Uses: This function will use to count the variable names in the try block
            // *** This will set following varibels in the block  //
            // *** Variables_in_try =
            // **  variables_count_try =           //
            VariableVisitor_try(try_con);

            // @******Features between method and try************@//

            // interupt();
            int try_pos = mytry.getStartPosition();

            String method_try_between_con = method_content.substring(0, try_pos);
            method_try_between_con = method_try_between_con.trim();
            method_try_between_con = utm.balance_closing_braces(method_try_between_con);

            // System.out.println("method  con:"+ method_content);

            // System.out.println("method between try con:"+ method_try_between_con);

            String modified_con_for_method_call_ext =
                utm.get_modified_con_for_method_cal_extraction(method_content, try_pos);
            mnc_till_try = utm.get_method_call_name(modified_con_for_method_call_ext, mnc_till_try);
            method_call_names_till_try = mnc_till_try.method_names;
            method_call_count_till_try = mnc_till_try.method_count;

            oaoc_till_try = utm.get_operators_and_count(method_try_between_con, oaoc_till_try);
            operators_till_try = oaoc_till_try.operator;
            operators_count_till_try = oaoc_till_try.operator_count;

            // @Uses: This function will use to count the variable names in the given block between
            // method and try
            // *** This will set following varibels in the block  //
            // *** Variables_till_try =
            // **  variables_count_till_try =           //
            VariableVisitor_method_try_between_con(method_try_between_con);

            loc_till_try = utm.get_loc(method_try_between_con);
            tli_till_try = utm.find_and_set_logging_level(method_try_between_con, tli_till_try);
            is_till_try_logged = tli_till_try.logged;
            till_try_log_count = tli_till_try.log_count;
            till_try_log_levels = tli_till_try.log_levels_combined;
            is_return_till_try = utm.check_return(method_try_between_con);
            throw_throws_till_try = utm.check_thorw_throws(method_try_between_con);
            if_in_till_try = utm.check_if(method_try_between_con);
            if_count_in_till_try = utm.get_if_count(method_try_between_con);
            is_assert_till_try = utm.check_assert(method_try_between_con);

            String previous_catch_as_string = "";
            List all_catches = mytry.catchClauses();
            Iterator itr = all_catches.iterator();

            int count = 0;

            while (itr.hasNext()) {

              log_level_interface catch_li = new log_level_interface();
              catch_id++;
              reset_catch_flags();
              CatchClause mycatch = (CatchClause) all_catches.get(count);

              String catch_exp = mycatch.getException().getType().toString();
              catch_exp = catch_exp.replace("\"", "\\\"");
              catch_exp = catch_exp.replace("\'", " ");
              catch_exp = catch_exp.replace("\\\\", " ");
              catch_exp = utm.find_final_catch_exp(catch_exp);

              String catch_exp_with_obj = mycatch.getException().toString();

              String catch_con = mycatch.getBody().toString();
              // catch_con = catch_con.replace("\"", "\\\"");
              // catch_con = catch_con.replace("\'", "\\\'");
              // catch_con = catch_con.replace("\\\\", " ");

              System.out.println("---------Set Flags----------------------");
              catch_li = utm.find_and_set_logging_level(catch_con, catch_li);
              is_catch_logged = catch_li.logged;
              catch_log_count = catch_li.log_count;
              catch_log_levels = catch_li.log_levels_combined;
              have_previous_catches = utm.contains_previous_catches(count);
              previous_catches_logged =
                  utm.are_previous_catches_logged(previous_catch_as_string, count);
              previous_catches_log_count = utm.get_log_count(previous_catch_as_string);
              is_return_in_catch = utm.check_return(catch_con);
              catch_depth = utm.get_catch_depth(count);
              is_catch_object_ignore = utm.check_ignore(catch_exp_with_obj);
              is_interrupted_exception = utm.check_interrupted_exception(catch_exp);
              is_throwable_exception = utm.check_throwable_exception(catch_exp);
              throw_throws_catch = utm.check_thorw_throws(catch_con);
              is_assert_catch = utm.check_assert(catch_con);

              System.out.println("Method Name=" + method_name);
              System.out.println("Package Name=" + package_name);
              System.out.println("File Path=" + temp_file_path);
              System.out.println("Catch Exception=" + catch_exp);

              write_in_db(
                  try_id,
                  catch_id,
                  try_con,
                  catch_con,
                  method_try_between_con,
                  catch_exp.toString(),
                  previous_catch_as_string,
                  temp_file_path,
                  package_name,
                  class_name,
                  method_name,
                  try_loc,
                  is_try_logged,
                  try_log_count,
                  try_log_levels,
                  is_catch_logged,
                  catch_log_count,
                  catch_log_levels,
                  have_previous_catches,
                  previous_catches_logged,
                  is_return_in_try,
                  is_return_in_catch,
                  is_catch_object_ignore,
                  is_interrupted_exception,
                  is_thread_sleep_try,
                  throw_throws_try,
                  throw_throws_catch,
                  if_in_try,
                  if_count_in_try,
                  is_assert_try,
                  is_assert_catch,
                  previous_catches_log_count,
                  catch_depth,
                  is_method_have_param,
                  method_param_as_string_original,
                  method_param_as_string,
                  method_param_type,
                  method_param_name,
                  method_param_count,
                  method_call_names_try,
                  method_call_count_try,
                  operators_in_try,
                  operators_count_try,
                  variables_in_try,
                  variables_count_try,
                  method_call_names_till_try,
                  method_call_count_till_try,
                  operators_till_try,
                  operators_count_till_try,
                  variables_till_try,
                  variables_count_till_try,
                  loc_till_try,
                  is_till_try_logged,
                  till_try_log_count,
                  till_try_log_levels,
                  is_return_till_try,
                  throw_throws_till_try,
                  if_in_till_try,
                  if_count_in_till_try,
                  is_assert_till_try);

              write_in_file(
                  catch_con,
                  catch_exp.toLowerCase(),
                  try_con,
                  previous_catch_as_string,
                  method_content,
                  catch_log_count,
                  method_param_as_string);

              // not perfect
              String catch_con_with_exp = mycatch.toString();
              catch_con_with_exp = catch_con_with_exp.replace("\"", "\\\\");
              catch_con_with_exp = catch_con_with_exp.replace("\'", " ");
              catch_con_with_exp = catch_con_with_exp.replace("\\\\", " ");
              previous_catch_as_string = previous_catch_as_string + "\n" + catch_con_with_exp;

              System.out.println(
                  "=========================================================================================================================");
              count++;
              itr.next();
            }

            return true;
          }

          public boolean visit(CatchClause mycatch) {
            String catch_train_con = "";
            return true;
          }
        });
  }