Object (Object contextNode) { if (contextNode instanceof XmlDocument) { return contextNode; } while (contextNode instanceof PsiElement) { if (contextNode instanceof XmlDocument) { return contextNode; } contextNode = ((PsiElement)contextNode).getParent(); } return null; }