Detecting Log and Throw
Just wondering if anybody knows of an plugin inspection or structural search template (?) that could help me clean up a legacy module that's full of catch statements like
try {
...
} catch (Exception e) {
String message="Theres an error!";
LOGGER.error(message+" "+e.getMessage());
throw new CustomException(message, e);
}
(theres a few varitions on this general pattern)
I want to remove the logs from these.
Please sign in to leave a comment.
Using Structural Replace, start with the existing template "try's"
Modify the template as follows:
CatchStatement1 - minimum count: 0, maximum count: unlimited
LogStatement - text/regexp: LOGGER\.error(.*)
CatchStatement2 - minimum count: 0, maximum count: unlimited
Replacement template:
Hope that helps,
Bas
Thanks I'll give those a go should give me a starting point for some of the common cut&pasted occurances.
Shame we don't have a wiki to share useful macros.
Don't use the structural search feature often enough to remember the syntax, seem to remember retriving working searches was a pain.
Stackoverflow is pretty good for that in my opinion:
http://stackoverflow.com/questions/tagged/structural-search+intellij-idea
Bas