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 ImmutableMapRules Refaster rule collection #1488

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Stephan202
Copy link
Member

@Stephan202 Stephan202 commented Dec 29, 2024

I set out to resolve #1223, then noticed a few other ways in which internal code can be simplified.

Suggested commit message:

Extend `ImmutableMapRules` Refaster rule collection (#1488)

Resolves #1223.

@Stephan202 Stephan202 added this to the 0.20.0 milestone Dec 29, 2024
@Stephan202 Stephan202 force-pushed the sschroevers/extend-ImmutableMapRules branch from 1a97fa7 to 6ac49c4 Compare December 29, 2024 19:36
Copy link

Looks good. All 1 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.NonStaticImport 0 1

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

Copy link
Member Author

@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.

Some context.

Comment on lines +48 to +62
/**
* Prefer {@link ImmutableMap.Builder#buildOrThrow()} over the less explicit {@link
* ImmutableMap.Builder#build()}.
*/
static final class ImmutableMapBuilderBuildOrThrow<K, V> {
@BeforeTemplate
ImmutableMap<K, V> before(ImmutableMap.Builder<K, V> builder) {
return builder.build();
}

@AfterTemplate
ImmutableMap<K, V> after(ImmutableMap.Builder<K, V> builder) {
return builder.buildOrThrow();
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

The builder subtypes for ImmutableBiMap and ImmutableSortedMap extend from ImmutableMap.Builder, so those build() calls are also covered.

Comment on lines -142 to -143
// XXX: We could add variants in which the entry is created some other way, but we have another
// rule that covers canonicalization to `Map.entry`.
Copy link
Member Author

Choose a reason for hiding this comment

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

Dropped, because this describes our approach more generally these days.

Copy link

Looks good. All 1 mutations in this change were killed.

class surviving killed
🎉tech.picnic.errorprone.bugpatterns.NonStaticImport 0 1

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

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
Contributor

@mohamedsamehsalah mohamedsamehsalah left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

Nice suggestion @EnricSala 🙌

@Stephan202 Stephan202 force-pushed the sschroevers/extend-ImmutableMapRules branch from fcd022d to b7d09da Compare December 30, 2024 11:54
Copy link
Member Author

@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.

Rebased and updated the integration test expectations.

Comment on lines -4576 to +4623
Map.ofEntries(
- Map.ofEntries(
+ ImmutableMap.ofEntries(
entry("days", "d"),
entry("hours", "h"),
entry("minutes", "min"),
Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't simplified further, because it's a long list. We could add more rules, but: meh.

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.

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.

Rewrite ImmutableMap.Builder#build to #buildOrThrow
2 participants