openrewrite / openrewrite/rewrite-static-analysis
Prefer String::equalsToIgnoreCase - "foo".equals("Foo".toLowercase()) -> "foo".equalsToIgnoreCase("Foo")
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 62
- Forks
- 112
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 40
Description
What problem are you trying to solve?
Just came across this finding from IntelliJ:
String upperFoo = "FoO"
"foo".equals(upperFoo.toLowercase())
can be
String upperFoo = "FoO"
"foo".equalsToIgnoreCase(upperFoo)
Condition: the first string is all lowercase
Would be nice to have that automated.
I've considered posting this in rewrite-migrate-java, but as there is no "since" in the API I guess it has been around forever and was never a new language feature.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the existing Java static-analysis recipes and their tests for String equality or case conversion. Check how the project represents chained String calls, then define tests for the lowercase-first-string condition and the requested case-insensitive comparison transformation. Done means the qualifying example is automated without changing non-qualifying expressions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100