void (@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 && ReferencesSearch.search(toRemove).findFirst() == null) { final PsiElement statement = toRemove.getParent(); if (statement instanceof PsiDeclarationStatement && ((PsiDeclarationStatement)statement).getDeclaredElements().length == 1) { statement.delete(); } else { toRemove.delete(); } } }