-
Notifications
You must be signed in to change notification settings - Fork 110
Closed
Labels
Description
- This issue is similar to the issue
Iterables.anyandIterables.filterare not migrated, which creates a conflict with thePreferJavaUtilPredicaterecipe #895. ThePredicateclass from Guava is converted injava.util.Predicateeven when it is used in aSets.filtermethod that is not converted. As a result, the following error appears after migration:The method filter(Set<E>, Predicate<? super E>) in the type Sets is not applicable for the arguments (Set<Object>, Predicate<Object>).
What version of OpenRewrite are you using?
I am using
- Rewrite Maven Plugin v6.22.1
- Maven v3.9.5
- org.openrewrite.recipe:rewrite-migrate-java v3.20.0
How are you running OpenRewrite?
I used the Maven command line to launch the recipe on the Sirius Desktop repository :
mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.recipeArtifactCoordinates=org.openrewrite.recipe:rewrite-migrate-java:RELEASE -Drewrite.activeRecipes=org.openrewrite.java.migrate.guava.NoGuava -Drewrite.exportDatatables=true -f packaging/org.eclipse.sirius.parent/pom.xmlWhat is the smallest, simplest way to reproduce the problem?
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import com.google.common.base.Predicate;
import com.google.common.collect.Sets;
class Test {
public static Set<Object> test() {
Set<Object> set = new HashSet<>();
Predicate<Object> isNotNull = Objects::nonNull;
return Sets.filter(set, isNotNull);
}
}What did you expect to see?
The method Sets.filter can be replaced by Collection.stream().filter(Predicate<? super T>).collect(Collectors.toSet()).
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;
class Test {
public static Set<Object> test() {
Set<Object> set = new HashSet<>();
Predicate<Object> isNotNull = Objects::nonNull;
return set.stream().filter(isNotNull).collect(Collectors.toSet());
}
}What did you see instead?
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import com.google.common.collect.Sets;
class Test {
public static Set<Object> test() {
Set<Object> set = new HashSet<>();
Predicate<Object> isNotNull = Objects::nonNull;
return Sets.filter(set, isNotNull);
}
}Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done