PsiElementVisitor (@NotNull final ProblemsHolder holder, final boolean isOnTheFly) { final List<SuspiciousMethodCallUtil.PatternMethod> patternMethods = new ArrayList<>(); return new JavaElementVisitor() { @Override public void visitMethodCallExpression(@NotNull PsiMethodCallExpression methodCall) { final PsiExpression[] args = methodCall.getArgumentList().getExpressions(); if (args.length < 1) return; for (int idx = 0; idx < Math.min(2, args.length); idx ++) { String message = getSuspiciousMethodCallMessage(methodCall, REPORT_CONVERTIBLE_METHOD_CALLS, patternMethods, args[idx], idx); if (message != null) { holder.registerProblem(methodCall.getArgumentList().getExpressions()[idx], message); } } } @Override public void visitMethodReferenceExpression(@NotNull PsiMethodReferenceExpression expression) { final PsiType functionalInterfaceType = expression.getFunctionalInterfaceType(); final PsiClassType.ClassResolveResult functionalInterfaceResolveResult = PsiUtil.resolveGenericsClassInType(functionalInterfaceType); final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(functionalInterfaceType); if (interfaceMethod != null && interfaceMethod.getParameterList().getParametersCount() == 1) { final PsiSubstitutor psiSubstitutor = LambdaUtil.getSubstitutor(interfaceMethod, functionalInterfaceResolveResult); final MethodSignature signature = interfaceMethod.getSignature(psiSubstitutor); String message = SuspiciousMethodCallUtil.getSuspiciousMethodCallMessage(expression, signature.getParameterTypes()[0], REPORT_CONVERTIBLE_METHOD_CALLS, patternMethods, 0); if (message != null) { holder.registerProblem(ObjectUtils.notNull(expression.getReferenceNameElement(), expression), message); } } } }; }