in sources/java-incremental-compilation/jvm-inc-builder/src/com/intellij/tools/build/bazel/org/jdom/output/XMLOutputter.java [747:808]
private void printTextRange(Writer out, List content, int start, int end) throws IOException {
String previous; // Previous text printed
Object node; // Next node to print
String next; // Next text to print
previous = null;
// Remove leading whitespace-only nodes
start = skipLeadingWhite(content, start);
int size = content.size();
if (start < size) {
// And remove trialing whitespace-only nodes
end = skipTrailingWhite(content, end);
for (int i = start; i < end; i++) {
node = content.get(i);
// Get the unmangled version of the text
// we are about to print
if (node instanceof Text) {
next = ((Text)node).getText();
}
else if (node instanceof EntityRef) {
next = "&" + ((EntityRef)node).getValue() + ";";
}
else {
throw new IllegalStateException("Should see only CDATA, Text, or EntityRef");
}
// This may save a little time
if (next == null || next.isEmpty()) {
continue;
}
// Determine if we need to pad the output (padding is
// only need in trim or normalizing mode)
if (previous != null) { // Not 1st node
if (currentFormat.mode == Format.TextMode.NORMALIZE ||
currentFormat.mode == Format.TextMode.TRIM) {
if ((endsWithWhite(previous)) ||
(startsWithWhite(next))) {
out.write(" ");
}
}
}
// Print the node
if (node instanceof CDATA) {
printCDATA(out, (CDATA)node);
}
else if (node instanceof EntityRef) {
printEntityRef(out, (EntityRef)node);
}
else {
printString(out, next);
}
previous = next;
}
}
}