PsiMethod (PsiMethod @NotNull [] methods, @NotNull PsiClass target) { return Stream.of(methods) .filter(m -> { for (PsiParameter parameter : m.getParameterList().getParameters()) { PsiType t = parameter.getType(); PsiClass aClass = PsiUtil.resolveClassInClassTypeOnly(t); if (aClass == target) { return false; } } return true; }).min(Comparator.comparing(MethodChainsSearchUtil::getNonPrimitiveParameterCount)).orElse(null); }