I have an Andriod project.
this project has many classes and variables.
all functions and variables in this project name's start with upper case.
I need to change to lower case.
Class A {
String Boo;
void HandlerMyJob(){
}
}
to
Class A {
String boo;
void handlerMyJob(){
}
}
can I use Android Studio for this problem?
You can do it using the Structural Search and Replace (SSR) functionality. Please make sure to update IntelliJ IDEA to the latest version to benefit from latest updates to SSR.
Details on the functionality and a few usage examples can be found here.
In your case, you can use the following template to fix variable names:
<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=""Field.name.uncapitalize()"" />
</replaceConfiguration>
You can alter it in the Structural Replace window in order to cover deviant cases.
Renaming methods using SSR can be tricky - but is still doable.
void MyMethod2(String field2) {
mField2 = field2;
}
For any method having the same structure as one above, the 'uncapitalizing' search/replace template will be:
<replaceConfiguration name="constructors & methods" text="class $Class$ { void $Method$($ParameterType$ $Parameter$){ $Statement$; }; }" recursive="false" caseInsensitive="true" type="JAVA" pattern_context="member" reformatAccordingToStyle="true" shortenFQN="true" replacement="void $Method2$($ParameterType$ $Parameter$){ $Statement$; } ">
<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=""Method.name.uncapitalize()"" />
</replaceConfiguration>