Object (Object object, final String elementId) { final XmlTag rootTag = ((XmlFile)((XmlElement)object).getContainingFile()).getRootTag(); if (rootTag == null) { return null; } final Ref<XmlTag> ref = new Ref<>(); rootTag.accept(new XmlRecursiveElementVisitor() { @Override public void visitElement(@NotNull PsiElement element) { if (ref.get() == null) { super.visitElement(element); } } @Override public void visitXmlAttribute(@NotNull XmlAttribute attribute) { final XmlAttributeDescriptor descriptor = attribute.getDescriptor(); final String value = attribute.getValue(); if ((value != null && (descriptor != null && descriptor.hasIdType()))) { if (elementId.equals(value)) { ref.set(attribute.getParent()); } } } }); return ref.get(); }