XPathType (XPathExpression expression) { final XPathExpression parentExpr = PsiTreeUtil.getParentOfType(expression, XPathExpression.class); if (parentExpr != null) { final ExpectedTypeVisitor visitor = new ExpectedTypeVisitor(expression); parentExpr.accept(visitor); return mapType(expression, visitor.getExpectedType()); } else { return mapType(expression, expression.getXPathContext().getExpectedType(expression)); } }