void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { PsiMethodCallExpression call = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class, false); if(call == null) return; PrepopulatedCollectionModel model = MAPPER.mapFirst(call); if(model == null) return; String typeArgument = getTypeArguments(call.getType(), model.myType); CommentTracker ct = new CommentTracker(); String replacementText; if (model.myCopy) { assert model.myContent.size() == 1; replacementText = "java.util." + model.myType + "." + typeArgument + "copyOf(" + model.myContent.get(0).getText() + ")"; } else if (model.hasTooManyMapEntries()) { replacementText = StreamEx.ofSubLists(model.myContent, 2) .map(expr -> ct.commentsBefore(expr.get(0)) + "java.util.Map.entry(" + ct.text(expr.get(0)) + "," + ct.textWithComments(expr.get(1)) + ")") .joining(",", "java.util.Map." + typeArgument + "ofEntries(", ")"); } else { replacementText = StreamEx.of(model.myContent) .map(ct::textWithComments) .joining(",", "java.util." + model.myType + "." + typeArgument + "of(", ")"); } List<PsiLocalVariable> vars = StreamEx.of(model.myElementsToDelete).map(PsiElement::getParent).select(PsiLocalVariable.class).toList(); model.myElementsToDelete.forEach(ct::delete); PsiElement replacement = ct.replaceAndRestoreComments(call, replacementText); vars.stream().filter(var -> !VariableAccessUtils.variableIsUsed(var, PsiUtil.getVariableCodeBlock(var, null))) .forEach(PsiElement::delete); RemoveRedundantTypeArgumentsUtil.removeRedundantTypeArguments(replacement); }