Java – Change all names, variables, and functions from uppercase to lowercase in android projects

Change all names, variables, and functions from uppercase to lowercase in android projects… here is a solution to the problem.

Change all names, variables, and functions from uppercase to lowercase in android projects

I have an Android project.

This project has a lot of classes and variables.

All functions and variables in this project name begin with uppercase.

I need to change to lowercase.

Class A {
   String Boo;
   void HandlerMyJob(){
   }
}

to

Class A {
   String boo;
   void handlerMyJob(){
   }
}

Can I use Android Studio to solve this problem?

Solution

You can use the Structure Search and Replace (SSR) feature to do this. Be sure to update IntelliJ IDEA to the latest version to benefit from the latest updates to your SSR.

Details about the feature and some usage examples can be found here

In your case, you can use the following template to fix the variable name:

<replaceConfiguration name="InitFinder" text="$FieldType$ $Field$; " recursive="false" caseInsensitive="true" type="JAVA" pattern_context="default" reformatAccordingToStyle="false" shortenFQN="true" replacement="$FieldType$ $Field2$; ">
  <constraint name="__context__" within="" contains="" />
  <constraint name="Field" regexp="\b^[A-Z]\w*\b" maxCount="2147483647" target="true" within="" contains="" />
  <constraint name="FieldType" within="" contains="" />
  <variableDefinition name="Field2" script="&quot; Field.name.uncapitalize()&quot; " />
</replaceConfiguration>

You can change it in the Structure Replacement window to override anomalies.


Using the SSR renaming method can be tricky – but it’s still doable.

void MyMethod2(String field2) {
        mField2 = field2;
    }

For any method with the same structure as above, the “uncapitalization” search/replace template would be:

<replaceConfiguration name="constructors &amp; methods" text="class $Class$ {&#10;    void $Method$($ParameterType$ $Parameter$){&#10;        $Statement$; &#10;    }; &#10; }" recursive="false" caseInsensitive="true" type="JAVA" pattern_context="member" reformatAccordingToStyle="true" shortenFQN="true" replacement="void $Method2$($ParameterType$ $ Parameter$){&#10;    $Statement$; &#10; }&#10; ">
  <constraint name="__context__" within="" contains="" />
  <constraint name="Method" regexp="\b^[A-Z][a-z]\w*\b" target="true" within="" contains="" />
  <constraint name="ParameterType" within="" contains="" />
  <constraint name="Parameter" within="" contains="" />
  <constraint name="Class" within="" contains="" />
  <constraint name="Statement" within="" contains="" />
  <variableDefinition name="Method2" script="&quot; Method.name.uncapitalize()&quot; " />
</replaceConfiguration>

Related Problems and Solutions