How to globaly change variable style?

I am working on a project and we have a large amount of code with old variable styles we would like to change to our new coding style.

Old Example:


would become

New Example:


Any ideas if this can be automated, with search and replace or a plugin etc?? Its a lot of work to do by hand even with variable rename refactor.

Many Thanks

Jasper

6 comments

Hi Jasper,

I would do this in parallel while performing other refactorings. In the past
I was working on misaligned old and crappy C-code. While understanding and
"refactoring" ("" because of the limited possibilities using MS VC++6) that
helped me to later see at one glance, what code was already reviewed by me
(and working as I expected) and what not.

Tom

0

Hello Jasper,

JP> I am working on a project and we have a large amount of code with
JP> old variable styles we would like to change to our new coding style.
JP>
JP> Old Example:
JP>

 public class Hello{
JP> int m_iIntegerVar = 6;
JP> String m_sStringVar = "Hello";
JP> public Hello(int i_iIntegerVar, String i_sStringVar){
JP> m_iIntegerVar = i_iIntegerVar;
JP> m_sStringVar = i_sStringVar;
JP> }
JP> public void setIntegerVar(int i_iIntegerVar){
JP> m_iIntegerVar = i_iIntegerVar;
JP> }
JP> }
JP> ]]>

JP>
JP> would become
JP>
JP> New Example:
JP>

 public class Hello{
JP> int integerVar = 6;
JP> String stringVar = "Hello";
JP> public Hello(int integerVar, String stringVar){
JP> this.integerVar = integerVar;
JP> this.stringVar = stringVar;
JP> }
JP> public void setIntegerVar(int integerVar){
JP> this.integerVar = integerVar;
JP> }
JP> }
JP> ]]>

JP>
JP> Any ideas if this can be automated, with search and replace or a
JP> plugin etc?? Its a lot of work to do by hand even with variable
JP> rename refactor.

The inspections from the "Naming Conventions" group may help you do this.
I'm not sure they can handle the batch replacing, but at least they can automatically
highlight the names which do not match your new convention.

--
Dmitry Jemerov
Software Developer
JetBrains, Inc.
http://www.jetbrains.com
"Develop with pleasure!"


0


The naming convention inspections don't include quick-fixes, and so they wouldn't work for batch replace. They could be used to list all of the variables that need fixed, however.

--Dave Griffith

0

The intentions are a help, is there a way of extending them to be able to fix as well? ie do a rename and chop off first 3 chars and change next to lower case?

Thanks, Jasper

0


If there were a canonical way of munging a name to fit a given regex, I would certainly implement it. Several have been suggested, but none both general enough and capable of covering the more common standards.

For a specific fix algorithm like you describe, you might be able to cudgel the Structural Search and Replace stuff to do what you want, but I'm honestly not sure how to go about it, myself.

--Dave Griffith

0

I had a look at Structural Search and Replace but dont think it will work. It needs to use the rename member/var refactoring power so it can add things like "this." where needed.

0

Please sign in to leave a comment.