public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException {
localTypeCheck(visitor, contextItemType);
if (select != null) {
final TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy();
select = visitor.typeCheck(select, contextItemType);
if (select instanceof ValueOf) {
Expression valSelect = ((ValueOf)select).getSelect();
if (th.isSubType(valSelect.getItemType(th), BuiltInAtomicType.STRING) &&
!Cardinality.allowsMany(valSelect.getCardinality())) {
select = valSelect;
}
}
if (!select.getItemType(th).isAtomicType()) {
Atomizer atomizer = new Atomizer(select);
ExpressionTool.copyLocationInfo(select, atomizer);
select = visitor.simplify(atomizer);
select = visitor.typeCheck(atomizer, contextItemType);
}
ItemType itemType = select.getItemType(th);
if (!(th.isSubType(itemType, BuiltInAtomicType.STRING) ||
th.isSubType(itemType, BuiltInAtomicType.UNTYPED_ATOMIC))) {
select = new AtomicSequenceConverter(select, BuiltInAtomicType.STRING);
}
// Don't bother converting untypedAtomic to string
if (select instanceof StringFn) {
StringFn fn = (StringFn)select;