Searching tool for clever renaming/refactoring

Discussion in 'Java' started by Anonymous user, Jan 2, 2006.

  1. Hello,

    i'm searching a tool for java source code wich can enable me to
    replace/refactor some (ugly) code. Let's take an example:

    1/ what i have:

    catch (Exception ex) {
    Log.getLog().log("Cannot read \" + filename + "\": " + ex);
    }

    what i want:

    catch (Exception ex) {
    Log.getNewLog().log("Cannot read \" + filename + "\".", ex);
    }



    2/ what i have:

    catch (Exception ex) {
    Log.getLog().log("There was a problem!");
    Log.getLog().log(ex);
    }

    what i want:

    catch (Exception ex) {
    Log.getNewLog().log("There was a problem!", ex);
    }

    3/ and sometimes, i have only the exception or the sting.

    Even if a i have to code some kind of AST matching code, it's OK. But
    can't do it from scratch. So what do you think is the best tool to use?

    TIA for any help
    Anonymous user, Jan 2, 2006
    #1
    1. Advertising

  2. Anonymous user

    Suresh Guest

    "Anonymous user" <> wrote in message
    news:...

    [snip]

    > So what do you think is the best tool to use?
    >


    vi with regex.
    Suresh, Jan 2, 2006
    #2
    1. Advertising

  3. Anonymous user

    Guest

    I have done something very similar to this, only 10 times more complex
    as this, using a perl script (which, btw I wrote using emacs :). It's
    1061 lines of hairy regexs. Here is what it does:

    #
    # The code currently has calls to the logging methods like the
    following:
    # Log.Log(CATEGORY_NAME, Log.LEVEL, "message " + a + " continue",
    exception);
    #
    # We want to transform this call into a call that looks like the
    following:
    # Log.CATEGORY_NAME.level(new Message("message {0}
    continue").setArgs(a), exception)
    #
    # This script will do it in 3 passes. Here is what each of the passes
    will do
    # Pass 1:
    # Will convert Log.Log(CAT_NAME, LEVEL, "msg" + a, ex) ->
    Log.CAT_NAME.level("msg" + a, ex);
    # Pass 2:
    # Log.CAT_NAME.level("msg" + a, ex) -> Log.CAT_NAME.level(new
    Message("msg" + a), ex);
    # Pass 3:
    # new Message("msg" + a) -> new Message("(Number)
    msg{0}").setArgs(a)
    # This pass also has the side effect of writing the properties file
    with the
    # appropriate internationalized string key/value pairs. It will
    only modify
    # the new Message("") calls inside logging methods
    #
    # Bugs/Enhancements
    # -----------------
    # 1. use same argument number '{number}' for arguments whose spelling
    is the same
    #

    Email me if you're interested, and I can share it.
    , Jan 2, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Hunsley
    Replies:
    2
    Views:
    552
    Juha Laiho
    Oct 16, 2003
  2. Tabrez Iqbal

    Refactoring Tool for C++

    Tabrez Iqbal, Sep 11, 2003, in forum: C++
    Replies:
    0
    Views:
    441
    Tabrez Iqbal
    Sep 11, 2003
  3. Andre Baresel

    C++ Refactoring Tool

    Andre Baresel, Dec 27, 2003, in forum: C++
    Replies:
    0
    Views:
    719
    Andre Baresel
    Dec 27, 2003
  4. Andre Baresel

    C++ Refactoring Tool

    Andre Baresel, Jan 7, 2004, in forum: C++
    Replies:
    0
    Views:
    8,211
    Andre Baresel
    Jan 7, 2004
  5. Sachin Garg

    Refactoring tool... PLEASE

    Sachin Garg, Jun 24, 2004, in forum: C++
    Replies:
    2
    Views:
    431
    Thierry Miceli
    Jun 24, 2004
Loading...

Share This Page