Open koppor opened 1 year ago
Hello @koppor, can I pick this up? And if the answer is yes, can you add a bit more description regarding this? cc: @timtebeek
Hi @jeexan2 ! Sure; if you open up a draft pull request containing just the tests of what you want to cover, I'll then assign the issue to you. You can start with a test class similar to the one we have already for collections, but then adapted to fit StringBuilder. https://github.com/openrewrite/rewrite-static-analysis/blob/d6dee9de9eff8136f77b5cf04748db147b51f591/src/test/java/org/openrewrite/staticanalysis/IsEmptyCallOnCollectionsTest.java#L37-L75
Implementation-wise the isEmpty
call on StringBuilder
comes in through java.lang.CharSequence#isEmpty
, so you'll want to target that in your recipe. The recipe itself can fit in right next to these existing String recipes in openrewrite/rewrite-migrate-java
Actually; come to think of it we already have such recipes in https://github.com/openrewrite/rewrite-migrate-java/blob/v2.1.1/src/main/java/org/openrewrite/java/migrate/lang/UseStringIsEmpty.java , but we need to broaden their matchers to use CharSequence
instead of String
!
The work still to do for this recipe then becomes:
CharSequence
, and optionally StringBuilder
CharSequence
where possibleThanks a lot for the suggestion & offer to help!
@jeexan2 (or anyone else looking to pick this up) I've added some clickable links to the above comment; hope that helps!
@timtebeek I am a new contributer. Shall I pick this ?
That would be appreciated, yes please! Feel free to start with a draft pull request containing just a test, and then I'll assign the issue to you.
@timtebeek sure.
I tried replicating this one, but it seems this test already passes unexpectedly when added to
If I understand the test correctly, it assures that nothing happens if > 1
is used.
My request was a) for > 0
(!)
Ah yes, of course; I'm multitasking too much. This one is interesting.
We could fit that in that way if we opt for the Java 9+ recipes we're adding in:
Our friends over at Picnic & ErrorProne Support already have a separate artifact to compile Java 17 templates to Java 8 runtime; they also have a matching recipe that with some changes there could solve this issue, once we pull it in through rewrite-third-party. https://github.com/PicnicSupermarket/error-prone-support/blob/3d5ee10d934df7c2de69a20ff39513a6000abc1f/error-prone-contrib/src/main/java/tech/picnic/errorprone/refasterrules/StringRules.java#L31-L46
Similar to https://docs.openrewrite.org/recipes/staticanalysis/isemptycalloncollections:
Example: https://github.com/JabRef/jabref/pull/10489/files#diff-7a00bcdda16c9953e17ec2db403404b78ad1a750671c76bd7ec885fdf8ffa776