openrewrite/rewrite-migrate-java

`PreferJavaUtilPredicate` does not change functional method {apply -> test}

Closed this issue · 2 comments

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a single module project.

                <plugin>
                    <groupId>org.openrewrite.maven</groupId>
                    <artifactId>rewrite-maven-plugin</artifactId>
                    <version>5.23.1</version>
                    <configuration>
                        <activeRecipes>
                            <recipe>org.openrewrite.java.migrate.guava.NoGuavaJava11</recipe>
                        </activeRecipes>
                        <failOnDryRunResults>true</failOnDryRunResults>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>org.openrewrite.recipe</groupId>
                            <artifactId>rewrite-migrate-java</artifactId>
                            <version>2.10.0</version>
                        </dependency>
                    </dependencies>
                </plugin>

What is the smallest, simplest way to reproduce the problem?

import com.google.common.base.Predicate;

class A {
    public static Predicate<String> makeStringPredicate() {
        return new Predicate<String>() {
            @Override
            public boolean apply(String input) {
                return input.isEmpty();
            }
        };
    }
}

What did you expect to see?

import java.util.function.Predicate;

class A {
    public static Predicate<String> makeStringPredicate() {
        return new Predicate<String>() {
            @Override
            public boolean test(String input) {
                return input.isEmpty();
            }
        };
    }
}

What did you see instead?

import java.util.function.Predicate;

class A {
    public static Predicate<String> makeStringPredicate() {
        return new Predicate<String>() {
            @Override
            public boolean apply(String input) {
                return input.isEmpty();
            }
        };
    }
}

Are you interested in contributing a fix to OpenRewrite?

No time, but interested in solution.

Thanks for the report @timo-abele ! This case was indeed missed. I'd have hoped we could fix this simply by using ChangeMethodName, but it appears that and MethodMatcher need fixes to support matching method declarations inside anonymous inner classes. So I'm thankful for you bringing this up; we just have a bit more work to do before we can close this one.

I think these two together should help fix this case