-
Notifications
You must be signed in to change notification settings - Fork 110
Closed
Labels
bugSomething isn't workingSomething isn't workingguavaquestionFurther information is requestedFurther information is requested
Description
- This issue follows the issue
Sets.newHashSet(Iterables.filter...is not correctly handed by NoGuavaSetsNewHashSet recipe #881. ThePredicateclass from Guava is converted injava.util.Predicate, but the apply method calls are not systematically converted. As a result, the following error appears after migration:The method and(Predicate<? super T>, Predicate<? super T>) in the type Predicates is not applicable for the arguments (new Predicate<Object>(){}, new Predicate<Object>(){}).
The use case to reproduce needs several classes in different modules.
I think that the problem is more in ChangeMethodName recipe or in MethodMatcher class. But I'm tracing the problem I initially faced.
What version of OpenRewrite are you using?
I am using
- OpenRewrite v6.21.1
- Maven v3.9.5
- org.openrewrite.recipe:rewrite-migrate-java v3.19.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.NoGuavaSetsNewHashSet -Drewrite.exportDatatables=true -f packaging/org.eclipse.sirius.parent/pom.xmlWhat is the smallest, simplest way to reproduce the problem?
package current.module.package;
import com.google.common.base.Predicate;
import current.module.another.package.Test3;
import different.module.package.Test4;
class Test {
public static void test() {
new Test().isDetached(new Object());
}
private boolean isDetached(Object object) {
boolean detached = false;
if (Test2.A_PREDICATE_DECLARE_IN_A_CLASS_IN_SAME_PACKAGE.apply(object)) {
detached = true;
}
if (Test3.A_PREDICATE_DECLARE_IN_A_CLASS_IN_ANOTHER_PACKAGE.apply(object)) {
detached = true;
}
if (Test4.A_PREDICATE_DECLARE_IN_A_CLASS_IN_ANOTHER_MODULE.apply(object)) {
detached = true;
}
return detached;
}
}package current.module.package;
import com.google.common.base.Predicate;
public class Test2 {
public static final Predicate<Object> A_PREDICATE_DECLARE_IN_A_CLASS_IN_SAME_PACKAGE = new Predicate<Object>() {
/**
* {@inheritDoc}
*/
@Override
public boolean apply(Object input) {
return false;
}
};
}package current.module.another.package;
import com.google.common.base.Predicate;
public class Test3 {
public static final Predicate<Object> A_PREDICATE_DECLARE_IN_A_CLASS_IN_ANOTHER_PACKAGE = new Predicate<Object>() {
/**
* {@inheritDoc}
*/
@Override
public boolean apply(Object input) {
return false;
}
};
}package different.module.package;
import com.google.common.base.Predicate;
public class Test4 {
public static final Predicate<Object> A_PREDICATE_DECLARE_IN_A_CLASS_IN_ANOTHER_MODULE = new Predicate<Object>() {
/**
* {@inheritDoc}
*/
@Override
public boolean apply(Object input) {
return false;
}
};
}What did you expect to see?
import current.module.another.package.Test3;
import different.module.package.Test4;
class Test {
public static void test() {
new Test().isDetached(new Object());
}
private boolean isDetached(Object object) {
boolean detached = false;
if (Test2.A_PREDICATE_DECLARE_IN_A_CLASS_IN_SAME_PACKAGE.test(object)) {
detached = true;
}
if (Test3.A_PREDICATE_DECLARE_IN_A_CLASS_IN_ANOTHER_PACKAGE.test(object)) {
detached = true;
}
if (Test4.A_PREDICATE_DECLARE_IN_A_CLASS_IN_ANOTHER_MODULE.test(object)) {
detached = true;
}
return detached;
}
}What did you see instead?
The apply method in class Test4 was not renamed as expected.
import current.module.another.package.Test3;
import different.module.package.Test4;
class Test {
public static void test() {
new Test().isDetached(new Object());
}
private boolean isDetached(Object object) {
boolean detached = false;
if (Test2.A_PREDICATE_DECLARE_IN_A_CLASS_IN_SAME_PACKAGE.test(object)) {
detached = true;
}
if (Test3.A_PREDICATE_DECLARE_IN_A_CLASS_IN_ANOTHER_PACKAGE.test(object)) {
detached = true;
}
if (Test4.A_PREDICATE_DECLARE_IN_A_CLASS_IN_ANOTHER_MODULE.apply(object)) {
detached = true;
}
return detached;
}
}Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingguavaquestionFurther information is requestedFurther information is requested
Type
Projects
Status
Done