XmlElementDescriptor (@NotNull XmlTag tag) { if (myPattern == null) { return null; } XmlTag _tag = tag; final LinkedList<XmlTag> chain = new LinkedList<>(); while (_tag != null) { chain.addFirst(_tag); _tag = _tag.getParentTag(); } XmlElementDescriptor desc; do { desc = findRootDescriptor(chain.removeFirst()); } while (desc == null && chain.size() > 0); if (desc != null) { for (XmlTag xmlTag : chain) { desc = desc.getElementDescriptor(xmlTag, xmlTag.getParentTag()); if (desc == null) { break; } } } if (desc == null || desc instanceof AnyXmlElementDescriptor) { return findRootDescriptor(tag); } return desc; }