Search code examples
javacamelcasing

Convert camel-lowercase to camel-upperCase automatically


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.


Solution

  • 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.