void (@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) { PsiPolyadicExpression expression = tryCast(element, PsiPolyadicExpression.class); if (expression == null) return; TerminalGenerator generator = getGenerator(expression); if (generator == null) return; List<PsiExpression> diffs = extractDiff(generator, expression); if (diffs.isEmpty()) return; PsiExpression[] operands = expression.getOperands(); PsiExpression firstExpression = diffs.get(0); assert PsiTreeUtil.isAncestor(operands[0], firstExpression, false); Object marker = new Object(); PsiTreeUtil.mark(firstExpression, marker); CommentTracker ct = new CommentTracker(); PsiExpression operandCopy = (PsiExpression)ct.markUnchanged(operands[0]).copy(); PsiElement expressionCopy = PsiTreeUtil.releaseMark(operandCopy, marker); if (expressionCopy == null) return; PsiType elementType = firstExpression.getType(); String name = new VariableNameGenerator(expression, VariableKind.PARAMETER).byType(elementType).byName("v").generate(true); PsiElementFactory factory = JavaPsiFacade.getElementFactory(project); PsiExpression expressionCopyReplaced = (PsiExpression)expressionCopy.replace(factory.createExpressionFromText(name, expressionCopy)); if (operandCopy == expressionCopy) { operandCopy = expressionCopyReplaced; } String operandCopyText = operandCopy.getText(); String lambda = operandCopyText.equals(name) ? null : name + "->" + operandCopyText; String streamClass = StreamApiUtil.getStreamClassForType(elementType); if (streamClass == null) return; String source = streamClass + "." + (elementType instanceof PsiClassType ? "<" + elementType.getCanonicalText() + ">" : "") + "of" + StreamEx.of(diffs).map(ct::text).joining(",", "(", ")"); String fullStream = source + generator.generateTerminal(elementType, lambda, ct); PsiElement result = ct.replaceAndRestoreComments(expression, fullStream); cleanup(result); }