Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Searching tool for clever renaming/refactoring

Thread view: 
Anonymous user - 02 Jan 2006 15:55 GMT
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
Suresh - 02 Jan 2006 17:18 GMT
[snip]

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

vi with regex.
mandar.amdekar@gmail.com - 02 Jan 2006 19:35 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.