I have a library, and I need to refactor a class X such that every call of the form:
f(x); //Non-member function
is subsituted with:
x.f(); //Member function
where f is a fixed method (same name in all the code) but x is an instance of type X, and as such will change.
Is there an wasy way to do a globl find and replace which would take care of such conversions?
Just in case, also knowing how to go from the member to the non-member case would be interesting :)
Thank you!
Use the compiler, luke.
Since I cannot image how this could be done via textual replacement, and I very much doubt you have a refactoring tool available that does it[*] for you:
Simply change your class definition accordingly, so that the previous function is no longer available. Then let your compiler tell you where you need to replace the calls to a no-longer-existing function.
[*] : Actually, I doubt there's any refactoring tool for C++ available that is able to achieve this.
Can't imagine so, not without a very advanced refactoring plugin/addon. It's even a little more complicated than you'd expect at first, because you'd also want to change any calls like x->f()
into f(*x)
. Let's not even get into the situation where you have method pointers...
Find and Replace, using regular expressions and tagged groups.
Then you can replace f\\({:i}\\)
with \\1.f()
and f\\(\\*{:i}\\)
with \\1->f()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.