Skip to content

Sets.filter is not migrated, which creates a conflict with the PreferJavaUtilPredicate recipe #897

@lredor

Description

@lredor

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

What 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

No one assigned

    Labels

    bugSomething isn't workingguava

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions