diff --git a/rewrite-java/src/main/java/org/openrewrite/java/trait/MethodAccess.java b/rewrite-java/src/main/java/org/openrewrite/java/trait/MethodAccess.java index d5087341ab2..1ab5e98790b 100644 --- a/rewrite-java/src/main/java/org/openrewrite/java/trait/MethodAccess.java +++ b/rewrite-java/src/main/java/org/openrewrite/java/trait/MethodAccess.java @@ -41,9 +41,14 @@ public class MethodAccess implements Trait { @RequiredArgsConstructor public static class Matcher extends SimpleTraitMatcher { + @Nullable private final MethodMatcher methodMatcher; private Predicate<@Nullable JavaType> returnsTest = m -> true; + public Matcher() { + methodMatcher = null; + } + public Matcher(String methodPattern) { this(new MethodMatcher(methodPattern)); } @@ -87,9 +92,7 @@ public J visitMemberReference(J.MemberReference memberRef, P p) { Object value = cursor.getValue(); JavaType.Method methodType = ((MethodCall) value).getMethodType(); JavaType returnType = methodType == null ? null : methodType.getReturnType(); - - return methodMatcher.matches(((Expression) value)) && - returnsTest.test(returnType) ? + return returnsTest.test(returnType) && (methodMatcher == null || methodMatcher.matches((Expression) value)) ? new MethodAccess(cursor) : null; }