String () { beforeApplyingModifications(); // Move closing quotes to the next line, if new lines are going to be inserted if (myOriginalDocString.getLineCount() == 1 && !myUpdates.isEmpty()) { insertAfterLine(0, myMinContentIndent); } // If several updates insert in one place (e.g. new field), insert them in backward order, // so the first added is placed above Collections.reverse(myUpdates); myUpdates.sort(Collections.reverseOrder()); for (final Modification update : myUpdates) { final TextRange updateRange = update.range; if (updateRange.getStartOffset() == updateRange.getEndOffset()) { myBuilder.insert(updateRange.getStartOffset(), update.text); } else { myBuilder.replace(updateRange.getStartOffset(), updateRange.getEndOffset(), update.text); } } return myBuilder.toString(); }