-
Notifications
You must be signed in to change notification settings - Fork 92
new recipe that changes .equals() to .contentEquals() when comparing … #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…a string with a StringBuilder
src/main/java/org/openrewrite/staticanalysis/EqualsToContentEquals.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/EqualsToContentEquals.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/EqualsToContentEquals.java
Outdated
Show resolved
Hide resolved
| Stream<JavaType> TYPES = Stream.of( | ||
| JavaType.buildType("java.lang.StringBuilder"), | ||
| JavaType.buildType("java.lang.StringBuffer"), | ||
| JavaType.buildType("java.lang.CharSequence") | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can probably also move these to a field above.
src/main/java/org/openrewrite/staticanalysis/EqualsToContentEquals.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/EqualsToContentEquals.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/EqualsToContentEqualsTest.java
Outdated
Show resolved
Hide resolved
timtebeek
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In terms of tests it would be good to have cases where either the first or the second select is not a string variable or constant, but for instance a method invocation, to be sure we handle those fairly predictable scenarios well.
src/test/java/org/openrewrite/staticanalysis/EqualsToContentEqualsTest.java
Outdated
Show resolved
Hide resolved
…ualsTest.java Co-authored-by: Tim te Beek <[email protected]>
…uals.java Co-authored-by: Tim te Beek <[email protected]>
…uals.java Co-authored-by: Tim te Beek <[email protected]>
…uals.java Co-authored-by: Tim te Beek <[email protected]>
…uals.java Co-authored-by: Tim te Beek <[email protected]>
…uals.java Co-authored-by: Tim te Beek <[email protected]>
…ualsTest.java Co-authored-by: Tim te Beek <[email protected]>
| @@ -0,0 +1,87 @@ | |||
| /* | |||
| * Copyright 2021 the original author or authors. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to adjust ./gradle/licenceHeader.txt and this here to set the right year.
…e not just raw string variables but also things like method calls
|
I added that test for if the recipe will run correctly on selects that are a method call. |
|
Great work! I've added another polish commit in 18287b2; with changes such as
Hope you don't mind, and I look forward to the next one! |
…a string with a StringBuilder
What's changed?
This PR adds a new recipe that finds when
.equals()is being used to compare a string and aStringBuilder,StringBufferorCharSequence.What's your motivation?
#22
Anything in particular you'd like reviewers to focus on?
I think the precondition checks should be correct but maybe they could be narrowing things down more.
Anyone you would like to review specifically?
@timtebeek
Checklist
./gradlew licenseFormat