XmlFile (PsiElement element) { while (!(element instanceof XmlFile) && element != null) { final PsiElement context = element.getContext(); if (context == null) { //todo Dmitry Avdeev: either XmlExtension should work on any PsiFile (not just XmlFile), or you need to handle elements from JspJavaFile in some other way final XmlExtension extension = XmlExtension.getExtensionByElement(element); if (extension != null) { element = extension.getContainingFile(element); } } else { if (element == context) { LOG.error("Context==element: " + element.getClass()); return null; } element = context; } } return (XmlFile)element; }