@Override
  public @NotNull PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly) {
    return new JavaElementVisitor() {

      @Override
      public void visitMethodReferenceExpression(final @NotNull PsiMethodReferenceExpression expression) {
        Problem problem = doCheckMethodCallOnFunctionalExpression(expression, call -> expression.resolve() != null);
        if (problem != null) {
          problem.register(holder);
        }
      }

      @Override
      public void visitLambdaExpression(final @NotNull PsiLambdaExpression expression) {
        Problem problem = doCheckLambda(expression);
        if (problem != null) {
          problem.register(holder);
        }
      }

      @Override
      public void visitAnonymousClass(final @NotNull PsiAnonymousClass aClass) {
        if (AnonymousCanBeLambdaInspection.canBeConvertedToLambda(aClass, false, Collections.emptySet())) {
          final PsiNewExpression newExpression = ObjectUtils.tryCast(aClass.getParent(), PsiNewExpression.class);
          Problem problem = doCheckMethodCallOnFunctionalExpression(call -> {
            final PsiMethod method = aClass.getMethods()[0];
            final PsiCodeBlock body = method.getBody();
            final PsiReturnStatement[] returnStatements = PsiUtil.findReturnStatements(body);
            if (returnStatements.length > 1) {
              return false;
            }
            final PsiElement callParent = PsiUtil.skipParenthesizedExprUp(call.getParent());
            return callParent instanceof PsiStatement ||
                   callParent instanceof PsiLocalVariable;
          }, newExpression, aClass.getBaseClassType(), new ReplaceAnonymousWithLambdaBodyFix());
          if (problem != null) {
            problem.register(holder);
          }
        }
      }
    };
  }
@Override
  public @NotNull PsiElementVisitor buildVisitor(final @NotNull ProblemsHolder holder, boolean isOnTheFly)