Java code quality bulk fix - Strings literals should be placed on the left side when checking for equality

Viewed 771

We have a huge legacy code base, for which we are trying to fix all Sonar quality issues.

There is issue which says - Strings literals should be placed on the left side when checking for equality. And count of this issue is 12k+.

testFlag.equalsIgnoreCase("Y") - non-complaint
"Y".equalsIgnoreCase(testFlag) - complaint

I am trying to use Intelliji IDE Inspection utility to fix this using "Strutural Search Inspection". How ever, it did not work out.

I have kept search template as

$instanceVariable$(equalsIgnoreCase)\(\"$StringLiteral$

and replace template as

$StringLiteral$(equalsIgnoreCase)\(\"$instanceVariable$

But it does not work, is it right way to do/ any better options available in intelliji for this.

I am open to other IDEs like Eclipse. So if there is an option in any open source IDEs, i could try out.

2 Answers
Related