Skip to content

Commit

Permalink
Make method pattern optional
Browse files Browse the repository at this point in the history
  • Loading branch information
sambsnyd committed Sep 19, 2024
1 parent 63252cb commit ee52aca
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ public class MethodAccess implements Trait<MethodCall> {

@RequiredArgsConstructor
public static class Matcher extends SimpleTraitMatcher<MethodAccess> {
@Nullable
private final MethodMatcher methodMatcher;
private Predicate<@Nullable JavaType> returnsTest = m -> true;

public Matcher() {
methodMatcher = null;
}

public Matcher(String methodPattern) {
this(new MethodMatcher(methodPattern));
}
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit ee52aca

Please sign in to comment.