* @return the root tag (existing, or newly created) - never {@code null}
* @throws IncorrectOperationException if the root already exists, but does not satisfy the tag
* path expression
*/
private XmlTag ensureRootTag() throws IncorrectOperationException {
final XmlDocument xmlDocument = ensureXmlDocument();
XmlTag rootTag = xmlDocument.getRootTag();
if (rootTag != null) {
final String rootTagName = rootTag.getName();
if (!rootTagName.equals(parseRootTagName()))
throw new IncorrectOperationException(
RES.get("incorrect.root.tag", rootTagName));
else
return rootTag;
}
final Project project = file.getProject();
final PsiManager psiMgr = PsiManager.getInstance(project);
final PsiElementFactory eltFactory = psiMgr.getElementFactory();
final String tagExpr = "<" + parseRootTagName() + "/>";
rootTag = eltFactory.createTagFromText(tagExpr);
return (XmlTag) xmlDocument.add(rootTag);
}