String (CommentTracker ct) { String nestedStreamSource; if (COLLECTION_ADD_ALL.test(myAddAllCall)) { // result.addAll(c) PsiExpression collection = myAddAllCall.getArgumentList().getExpressions()[0]; if (myElement.getType() instanceof PsiPrimitiveType) { String collectionVariableName = new VariableNameGenerator(myAddAllCall, VariableKind.PARAMETER) .byExpression(collection) .byName("c", "col") .generate(true); return ".mapToObj(" + myElement.getName() + "->" + collection.getText() + ")" + ".flatMap(" + collectionVariableName + "->" + collectionVariableName + ".stream())"; } else { nestedStreamSource = ParenthesesUtils.getText( collection, ParenthesesUtils.POSTFIX_PRECEDENCE) + ".stream()"; String lambda = myElement.getName() + "->" + nestedStreamSource; return ".flatMap(" + lambda + ")"; } } else {// Collections.addAll(result, ...) PsiType[] typeParameters = myAddAllCall.getMethodExpression().getTypeParameters(); String generic = ""; if (typeParameters.length == 1) { generic = "<" + typeParameters[0].getCanonicalText() + ">"; } String method = MethodCallUtils.isVarArgCall(myAddAllCall) ? JAVA_UTIL_STREAM_STREAM + "." + generic + "of" : JAVA_UTIL_ARRAYS + "." + generic + "stream"; nestedStreamSource = StreamEx.of(myAddAllCall.getArgumentList().getExpressions()).skip(1).map(ct::text) .joining(",", method + "(", ")"); String lambda = myElement.getName() + "->" + nestedStreamSource; return myElement.getType() instanceof PsiPrimitiveType ? ".mapToObj(" + lambda + ").flatMap(" + JAVA_UTIL_FUNCTION_FUNCTION + ".identity())" : ".flatMap(" + lambda + ")"; } }