if (e != this) {
return e;
}
// This wrapper expression is unnecessary if the base expression cannot return text nodes,
// or if it can return at most one item
TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy();
if (th.relationship(getBaseExpression().getItemType(th), NodeKindTest.TEXT) == TypeHierarchy.DISJOINT) {
return getBaseExpression();
}
if (!Cardinality.allowsMany(getBaseExpression().getCardinality())) {
return getBaseExpression();
}
// In a choose expression, we can push the wrapper down to the action branches (whence it may disappear)
if (getBaseExpression() instanceof Choose) {
Choose choose = (Choose) getBaseExpression();
Expression[] actions = choose.getActions();
for (int i=0; i<actions.length; i++) {
AdjacentTextNodeMerger atm2 = new AdjacentTextNodeMerger(actions[i]);
actions[i] = atm2.typeCheck(visitor, contextItemType);
}
return choose;
}
// In a Block expression, check whether adjacent text nodes can occur (used in test strmode089)
// Code deleted:
if (getBaseExpression() instanceof Block) {
Block block = (Block) getBaseExpression();
Expression[] actions = block.getChildren();
boolean prevtext = false;
boolean needed = false;
boolean maybeEmpty = false;
for (int i=0; i<actions.length; i++) {
boolean maybetext;
if (actions[i] instanceof ValueOf) {
maybetext = true;
Expression content = ((ValueOf)actions[i]).getContentExpression();
if (content instanceof StringLiteral) {
// if it's empty, we could remove it now, but that's awkward and probably doesn't happen
maybeEmpty |= ((StringLiteral)content).getStringValue().length() == 0;
} else {
maybeEmpty = true;
}
} else {
maybetext = th.relationship(actions[i].getItemType(th), NodeKindTest.TEXT) != TypeHierarchy.DISJOINT;
maybeEmpty |= maybetext;
}
if (prevtext && maybetext) {
needed = true;
break; // may contain adjacent text nodes