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

Recipes to replace Guava Immutable{Set|List|Map}.copyOf() with Java {Set|List|Map}.copyOf() #587

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

knutwannheden
Copy link
Contributor

@knutwannheden knutwannheden commented Oct 20, 2024

Add recipes to replace Guava ImmutableSet.copyOf(), ImmutableList.copyOf(), and ImmutableMap.copyOf() calls with Java Set.copyOf(), List.copyOf(), and Map.copyOf() calls.

  • Add AbstractNoGuavaImmutableCopyOf class to provide a base for the new recipes.
  • Add NoGuavaImmutableSetCopyOf, NoGuavaImmutableListCopyOf, and NoGuavaImmutableMapCopyOf classes extending AbstractNoGuavaImmutableCopyOf.
  • Update no-guava.yml to include the new recipes.
  • Add test classes NoGuavaImmutableSetCopyOfTest, NoGuavaImmutableListCopyOfTest, and NoGuavaImmutableMapCopyOfTest with test cases for the new recipes.

For more details, open the Copilot Workspace session.

… `{Set|List|Map}.copyOf()`

Fixes #584

Add recipes to replace Guava `ImmutableSet.copyOf()`, `ImmutableList.copyOf()`, and `ImmutableMap.copyOf()` calls with Java `Set.copyOf()`, `List.copyOf()`, and `Map.copyOf()` calls.

* Add `AbstractNoGuavaImmutableCopyOf` class to provide a base for the new recipes.
* Add `NoGuavaImmutableSetCopyOf`, `NoGuavaImmutableListCopyOf`, and `NoGuavaImmutableMapCopyOf` classes extending `AbstractNoGuavaImmutableCopyOf`.
* Update `no-guava.yml` to include the new recipes.
* Add test classes `NoGuavaImmutableSetCopyOfTest`, `NoGuavaImmutableListCopyOfTest`, and `NoGuavaImmutableMapCopyOfTest` with test cases for the new recipes.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/openrewrite/rewrite-migrate-java/issues/584?shareId=XXXX-XXXX-XXXX-XXXX).
@BramliAK
Copy link
Contributor

In my opinion, a new abstract class known as AbstractNoGuavaImmutable can be created and the common methods can be added to it. We can further expand it with AbstractNoGuavaImmutableCopyOf.java and AbstractNoGuavaImmutableOf.java to eliminate the use of duplicated code.

@timtebeek
Copy link
Contributor

I was thinking along the same lines, especially after the improvements you added @BramliAK ; reuse between these two is likely preferred over duplication.

@timtebeek timtebeek marked this pull request as draft October 24, 2024 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

Recipes to replace Guava Immutable{Set|List|Map}.copyOf() calls with Java {Set|List|Map}.copyOf() calls
3 participants