void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { if (!(element instanceof PsiReferenceExpression)) return; PsiExpression qualifier = ExpressionUtils.getEffectiveQualifier((PsiReferenceExpression)element); if (qualifier == null) return; PsiExpression iterable; if (element instanceof PsiMethodReferenceExpression) { iterable = findIterableForFunction((PsiFunctionalExpression)element); } else { PsiElement parent = element.getParent(); if (!(parent instanceof PsiMethodCallExpression)) return; iterable = findIterable((PsiMethodCallExpression)parent, myInfo); } if (iterable == null) return; PsiElement parent = CommonJavaRefactoringUtil.getParentStatement(iterable, false); if (parent == null) return; CommentTracker ct = new CommentTracker(); String iterableText = calculateIterableText(iterable, ct); if (parent instanceof PsiDeclarationStatement) { PsiLoopStatement loop = PsiTreeUtil.getParentOfType(element, PsiLoopStatement.class); if (loop != null && loop.getParent() == parent.getParent()) { ct.delete(loop); } } PsiElement result = ct.replaceAndRestoreComments(parent, ct.text(qualifier) + "." + myInfo.getBulkName() + "(" + iterableText + ")" + (parent instanceof PsiStatement ? ";" : "")); result = JavaCodeStyleManager.getInstance(project).shortenClassReferences(result); CodeStyleManager.getInstance(project).reformat(result); }