Java source refactoring of 7000 references

前端 未结 12 1086
醉梦人生
醉梦人生 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:19

    Il fact your problem is not to use a click'n'play engine that will allow you to replace all occurences of

    log("some weird message");
    

    by

    log(this.getClass(), new Exception().getStackTrace()[1].getMethodName());
    

    As it has few chances to work on various cases (like static methods, as an example).

    I would tend to suggest you to take a look at spoon. This tool allows source code parsing and transformation, allowing you to achieve your operation in a -obviously code based- slow, but controlled operation.

    However, you could alos consider transforming your actual method with one exploring stack trace to get information or, even better, internally use log4j and a log formatter that displays the correct information.

提交回复
热议问题