String (@NotNull String text) { if (text.isEmpty()) return "\"\""; StringJoiner joiner = new StringJoiner(" +\n"); String[] lines = getTextBlockLines(text).split("\n", -1); for (int i = 0; i < lines.length; i++) { String line = lines[i]; boolean addNewLine = i != lines.length - 1; if (!addNewLine && line.isEmpty()) break; joiner.add("\"" + line + (addNewLine ? "\\n\"" : "\"")); } return joiner.toString(); }