private static boolean isRedundantOperation(PsiExpression replacement,
                                                  PsiStatement body,
                                                  CountingLoop countingLoop,
                                                  IndexedContainer container) {
        PsiLocalVariable counter = countingLoop.getCounter();
        if (ExpressionUtils.isReferenceTo(container.extractIndexFromGetExpression(replacement), counter)) return true;
        if (!(replacement instanceof PsiReferenceExpression)) return false;
        PsiVariable variable = tryCast(((PsiReferenceExpression)replacement).resolve(), PsiVariable.class);
        if (variable == null) return false;
        PsiExpression initializer = variable.getInitializer();
        PsiExpression index = container.extractIndexFromGetExpression(initializer);
        return ExpressionUtils.isReferenceTo(index, counter) && HighlightControlFlowUtil.isEffectivelyFinal(variable, body, null);
      }
private static boolean isRedundantOperation(PsiExpression replacement,
                                                  PsiStatement body,
                                                  CountingLoop countingLoop,
                                                  IndexedContainer container)