Is there a way to change variables’ naming conventions in Eclipse (specifically Eclipse CDT)? For example, can I do a search-and-replace of variables with names like need_foo and change that to NeedFoo?
Adding and removing underscores is easy, obviously, but I don’t see a way to change case. Perl’s regexes have \u and \l modifiers to uppercase and lowercase characters, but Eclipse’s apparently don’t.
There’s no automated way of mass-renaming multiple non conforming function names in CDT. There is, however, a Code Analysis rule, which is designed to point out these sort of things. It uses Eclipse Regex described in their online help. These will give you an “Information” level marker in your Problems View.
The way they work is matching a regex against each function name, and raising an error/warning/information if that doesn’t return a match. You can access them via “Window->Preferences->C/C++->Code Analysis”. It’s about half way down the scroll list (in Eclipse Indigo).
To directly answer your second paragraph, Eclipse does not have an equivalent of Perl’s
\uand\l, the closest it has is (?ismd-ismd), which allows you to turn on matching based on case.Depending on if the Code Analysis tool returns 5 or 50,000 errors:
Only a few function definitions to rename
You can use the standard refactoring renaming tool. Right click the function name, “Refactor->Rename” will replace all references to that function with your new function name (respecting different scopes).
Many many errors
This is… not as nice. Seeing as there’s no built in method, you need to do it externally. The first approach I’d take is to see if there’s an existing plugin out there that would do this.
Failing that, what you could perhaps do is use the Code Analysis tool to identify non-conforming function names, and then using the output from that as input to a custom Perl script? You could do it in a few stages:
1) Run the code analysis, and copy and paste the warnings into a text file:
2) Change the function definition,
fooBar()–>FooBar(), using the above errors as input for a perl script (note you have the badly-conforming-function name, the file name and line number).3) Compile it and then use the output from the compiler’s
undefined reference to fooBar()to rename any references:This method would have some short comings, such as the compiler giving a partial list of undefined references due to the compilation terminating ‘early’, in which case you’d want to run it multiple times.
Another thing to look at is Refactor Scripts (Refactor –> Apply Script), but from the little I’ve seen of that, I don’t think it’s going to do what you want.
All in all, I’ve found the refactoring tools in Eclipse CDT to be no where near as powerful as those for Java (from what I remember). Still better than those in Notepad though (also, not bashing CDT, it’s an awesome development environment!)