一次重命名许多Java类中的许多变量 [英] Renaming a lot of variables in many Java classes at once

查看:109
本文介绍了一次重命名许多Java类中的许多变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个相当大的Java项目(2500多个类)中工作,该项目使用旧的代码标准,其中所有
成员变量都以m_为前缀(例如m_temperature)。这已经没有理由了,我想摆脱它们但是:


  1. 为了做出改变我必须一次所有变量

  2. 不得产生任何错误。

简单地将所有m_variable重命名为变量的第一种简单方法是不够的,因为这可能会在已经存在的名为variable的变量与新重命名的变量之间产生名称冲突。 p>

所以,总结一下:
如何重命名所有这些讨厌的成员变量而不会遇到麻烦,还有比上面提到的更多问题吗?



是的,我知道IDE中的重构/重命名功能,请记住我想对进行更改所有变量一次匹配条件而不是右键单击变量并逐个重命名。

解决方案

Theres a 问题也是关于java中的大规模重构。最好的答案是使用 japvaparser 并实施访问者来进行实际的重构。对于简单的重命名,这不应该那么多。


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 really no reason for this any longer and I'd like to get rid of them but:

  1. In order to make the change I must do all variables at once.
  2. It must not generate any bugs.

The first naive approach of simply renaming all the "m_variable" to just "variable" will not be sufficient as that could produce name collisions between an already existing variable named "variable", and the newly renamed one.

So, to sum up: How do I rename all these pesky member variablest without getting into trouble and are there any more problems than the one mentioned above?

Yes, I'm aware of the refactoring/renaming features within IDEs, please bear in mind that I want to do the changes to all variables matching the criteria at once and not by right-clicking on variables and renaming them one-by-one.

解决方案

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.

这篇关于一次重命名许多Java类中的许多变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆