-
Notifications
You must be signed in to change notification settings - Fork 92
Alek/remove to string calls from array instances #126
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
…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]>
…e not just raw string variables but also things like method calls
…for two tests which are testing an edge cases related to String.format()
|
There's some conflicts here; could you resolve those? Did you perhaps start your branch from your previous branch? |
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Outdated
Show resolved
Hide resolved
|
I figured out the edge case and also the precondition check. I think this recipe is functionally complete, but maybe there could be last minute polishes I don't see. |
sambsnyd
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.
Good work! This will be a useful recipe. 👍
After you address my feedback this looks good to check in, no need to seek another round of review from me.
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Outdated
Show resolved
Hide resolved
src/test/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstancesTest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Outdated
Show resolved
Hide resolved
…so reworked recipe so that it uses cursor messaging
8077b60 to
bd586b7
Compare
|
Ok, so I've tried to incorporate all the feedback from this thread. I still need to add more tests for a bunch of the other methods mentioned above. However, I think I should wait to do that till I have the cursor messaging working. I've updated the branch with my implementation of the cursor messaging but it doesn't work. The message never seems to be found in the |
@AlekSimpson You got it almost all right! The important thing here is that the |
…ipe also covers arrays concatenated with strings now
|
All changes have been made and tests have been updated. All tests pass. |
knutwannheden
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.
Almost there! I added a few more comments which should be addressed.
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Outdated
Show resolved
Hide resolved
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Outdated
Show resolved
Hide resolved
| public Expression visitExpression(Expression exp, ExecutionContext ctx) { | ||
| Expression e = (Expression) super.visitExpression(exp, ctx); | ||
| if (e.getType() instanceof JavaType.Array) { | ||
| if (e instanceof TypedTree && e.getType() instanceof JavaType.Array) { |
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.
Maybe this is more a question for Knut of Kun, but I had expected a call out to TypeUtils here rather than a direct use of instanceof. When would we use each?
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 could replace e.getType() instanceof JavaType.Array with TypeUtils.asArray(e.getType()) != null but I don't think it is really much better. IMHO the instanceof here is fine.
5963274 to
ffadf48
Compare
knutwannheden
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.
Apart from one last minor comment I think this looks good.
| public Expression visitExpression(Expression exp, ExecutionContext ctx) { | ||
| Expression e = (Expression) super.visitExpression(exp, ctx); | ||
| if (e.getType() instanceof JavaType.Array) { | ||
| if (e instanceof TypedTree && e.getType() instanceof JavaType.Array) { |
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 could replace e.getType() instanceof JavaType.Array with TypeUtils.asArray(e.getType()) != null but I don't think it is really much better. IMHO the instanceof here is fine.
src/main/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstances.java
Outdated
Show resolved
Hide resolved
…lsFromArrayInstances.java Co-authored-by: Knut Wannheden <[email protected]>
src/test/java/org/openrewrite/staticanalysis/RemoveToStringCallsFromArrayInstancesTest.java
Outdated
Show resolved
Hide resolved
…lsFromArrayInstancesTest.java
What's changed?
toString should not be called on array instances. RSPEC-2116
What's your motivation?
#44
Anything in particular you'd like reviewers to focus on?
I think the recipe is pretty much finished, only two things is there is an edge case with String.format() calls I still haven't quite worked out. It gives an error when I try and run the tests on them. Second thing is that I'm not sure how to get the preconditions to check for if the code is using the array type before it runs.
Anyone you would like to review specifically?
@timtebeek
Checklist
./gradlew licenseFormat