PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { if (!PsiUtil.isLanguageLevel10OrHigher(holder.getFile())) { //var won't be parsed as inferred type otherwise return PsiElementVisitor.EMPTY_VISITOR; } return new JavaElementVisitor() { @Override public void visitLambdaExpression(@NotNull PsiLambdaExpression expression) { List<PsiTypeElement> typeElements = new ArrayList<>(); for (PsiParameter parameter: expression.getParameterList().getParameters()) { PsiTypeElement typeElement = getTypeElementToExpand(parameter); if (typeElement == null) return; typeElements.add(typeElement); } for (PsiTypeElement typeElement: typeElements) { registerTypeElementProblem(typeElement); } } @Override public void visitVariable(@NotNull PsiVariable variable) { if (variable instanceof PsiParameter && ((PsiParameter)variable).getDeclarationScope() instanceof PsiLambdaExpression) { return; } PsiTypeElement typeElement = getTypeElementToExpand(variable); if (typeElement != null) { registerTypeElementProblem(typeElement); } } private void registerTypeElementProblem(@NotNull PsiTypeElement typeElement) { holder.problem(typeElement, JavaAnalysisBundle.message("var.can.be.replaced.with.explicit.type")) .fix(new ReplaceVarWithExplicitTypeFix(typeElement)) .register(); } }; }