Skip to content
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

Extend {Is,Non}NullFunction Refaster rules #1494

Merged
merged 2 commits into from
Dec 31, 2024
Merged

Conversation

werli
Copy link
Member

@werli werli commented Dec 31, 2024

Pretty trivial extension after I saw this construct in the wild.


Suggested commit message:

Extend `{Is,Non}NullFunction` Refaster rules (#1494)

Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tnx @werli! I added a commit. Suggested commit message:

Extend `{Is,Non}NullFunction` Refaster rules (#1494)

While there, simplify the associated tests.

@@ -111,7 +112,7 @@ Predicate<T> after() {
static final class NonNullFunction<T> {
@BeforeTemplate
Predicate<T> before() {
return o -> o != null;
return Refaster.anyOf(o -> o != null, not(Objects::isNull));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, three occurrences of this in the internal code base.

import java.util.stream.Stream;
import tech.picnic.errorprone.refaster.test.RefasterRuleCollectionTestCase;

final class NullRulesTest implements RefasterRuleCollectionTestCase {
@Override
public ImmutableSet<Object> elidedTypesAndStaticImports() {
return ImmutableSet.of(MoreObjects.class, Optional.class);
return ImmutableSet.of(MoreObjects.class, Optional.class, Predicate.class, not(null));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like we can omit Predicate here :)

Comment on lines 33 to 46
long testIsNullFunction() {
return Stream.of("foo").filter(s -> s == null).count();
ImmutableSet<Long> testIsNullFunction() {
return ImmutableSet.of(
Stream.of("foo").filter(s -> s == null).count(),
Stream.of("bar").filter(not(Objects::nonNull)).count());
}

long testNonNullFunction() {
return Stream.of("foo").filter(s -> s != null).count();
ImmutableSet<Long> testNonNullFunction() {
return ImmutableSet.of(
Stream.of("foo").filter(s -> s != null).count(),
Stream.of("bar").filter(not(Objects::isNull)).count());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that these tests were a bit more complicated than how we usually write them; will use this opportunity to simplify.

@@ -98,7 +99,7 @@ T after(T object, Supplier<S> supplier) {
static final class IsNullFunction<T> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also update the associated comments.

@Stephan202 Stephan202 marked this pull request as ready for review December 31, 2024 13:23
@Stephan202 Stephan202 added this to the 0.20.0 milestone Dec 31, 2024
@Stephan202 Stephan202 requested a review from rickie December 31, 2024 13:23
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie merged commit d11ac09 into master Dec 31, 2024
16 checks passed
@rickie rickie deleted the werli/null-predicate branch December 31, 2024 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants