How to automatically rename (many) data members?
-
(This question is not directly related to Qt, but Qt might provide tools which help...)
In our Qt C++ project, we would like to change the names of data members by appending a suffix to them (currently they have no suffix). For example, we would like to rename data member
foo
tofoo_
.Is it possible to do this automatically? Our project has about 300,000 lines of C++ code, so any manual or semi-manual solution would be impractical.
Our environment:
- Windows 10
- MS Visual Studio 2015 with Update 3, 64-bit
- Qt 5.6.2
- Qt Creator 4.8.1
PS: Doing this change is not my decision, so no need to tell me how stupid you may think it is.
-
(This question is not directly related to Qt, but Qt might provide tools which help...)
In our Qt C++ project, we would like to change the names of data members by appending a suffix to them (currently they have no suffix). For example, we would like to rename data member
foo
tofoo_
.Is it possible to do this automatically? Our project has about 300,000 lines of C++ code, so any manual or semi-manual solution would be impractical.
Our environment:
- Windows 10
- MS Visual Studio 2015 with Update 3, 64-bit
- Qt 5.6.2
- Qt Creator 4.8.1
PS: Doing this change is not my decision, so no need to tell me how stupid you may think it is.
-
The problem is: we have thousands of data members, hence the impracticality of any (semi-)manual method.
-
@J.Hilk Yes, I have tried it. Qt Creator will indeed rename all instanced of that variable. Very convenient for changing a few data members. The problem, as I said, is that we have thousands of data members. That is, the process would look like:
for each instance variable:
- right mouse click on the the variable you want to change
- select refactor
- select rename symbol under curser
- enter new name
Doing this thousands of time would take days (weeks?), would be error-prone, and... not fun.
Instead, is there a way to rename all data members in one go? I suppose Qt Creator does not support this, but perhaps another tool?
-
@J.Hilk Yes, I have tried it. Qt Creator will indeed rename all instanced of that variable. Very convenient for changing a few data members. The problem, as I said, is that we have thousands of data members. That is, the process would look like:
for each instance variable:
- right mouse click on the the variable you want to change
- select refactor
- select rename symbol under curser
- enter new name
Doing this thousands of time would take days (weeks?), would be error-prone, and... not fun.
Instead, is there a way to rename all data members in one go? I suppose Qt Creator does not support this, but perhaps another tool?
@dave2 said in How to automatically rename (many) data members?:
Instead, is there a way to rename all data members in one go? I suppose Qt Creator does not support this, but perhaps another tool?
I don't think there's anything like that build into QtCreator, maybe there's a plugin or something, I wouldn't know.
You could write a small program that recursively parses all files of your project folder and replaces words. But that explodes in complexity, if you want any kind of sanity check.
-
@dave2 said in How to automatically rename (many) data members?:
Instead, is there a way to rename all data members in one go? I suppose Qt Creator does not support this, but perhaps another tool?
I don't think there's anything like that build into QtCreator, maybe there's a plugin or something, I wouldn't know.
You could write a small program that recursively parses all files of your project folder and replaces words. But that explodes in complexity, if you want any kind of sanity check.
@J.Hilk You are right: such a tool would need to understand C++, because in our project, unfortunately, data members sometimes appear also as local variables or parameters (thus causing tons of warnings "local variable/parameter hides data member"). And we are certainly not going to write a C++ parser ourselves...
-
@J.Hilk Yes, I have tried it. Qt Creator will indeed rename all instanced of that variable. Very convenient for changing a few data members. The problem, as I said, is that we have thousands of data members. That is, the process would look like:
for each instance variable:
- right mouse click on the the variable you want to change
- select refactor
- select rename symbol under curser
- enter new name
Doing this thousands of time would take days (weeks?), would be error-prone, and... not fun.
Instead, is there a way to rename all data members in one go? I suppose Qt Creator does not support this, but perhaps another tool?
@dave2 said in How to automatically rename (many) data members?:
is there a way to rename all data members in one go? I suppose Qt Creator does not support this, but perhaps another tool?
I'm 80% sure the answer is "no". Your use-case is very niche.
Doing this thousands of time would take days (weeks?), would be error-prone
I'd say this is faster and less error-prone than creating your own automation tool.
PS: Doing this change is not my decision, so no need to tell me how stupid you may think it is.
Tell the decision-maker that it will take weeks. If they still don't change their mind, make sure they're paying you to do the job.
And we are certainly not going to write a C++ parser ourselves...
libclang
makes this kinda feasible... ;)