Renaming a lot of variables in many Java classes at once

前端 未结 6 1094
清酒与你
清酒与你 2021-01-04 01:51

I work in a pretty large Java-project (2500+ classes) that uses an old code standard where all member variables are prefixed with \"m_\" (e.g m_temperature). There is reall

相关标签:
6条回答
  • 2021-01-04 02:00

    Theres a question on SC which is about a massive refactoring in java too. The best answer is using japvaparser and implementing a visitor to do the actual refactoring. This shouldn't be that much work for a simple rename.

    0 讨论(0)
  • 2021-01-04 02:02

    How about below from : mass renaming of java variables

    by Simulant

    click on the variable name.

    1:press [alt] + [shift] + [R]

    2:enter the new name.

    3:press [enter] to confirm.

    -->all instances of this variable will be renamed.

    0 讨论(0)
  • 2021-01-04 02:02

    I don't know if this can work. But I find this link to find and replace all occurence in a project using IntelliJ.

    http://www.jetbrains.com/idea/webhelp/finding-and-replacing-text-in-project.html

    0 讨论(0)
  • 2021-01-04 02:08

    Refactoring tool will help in this case. When you rename a variable, it will rename it in all dependent places including if it is called in different class file. While doing this, it will alert you in case if your renamed variable matches with already existing name.

    However we have to do it manually for each variable.

    0 讨论(0)
  • 2021-01-04 02:13

    To answer your second question (are there any more problems)

    1. I would avoid global variables. Favour encapsulation such that you can localise functionality.
    2. I would implement some unit tests such that you can verify future changes. At the moment it appears your only available check is that your project compiles properly.

    I realise both of these are potentially sizable issues in an existing project. But it's worth lookingto identify possible pain points and work on those first of all.

    0 讨论(0)
  • 2021-01-04 02:19

    If you are using eclispe IDE, you can do it in easy manner.

    Steps:

    1. select the variable
    2. right click on it
    3. click on refactor
    4. click on rename

    even in netbeans you can follow same steps. The IDE finds the reference and usages and replace it all.

    0 讨论(0)
提交回复
热议问题