Java source refactoring of 7000 references

Eclipse is able to do that using Refactor -> Change Method signature and provide default values for the new parameters.

For the class parameter the defaultValue should be this.getClass() but you are right in your comment I don't know how to do for the method name parameter.


I think that there are several steps to dealing with this, as it is not just a technical issue but a 'situation':

  1. Decline to do it in short order due to the risk.
  2. Point out the issues caused by not using standard frameworks but reinventing the wheel (as Paul says).
  3. Insist on using Log4j or equivalent if making the change.
  4. Use Eclipse refactoring in sensible chunks to make the changes and deal with the varying defaults.

I have used Eclipse refactoring on quite large changes for fixing old smelly code - nowadays it is fairly robust.


Great, I can copy a previous answer of mine and I just need to edit a tiny little bit:


I think what you need to do is use a source code parser like javaparser to do this.

For every java source file, parse it to a CompilationUnit, create a Visitor, probably using ModifierVisitor as base class, and override (at least) visit(MethodCallExpr, arg). Then write the changed CompilationUnit to a new File and do a diff afterwards.

I would advise against changing the original source file, but creating a shadow file tree may me a good idea (e.g. old file: src/main/java/com/mycompany/MyClass.java, new file src/main/refactored/com/mycompany/MyClass.java, that way you can diff the entire directories).


IntelliJ IDEA shouldn't have any trouble with this.

I'm not a Java expert, but something like this could work. It's not a perfect solution (it may even be a very bad solution), but it could get you started:

Change the method signature with IntelliJ's refactoring tools, and specify default values for the 2 new parameters:

c: self.getClass()
methodName: Thread.currentThread().getStackTrace()[1].getMethodName()

or better yet, simply specify null as the default values.