/** * Type-check the expression * @return the checked expression */ public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { operand = visitor.typeCheck(operand, contextItemType); if (operand instanceof Literal) { return Literal.makeLiteral( (AtomicValue)evaluateItem(visitor.getStaticContext().makeEarlyEvaluationContext())); } // See if we can get the answer by static analysis. if (Cardinality.subsumes(targetCardinality, operand.getCardinality())) { final TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); int relation = th.relationship(operand.getItemType(th), targetType); if (relation == TypeHierarchy.SAME_TYPE || relation == TypeHierarchy.SUBSUMED_BY) { return Literal.makeLiteral(BooleanValue.TRUE); } else if (relation == TypeHierarchy.DISJOINT) { // if the item types are disjoint, the result might still be true if both sequences are empty if (!Cardinality.allowsZero(targetCardinality) || !Cardinality.allowsZero(operand.getCardinality())) { return Literal.makeLiteral(BooleanValue.FALSE); } } } return this; }
/** * Type-check the expression * @return the checked expression */ public Expression typeCheck(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { operand = visitor.typeCheck(operand, contextItemType); if (operand instanceof Literal) { return Literal.makeLiteral( (AtomicValue)evaluateItem(visitor.getStaticContext().makeEarlyEvaluationContext())); } // See if we can get the answer by static analysis. if (Cardinality.subsumes(targetCardinality, operand.getCardinality())) { final TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); int relation = th.relationship(operand.getItemType(th), targetType); if (relation == TypeHierarchy.SAME_TYPE || relation == TypeHierarchy.SUBSUMED_BY) { return Literal.makeLiteral(BooleanValue.TRUE); } else if (relation == TypeHierarchy.DISJOINT) { // if the item types are disjoint, the result might still be true if both sequences are empty if (!Cardinality.allowsZero(targetCardinality) || !Cardinality.allowsZero(operand.getCardinality())) { return Literal.makeLiteral(BooleanValue.FALSE); } } } return this; }
if (operand instanceof Literal) { Literal lit = Literal.makeLiteral( evaluateItem(visitor.getStaticContext().makeEarlyEvaluationContext()), this); ExpressionTool.copyLocationInfo(this, lit); return lit;
if (operand instanceof Literal) { Literal lit = Literal.makeLiteral( evaluateItem(visitor.getStaticContext().makeEarlyEvaluationContext()), this); ExpressionTool.copyLocationInfo(this, lit); return lit;