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() calls with Java {Set|List|Map}.copyOf() calls #584

Open
knutwannheden opened this issue Oct 20, 2024 · 0 comments · May be fixed by #587
Assignees
Labels
enhancement New feature or request

Comments

@knutwannheden
Copy link
Contributor

Since Java 10 the interfaces Set, List, and Map declare static copyOf() methods which are equivalent to the copyOf() counterparts in Guava's ImmutableSet, ImmutableList, and ImmutableMap counterparts.

Implement three imperative recipes which implement this migration. It would probably make sense to create an abstract supertype based on AbstractNoGuavaImmutableOf, so that the recipes can be declared as subtypes of that new abstract base class. As noted the precondition would be Java 10.

There should be some test cases for this (again similarly to as how it was done for the implementations of AbstractNoGuavaImmutableOf) and finally the three new recipes should be added to the recipe list of org.openrewrite.java.migrate.guava.NoGuavaJava11 which is declared in no-guava.yml, where also the other three mentioned recipes are already declared.

@knutwannheden knutwannheden added the enhancement New feature or request label Oct 20, 2024
@knutwannheden knutwannheden self-assigned this Oct 20, 2024
knutwannheden added a commit that referenced this issue Oct 20, 2024
…yOf(), and ImmutableMap.copyOf() with Java Set.copyOf(), List.copyOf(), and Map.copyOf()

Fixes #584

Implement recipes to replace Guava `Immutable{Set|List|Map}.copyOf()` calls with Java `{Set|List|Map}.copyOf()` calls.

* Add `AbstractNoGuavaImmutableCopyOf` abstract class to handle the logic for replacing `copyOf()` calls.
* Add `NoGuavaImmutableSetCopyOf`, `NoGuavaImmutableListCopyOf`, and `NoGuavaImmutableMapCopyOf` classes extending `AbstractNoGuavaImmutableCopyOf`.
* Update `no-guava.yml` to include the new recipes.
* Add test cases for `NoGuavaImmutableSetCopyOf`, `NoGuavaImmutableListCopyOf`, and `NoGuavaImmutableMapCopyOf`.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/openrewrite/rewrite-migrate-java/issues/584?shareId=XXXX-XXXX-XXXX-XXXX).
knutwannheden added a commit that referenced this issue Oct 20, 2024
… `{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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment