in sources/java-incremental-compilation/jvm-inc-builder/src/com/intellij/tools/build/bazel/org/jdom/output/XMLOutputter.java [583:670]
private void printElement(Writer out, Element element, int level, NamespaceStack namespaces) throws IOException {
List<Attribute> attributes = element.getAttributes();
List<Content> content = element.getContent();
// Check for xml:space and adjust format settings
String space = null;
if (attributes != null) {
space = element.getAttributeValue("space", Namespace.XML_NAMESPACE);
}
Format previousFormat = currentFormat;
if ("default".equals(space)) {
currentFormat = userFormat;
}
else if ("preserve".equals(space)) {
currentFormat = preserveFormat;
}
// Print the beginning of the tag plus attributes and any
// necessary namespace declarations
out.write("<");
printQualifiedName(out, element);
// Mark our namespace starting point
int previouslyDeclaredNamespaces = namespaces.size();
// Print the element's namespace, if appropriate
printElementNamespace(out, element, namespaces);
// Print out additional namespace declarations
printAdditionalNamespaces(out, element, namespaces);
// Print out attributes
if (attributes != null) {
printAttributes(out, attributes, namespaces);
}
// Depending on the settings (newlines, textNormalize, etc), we may
// or may not want to print all of the content, so determine the
// index of the start of the content we're interested
// in based on the current settings.
int start = skipLeadingWhite(content, 0);
int size = content.size();
if (start >= size) {
// Case content is empty or all insignificant whitespace
if (currentFormat.expandEmptyElements) {
out.write("></");
printQualifiedName(out, element);
out.write(">");
}
else {
out.write(" />");
}
}
else {
out.write(">");
// For a special case where the content is only CDATA
// or Text we don't want to indent after the start or
// before the end tag.
if (nextNonText(content, start) < size) {
// Case Mixed Content - normal indentation
newline(out);
printContentRange(out, content, start, size,
level + 1, namespaces);
newline(out);
indent(out, level);
}
else {
// Case all CDATA or Text - no indentation
printTextRange(out, content, start, size);
}
out.write("</");
printQualifiedName(out, element);
out.write(">");
}
// remove declared namespaces from stack
while (namespaces.size() > previouslyDeclaredNamespaces) {
namespaces.pop();
}
// Restore our format settings
currentFormat = previousFormat;
}