String (CommentTracker ct, final String collectorName) { PsiExpression[] args = myMapUpdateCall.getArgumentList().getExpressions(); LOG.assertTrue(args.length >= 2); String methodName = myMapUpdateCall.getMethodExpression().getReferenceName(); LOG.assertTrue(methodName != null); Project project = myMapUpdateCall.getProject(); JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project); String aVar = codeStyleManager.suggestUniqueVariableName("a", myMapUpdateCall, true); String bVar = codeStyleManager.suggestUniqueVariableName("b", myMapUpdateCall, true); String merger = switch (methodName) { case "put" -> "(" + aVar + "," + bVar + ")->" + bVar; case "putIfAbsent" -> "(" + aVar + "," + bVar + ")->" + aVar; case "merge" -> { LOG.assertTrue(args.length == 3); yield ct.text(args[2]); } default -> null; }; if (merger == null) return null; StringBuilder collector = new StringBuilder(".collect(" + JAVA_UTIL_STREAM_COLLECTORS + "." + collectorName + "("); collector.append(ct.lambdaText(myElementVariable, args[0])).append(',') .append(ct.lambdaText(myElementVariable, args[1])).append(',') .append(merger); PsiLocalVariable variable = Objects.requireNonNull(getTargetVariable()); PsiExpression initializer = variable.getInitializer(); LOG.assertTrue(initializer != null); if ("toMap".equals(collectorName) && !isHashMap(variable)) { collector.append(",()->").append(ct.text(initializer)); } collector.append("))"); return collector.toString(); }