PsiElement () { final XmlTag tag = PsiTreeUtil.getContextOfType(myElement, XmlTag.class, false); if (tag == null) return null; String canonicalText = getCanonicalText(); boolean[] redefined = new boolean[1]; XsdNsDescriptor nsDescriptor = getDescriptor(tag, canonicalText, redefined); if (myType != null && nsDescriptor != null) { return switch (myType) { case GroupReference -> nsDescriptor.findGroup(canonicalText); case AttributeGroupReference -> nsDescriptor.findAttributeGroup(canonicalText); case ElementReference -> { XmlElementDescriptor descriptor = nsDescriptor.getElementDescriptor( XmlUtil.findLocalNameByQualifiedName(canonicalText), getNamespace(tag, canonicalText), new HashSet<>(), true ); yield descriptor != null ? descriptor.getDeclaration() : null; } case AttributeReference -> { //final String prefixByQualifiedName = XmlUtil.findPrefixByQualifiedName(canonicalText); final String localNameByQualifiedName = XmlUtil.findLocalNameByQualifiedName(canonicalText); XmlAttributeDescriptor descriptor = nsDescriptor.getAttribute( localNameByQualifiedName, getNamespace(tag, canonicalText), tag ); if (descriptor != null) yield descriptor.getDeclaration(); yield null; } case TypeReference -> { TypeDescriptor typeDescriptor = redefined[0] ? nsDescriptor.findTypeDescriptor(XmlUtil.findLocalNameByQualifiedName(canonicalText), "") : nsDescriptor.getTypeDescriptor(canonicalText, tag); if (typeDescriptor instanceof ComplexTypeDescriptor) { yield typeDescriptor.getDeclaration(); } else if (typeDescriptor != null) { yield myElement; } yield null; } }; } return null; }