-
Notifications
You must be signed in to change notification settings - Fork 39
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
Introduce CharSequenceRules
Refaster rule collection
#1480
Conversation
final class CharSequenceRulesTest implements RefasterRuleCollectionTestCase { | ||
ImmutableSet<Boolean> testCharSequenceIsEmpty() { | ||
return ImmutableSet.of( | ||
((CharSequence) "foo").length() == 0, |
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 there is a better way, but now we know for sure its a CharSequence
:D
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.
new StringBuilder("foo")
, str.subSequence(0, 1)
, ... :)
Looks good. No mutations were possible for these changes. |
1 similar comment
Looks good. No mutations were possible for these changes. |
bb69636
to
b7754d9
Compare
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.
Rebased and added a commit. Suggested commit message:
Introduce `CharSequenceRules` Refaster rule collection (#1480)
Resolves #1394.
*/ | ||
static final class CharSequenceIsEmpty { | ||
@BeforeTemplate | ||
boolean before(CharSequence ch) { |
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.
boolean before(CharSequence ch) { | |
boolean before(CharSequence charSequence) { |
As ch
generally denotes "char"`. (Unifying the variable naming approach is also on my list, somewhere ;).)
@@ -32,6 +32,7 @@ private StringRules() {} | |||
// XXX: Now that we build with JDK 15+, this rule can be generalized to cover all `CharSequence` | |||
// subtypes. This does require a mechanism (perhaps an annotation, or a separate Maven module) to | |||
// make sure that non-String expressions are rewritten only if client code also targets JDK 15+. | |||
@SuppressWarnings("CharSequenceIsEmpty" /* This is a more specific template. */) |
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.
The scope of this suppression should be restricted to the @BeforeTemplate
.
// XXX: Now that we build with JDK 15+, this rule can be generalized to cover all `CharSequence` | ||
// subtypes. This does require a mechanism (perhaps an annotation, or a separate Maven module) to | ||
// make sure that non-String expressions are rewritten only if client code also targets JDK 15+. |
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.
This comment should be updated.
final class CharSequenceRulesTest implements RefasterRuleCollectionTestCase { | ||
ImmutableSet<Boolean> testCharSequenceIsEmpty() { | ||
return ImmutableSet.of( | ||
((CharSequence) "foo").length() == 0, |
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.
new StringBuilder("foo")
, str.subSequence(0, 1)
, ... :)
* Prefer {@link CharSequence#isEmpty()} over alternatives that consult the char sequence's | ||
* length. | ||
*/ | ||
static final class CharSequenceIsEmpty { |
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 should document this rule's relation to StringIsEmpty
.
((CharSequence) "foo").length() != 0, | ||
((CharSequence) "bar").length() > 0, | ||
((CharSequence) "baz").length() >= 1); |
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.
"qux"
, "quux"
, "corge"
(we inconsistently sometimes also include "quuz"
; something to unify another day ;).)
Looks good. No mutations were possible for these changes. |
Quality Gate passedIssues Measures |
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.
🚀
This aims to solve the following issue: #1394.
@timtebeek mentioned that OpenRewrite has some checks that ensure that only the correct recipes are loaded for the Java version it's running on. For us I also don't see any problems for running on our code. The only advantage is that we will be matching more now :).