@MagicConstant(valuesFromClass = EnumerationCanBeIterationInspection.class)
    private static int replaceMethodCalls(PsiVariable enumerationVariable, int startOffset, String newVariableName) {
      final PsiManager manager = enumerationVariable.getManager();
      final Project project = manager.getProject();
      final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
      final PsiElementFactory factory = facade.getElementFactory();
      final List<PsiReferenceExpression> referenceElements = VariableAccessUtils.getVariableReferences(enumerationVariable);
      referenceElements.sort(PsiElementOrderComparator.getInstance());
      int result = KEEP_NOTHING;
      for (PsiReferenceExpression referenceExpression : referenceElements) {
        if (referenceExpression.getTextOffset() <= startOffset) {
          result = KEEP_DECLARATION;
          continue;
        }
        final PsiElement referenceParent = referenceExpression.getParent();
        if (!(referenceParent instanceof PsiReferenceExpression)) {
          if (referenceParent instanceof PsiAssignmentExpression) {
            result = KEEP_DECLARATION;
            break;
          }
          result = KEEP_INITIALIZATION;
          continue;
        }
        final PsiElement referenceGrandParent =
          referenceParent.getParent();
        if (!(referenceGrandParent instanceof PsiMethodCallExpression callExpression)) {
          result = KEEP_INITIALIZATION;
          continue;
        }
        final PsiReferenceExpression foundReferenceExpression =
          callExpression.getMethodExpression();
        final @NonNls String foundName =
          foundReferenceExpression.getReferenceName();
        final @NonNls String newExpressionText;
        if ("hasMoreElements".equals(foundName)) {
          newExpressionText = newVariableName + ".hasNext()";
        }
        else if ("nextElement".equals(foundName)) {
          newExpressionText = newVariableName + ".next()";
        }
        else {
          result = KEEP_INITIALIZATION;
          continue;
        }
        final PsiExpression newExpression =
          factory.createExpressionFromText(newExpressionText,
                                           callExpression);
        callExpression.replace(newExpression);
      }
      return result;
    }
@MagicConstant(valuesFromClass = EnumerationCanBeIterationInspection.class)
    private static int replaceMethodCalls(PsiVariable enumerationVariable, int startOffset, String newVariableName)