Java source refactoring of 7000 references

前端 未结 12 1126
醉梦人生
醉梦人生 2020-12-25 13:05

I need to change the signature of a method used all over the codebase.

Specifically, the method void log(String) will take two additional arguments (

12条回答
  •  温柔的废话
    2020-12-25 13:12

    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 ModifierVisitorAdapter 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).

提交回复
热议问题