in sources/java-incremental-compilation/jvm-inc-builder/src/com/intellij/tools/build/bazel/org/jdom/Document.java [684:731]
public void canContainContent(Content child, int index, boolean replace) {
if (child instanceof Element) {
int cre = content.indexOfFirstElement();
if (replace && cre == index) {
return;
}
if (cre >= 0) {
throw new IllegalAddException(
"Cannot add a second root element, only one is allowed");
}
if (content.indexOfDocType() >= index) {
throw new IllegalAddException(
"A root element cannot be added before the DocType");
}
}
if (child instanceof DocType) {
int cdt = content.indexOfDocType();
if (replace && cdt == index) {
// It's OK to replace an existing DocType
return;
}
if (cdt >= 0) {
throw new IllegalAddException(
"Cannot add a second doctype, only one is allowed");
}
int firstElt = content.indexOfFirstElement();
if (firstElt != -1 && firstElt < index) {
throw new IllegalAddException(
"A DocType cannot be added after the root element");
}
}
if (child instanceof CDATA) {
throw new IllegalAddException("A CDATA is not allowed at the document root");
}
if (child instanceof Text) {
if (Verifier.isAllXMLWhitespace(((Text)child).getText())) {
// only whitespace, not a problem.
return;
}
throw new IllegalAddException("A Text is not allowed at the document root");
}
if (child instanceof EntityRef) {
throw new IllegalAddException("An EntityRef is not allowed at the document root");
}
}