PsiElementVisitor (@NotNull ProblemsHolder holder, boolean isOnTheFly) { return new JavaElementVisitor() { @Override public void visitAssignmentExpression(@NotNull PsiAssignmentExpression assignmentExpression) { super.visitAssignmentExpression(assignmentExpression); visitLocation(assignmentExpression); } @Override public void visitLocalVariable(@NotNull PsiLocalVariable variable) { super.visitLocalVariable(variable); // At the "information" level only bare minimal set of elements are visited when the file is being edited. // If the caret is at the variable declaration the assignment expression can be not visited so we do the same check here. if (isOnTheFly && isInformationLevel(variable)) { visitLocation(variable); } } private void visitLocation(@Nullable PsiElement location) { Context context = getContext(location); if (context != null) { PsiLocalVariable variable = context.myVariable; PsiAssignmentExpression assignment = context.myAssignment; assert location == variable || location == assignment : "context location"; String message = JavaBundle.message("inspection.join.declaration.and.assignment.message", context.myName); JoinDeclarationAndAssignmentFix fix = new JoinDeclarationAndAssignmentFix(); if (isOnTheFly && (context.myIsUpdate || isInformationLevel(location))) { ProblemHighlightType highlightType = context.myIsUpdate ? INFORMATION : GENERIC_ERROR_OR_WARNING; holder.registerProblem(location, message, highlightType, fix); } else if (location == assignment && !context.myIsUpdate) { holder.registerProblem(assignment.getLExpression(), message, fix); } } } private boolean isInformationLevel(@NotNull PsiElement element) { return InspectionProjectProfileManager.isInformationLevel(getShortName(), element); } }; }