Skip to content

Commit dcfe8ed

Browse files
authored
Extend MethodMatcher's ability to make structural matches when partial type information is available. (#7292)
This should help fix reports that org.openrewrite.gradle.UpgradePluginVersion is failing to update groovy scripts.
1 parent 34acf1c commit dcfe8ed

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

rewrite-java/src/main/java/org/openrewrite/java/MethodMatcher.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ public boolean matches(J.MethodDeclaration method, J.ClassDeclaration enclosing)
300300
return false;
301301
}
302302

303+
//noinspection NullableProblems
303304
List<JavaType> parameterTypes =
304305
method
305306
.getParameters()
@@ -363,7 +364,14 @@ public boolean matches(J.@Nullable MethodInvocation method, boolean matchUnknown
363364
return matchUnknownTypes && matchesAllowingUnknownTypes(method);
364365
}
365366

366-
return matches(method.getMethodType());
367+
if (matches(method.getMethodType())) {
368+
return true;
369+
}
370+
371+
// When matchUnknownTypes is true, fall back to structural matching even when
372+
// type information is present but incomplete (e.g. after lossy LST deserialization
373+
// where interface hierarchies may be stripped from declaring types)
374+
return matchUnknownTypes && matchesAllowingUnknownTypes(method);
367375
}
368376

369377
private boolean matchesAllowingUnknownTypes(J.MethodInvocation method) {

0 commit comments

Comments
 (0)