private void checkBody(PsiElement body, ProblemsHolder holder) {
    if (body == null) return;
    final Set<PsiVariable> usedVariables = new HashSet<>();
    List<DefUseUtil.Info> unusedDefs = DefUseUtil.getUnusedDefs(body, usedVariables);

    if (unusedDefs != null && !unusedDefs.isEmpty()) {
      unusedDefs.sort(Comparator.comparingInt(o -> o.getContext().getTextOffset()));

      for (DefUseUtil.Info info : unusedDefs) {
        PsiElement context = info.getContext();
        PsiVariable psiVariable = info.getVariable();

        if (context instanceof PsiDeclarationStatement || context instanceof PsiResourceVariable) {
          if (info.isRead() && REPORT_REDUNDANT_INITIALIZER) {
            PsiTypeElement typeElement = psiVariable.getTypeElement();
            if (typeElement == null || !typeElement.isInferredType()) {
              reportInitializerProblem(psiVariable, holder);
            }
          }
        }
        else if (context instanceof PsiAssignmentExpression) {
          PsiElement parent = PsiUtil.skipParenthesizedExprUp(context.getParent());
          if (parent == psiVariable) continue; // int x = x = 5; -- compilation error and reported as reassigned var
          if (parent instanceof PsiAssignmentExpression &&
              ((PsiAssignmentExpression)parent).getOperationTokenType() == JavaTokenType.EQ &&
              EquivalenceChecker.getCanonicalPsiEquivalence().expressionsAreEquivalent(
                ((PsiAssignmentExpression)parent).getLExpression(), ((PsiAssignmentExpression)context).getLExpression())) {
            // x = x = 5; reported by "Variable is assigned to itself"
            continue;
          }
          reportAssignmentProblem((PsiAssignmentExpression)context, holder);
        }
        else if (context instanceof PsiPrefixExpression && REPORT_PREFIX_EXPRESSIONS ||
                 context instanceof PsiPostfixExpression && REPORT_POSTFIX_EXPRESSIONS) {
          holder.registerProblem(context, JavaBundle.message("inspection.unused.assignment.problem.descriptor4"));
        }
        else if (REPORT_PATTERN_VARIABLE && psiVariable instanceof PsiPatternVariable &&
                 //case is covered with `Java | Declaration redundancy | Unused declaration`
                 info.isWriteOutsideDeclaration()) {
          holder.registerProblem(psiVariable.getNameIdentifier(), JavaBundle.message("inspection.unused.assignment.problem.descriptor5"));
        }
        else if (REPORT_FOR_EACH_PARAMETER && context instanceof PsiForeachStatement foreachStatement &&
                 foreachStatement.getIterationParameter() == psiVariable && psiVariable.getNameIdentifier() != null &&
                 //case is covered with `Java | Declaration redundancy | Unused declaration`
                 info.isWriteOutsideDeclaration()) {
          holder.registerProblem(psiVariable.getNameIdentifier(), JavaBundle.message("inspection.unused.assignment.problem.descriptor6"));
        }
      }
    }

    processFieldsViaDfa(body, holder);
  }
private void checkBody(PsiElement body, ProblemsHolder holder)