* @param th the type hierarchy cache
* @return the item type of the result of evaluating the operand expression, after atomization
*/
public static ItemType getAtomizedItemType(Expression operand, boolean alwaysUntyped, TypeHierarchy th) {
ItemType in = operand.getItemType(th);
if (in.isAtomicType()) {
return in;
}
if (in instanceof NodeTest) {
if (in instanceof EmptySequenceTest) {
return in;
}
int kinds = ((NodeTest)in).getNodeKindMask();
if (alwaysUntyped) {
// Some node-kinds always have a typed value that's a string
if ((kinds | STRING_KINDS) == STRING_KINDS) {
return BuiltInAtomicType.STRING;
}
// Some node-kinds are always untyped atomic; some are untypedAtomic provided that the configuration
// is untyped
if ((kinds | UNTYPED_IF_UNTYPED_KINDS) == UNTYPED_IF_UNTYPED_KINDS) {
return BuiltInAtomicType.UNTYPED_ATOMIC;
}
} else {
if ((kinds | UNTYPED_KINDS) == UNTYPED_KINDS) {
return BuiltInAtomicType.UNTYPED_ATOMIC;
}
}
return in.getAtomizedItemType();
}
return BuiltInAtomicType.ANY_ATOMIC;
}