@Override
    protected void applyFix(@NotNull Project project, @NotNull PsiElement startElement, @NotNull ModPsiUpdater updater) {
      PsiExpression expression = tryCast(startElement, PsiExpression.class);
      if (expression == null) return;
      final PsiVariable toRemove;
      final PsiExpression keySetExpression;
      if (expression instanceof PsiReferenceExpression) {
        toRemove = ExpressionUtils.resolveLocalVariable(expression);
        if (toRemove == null) return;
        keySetExpression = PsiUtil.skipParenthesizedExprDown(toRemove.getInitializer());
      }
      else {
        toRemove = null;
        keySetExpression = expression;
      }
      PsiReferenceExpression mapRef = getMapReferenceFromKeySetCall(keySetExpression);
      if (mapRef == null) return;
      if (myMode == ReplacementMode.FOR_EACH) {
        processLambda(project, expression, mapRef);
      } else {
        processLoop(project, expression, mapRef, myMode);
      }
      if (toRemove != null && VariableAccessUtils.getVariableReferences(toRemove).isEmpty()) {
        if (toRemove.getParent() instanceof PsiDeclarationStatement declaration && declaration.getDeclaredElements().length == 1) {
          declaration.delete();
        }
        else {
          toRemove.delete();
        }
      }
    }
@Override
    protected void applyFix(@NotNull Project project, @NotNull PsiElement startElement, @NotNull ModPsiUpdater updater)