-
Notifications
You must be signed in to change notification settings - Fork 37
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 StringIs{,Not}EmptyPredicate
Refaster rules
#577
Introduce StringIs{,Not}EmptyPredicate
Refaster rules
#577
Conversation
Looks good. No mutations were possible for these changes. |
5b9e3e1
to
b6d3c6a
Compare
...e-contrib/src/test/resources/tech/picnic/errorprone/refasterrules/StringRulesTestOutput.java
Outdated
Show resolved
Hide resolved
@@ -39,6 +39,8 @@ ImmutableSet<Boolean> testStringIsNullOrEmpty() { | |||
getClass().getName() != null && !getClass().getName().isEmpty()); | |||
} | |||
|
|||
// XXX: Consider updating qualifier `Predicate#not` if/when conditional `ImportPolicy` is |
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.
Allow more control over which methods are statically imported by @UseImportPolicy. Sometimes the @AfterTemplate contains more than one static method invocation, and only a subset should be statically imported.
See here
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.
Check. Effectively we won't do this, I think. Instead we'll just rely on the existing StaticImport
check.
Looks good. No mutations were possible for these changes. |
Optional.ofNullable(toString()).filter(s -> !s.isEmpty()), | ||
Optional.ofNullable(toString()).filter(s -> !s.isEmpty())); | ||
Optional.ofNullable(toString()).filter(Predicate.not(String::isEmpty)), | ||
Optional.ofNullable(toString()).filter(Predicate.not(String::isEmpty)), |
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.
Should be a candidate for static import later.
See here
not(String::isEmpty) over
s -> !s.isEmpty()` when filteringnot(String::isEmpty) over
s -> !s.isEmpty()` for Predicates
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.
Tnx for picking this up @mohamedsamehsalah! I added a commit with a proposal.
Suggested commit message:
Introduce `StringIs{,Not}EmptyPredicate` Refaster rules (#577)
} | ||
} | ||
|
||
static final class FilterEmptyString { | ||
@BeforeTemplate | ||
Optional<String> before(Optional<String> optional) { | ||
return optional.map(Strings::emptyToNull); | ||
return Refaster.anyOf(optional.map(Strings::emptyToNull), optional.filter(s -> !s.isEmpty())); |
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.
Now the rule is very specific to this case. Instead we can introduce a separate rule like we have for EqualsPredicate
. (In general we always try to go the smallest/most generic rule.)
@@ -39,6 +39,8 @@ ImmutableSet<Boolean> testStringIsNullOrEmpty() { | |||
getClass().getName() != null && !getClass().getName().isEmpty()); | |||
} | |||
|
|||
// XXX: Consider updating qualifier `Predicate#not` if/when conditional `ImportPolicy` is |
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.
Check. Effectively we won't do this, I think. Instead we'll just rely on the existing StaticImport
check.
Looks good. No mutations were possible for these changes. |
error-prone-contrib/README.md
Outdated
- Allow more control over _which_ methods are statically imported by | ||
`@UseImportPolicy`. Sometimes the `@AfterTemplate` contains more than one | ||
static method invocation, and only a subset should be statically imported. |
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.
Changed my mind about removing this, as I just noticed that this is under the heading "Refaster extension ideas". Will revert. (Actually moving this section elsewhere is for another day.)
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.
(Actually moving this section elsewhere is for another day.)
I can pick that up if you tell me where it is suposed to be 😅
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.
Haha, not sure. Eventually we should likely have additional sections on the website, but that requires first knowing what we want. (And even then the text should likely be reviewed first, etc.)
But I'll keep an eye out for other possible PRs! 😄
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.
Alright, maybe you'd be interested in this one: #578 😄
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.
Thank you 🚀
Looks good. No mutations were possible for these changes. |
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.
Nice improvements, curious to see the impact on our codebase 🚀 !
@werli can you take a look? 😄
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.
I meant to press approve 😅.
4d2cb98
to
c316c88
Compare
Looks good. No mutations were possible for these changes. |
c316c88
to
2e52821
Compare
Looks good. No mutations were possible for these changes. |
2e52821
to
2cceebb
Compare
Looks good. No mutations were possible for these changes. |
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.
Let's indeed generalize this in MethodReferenceUsage
. 👍
Small step for now, but should be solved on a larger scale.
2cceebb
to
96b5773
Compare
Looks good. No mutations were possible for these changes. |
not(String::isEmpty) over
s -> !s.isEmpty()` for PredicatesStringIs{,Not}EmptyPredicate
Refaster rules
Original suggestion here.
Suggested commit message: