Searching tool for clever renaming/refactoring

A

Anonymous user

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
 
M

mandar.amdekar

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top