TextRange (XPathElement expr) { final PsiLanguageInjectionHost host = PsiTreeUtil.getContextOfType(expr, PsiLanguageInjectionHost.class, true); assert host != null; final List<Pair<PsiElement,TextRange>> psi = InjectedLanguageManager.getInstance(host.getProject()).getInjectedPsiFiles(host); assert psi != null; for (Pair<PsiElement, TextRange> pair : psi) { if (PsiTreeUtil.isAncestor(pair.first, expr, false)) { return pair.second; } } assert false; return null; }