自动将驼峰小写转换为驼峰大写
我正在寻找一种简单的方法来将java代码中的所有变量和函数名称从小写转换为大写。代码确实很多,一一重构名称并不是一个好主意。
这意味着这个函数
public void create_table(String table_name)
{
int useless_var = 0;
useless_function("string_param");
// This comment should not be altered, even_if_I_use_some_underscores
}
应该变成
public void createTable(String tableName)
{
int uselessVar = 0;
uselessFunction("string_param"); // "string_param" must not become "stringParam"
// Comments should be left untouched, even_if_I_use_some_underscores
}
等等。
我知道我可以使用 Python 脚本来完成此操作,但这需要一些时间,而且我很容易犯错误,例如转换不是标识符的内容。这就是为什么我想知道是否有工具或其他东西可以做到这一点。
I'm looking for an easy way to convert all variables and function names from lower_case to upperCase in a java code. There's really a lot of code, refactoring the names one by one isn't a good idea.
It means that this function
public void create_table(String table_name)
{
int useless_var = 0;
useless_function("string_param");
// This comment should not be altered, even_if_I_use_some_underscores
}
should become
public void createTable(String tableName)
{
int uselessVar = 0;
uselessFunction("string_param"); // "string_param" must not become "stringParam"
// Comments should be left untouched, even_if_I_use_some_underscores
}
and so on.
I know I can do it with a Python script, but it will take some time and I can easily make a mistake like converting something which is not an identifier. That's why I want to know if there's a tool or something to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
大多数 Java IDE 都可以将您对一个变量所做的更改级联到使用它的任何位置。我相信像 PMD 这样的工具可以找到这些情况,但可能无助于修复它们。
如果这是一个正在运行的应用程序,您可能需要在执行维护时进行更正。而不是一次性更新整个项目。
Most Java IDEs can cascade the changes you make to one variable where ever it is used. I believe tools like PMD can find these cases but might not help in fixing them.
If this is a working application, you might want to make corrections as you perform maintenance. Instead of updating the entire project at once.
使用 IDE 中的重构工具。
我用的是Eclipse,其中重构就是在方法或者变量上右键,Refactor >重命名。输入新名称代替旧名称,然后按“返回”,代码中的所有位置都会被重命名。请注意,它不适用于您的字符串“string_param”,您必须手动执行此操作。
希望有帮助!
Use the refactoring tool in an IDE.
I use Eclipse, where refactoring is right-click on the method or variable, Refactor > Rename. Type the new name in place of the old name, hit 'return', and it will be renamed everywhere in your code. Note, it won't work on your string "string_param" though, you'll have to do that manually.
Hope that helps!
您可以使用 WildEdit 来完成此操作。
You might be able to do this with WildEdit.