PsiElementVisitor (@NotNull final ProblemsHolder holder, boolean isOnTheFly) { if (!PsiUtil.isLanguageLevel8OrHigher(holder.getFile())) { return PsiElementVisitor.EMPTY_VISITOR; } return new JavaElementVisitor() { @Override public void visitLambdaExpression(@NotNull PsiLambdaExpression expression) { final PsiElement body = expression.getBody(); final PsiExpression psiExpression = isCodeBlockRedundant(body); if (psiExpression != null) { final PsiElement errorElement; final PsiElement parent = psiExpression.getParent(); if (parent instanceof PsiReturnStatement) { errorElement = parent.getFirstChild(); } else { errorElement = body.getFirstChild(); } holder.registerProblem(errorElement, JavaAnalysisBundle.message("statement.lambda.can.be.replaced.with.expression.lambda"), new ReplaceWithExprFix()); } } }; }