@Override protected Expression preEvaluate() { if (Literal.hasEffectiveBooleanValue(getLhsExpression(), true) || Literal.hasEffectiveBooleanValue(getRhsExpression(), true)) { // A or true() => true() // true() or B => true() return Literal.makeLiteral(BooleanValue.TRUE, this); } else if (Literal.hasEffectiveBooleanValue(getLhsExpression(), false)) { // false() or B => B return forceToBoolean(getRhsExpression()); } else if (Literal.hasEffectiveBooleanValue(getRhsExpression(), false)) { // A or false() => A return forceToBoolean(getLhsExpression()); } else { return this; } }
@Override protected Expression preEvaluate() { if (Literal.hasEffectiveBooleanValue(getLhsExpression(), true) || Literal.hasEffectiveBooleanValue(getRhsExpression(), true)) { // A or true() => true() // true() or B => true() return Literal.makeLiteral(BooleanValue.TRUE, this); } else if (Literal.hasEffectiveBooleanValue(getLhsExpression(), false)) { // false() or B => B return forceToBoolean(getRhsExpression()); } else if (Literal.hasEffectiveBooleanValue(getRhsExpression(), false)) { // A or false() => A return forceToBoolean(getLhsExpression()); } else { return this; } }
@Override /*@NotNull*/ public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { conditionOp.optimize(visitor, contextItemType); if (Literal.hasEffectiveBooleanValue(getCondition(), true)) { return getDocumentSorter(); } else if (Literal.hasEffectiveBooleanValue(getCondition(), false)) { return getDocumentSorter().getBaseExpression(); } return this; }
@Override /*@NotNull*/ public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { conditionOp.optimize(visitor, contextItemType); if (Literal.hasEffectiveBooleanValue(getCondition(), true)) { return getDocumentSorter(); } else if (Literal.hasEffectiveBooleanValue(getCondition(), false)) { return getDocumentSorter().getBaseExpression(); } return this; }
@Override protected Expression preEvaluate() { // If the value can be determined from knowledge of one operand, precompute the result if (Literal.isConstantBoolean(getLhsExpression(), false) || Literal.isConstantBoolean(getRhsExpression(), false)) { // A and false() => false() // false() and B => false() return Literal.makeLiteral(BooleanValue.FALSE, this); } else if (Literal.hasEffectiveBooleanValue(getLhsExpression(), true)) { // true() and B => B return forceToBoolean(getRhsExpression()); } else if (Literal.hasEffectiveBooleanValue(getRhsExpression(), true)) { // A and true() => A return forceToBoolean(getLhsExpression()); } else { return this; } }
@Override protected Expression preEvaluate() { // If the value can be determined from knowledge of one operand, precompute the result if (Literal.isConstantBoolean(getLhsExpression(), false) || Literal.isConstantBoolean(getRhsExpression(), false)) { // A and false() => false() // false() and B => false() return Literal.makeLiteral(BooleanValue.FALSE, this); } else if (Literal.hasEffectiveBooleanValue(getLhsExpression(), true)) { // true() and B => B return forceToBoolean(getRhsExpression()); } else if (Literal.hasEffectiveBooleanValue(getRhsExpression(), true)) { // A and true() => A return forceToBoolean(getLhsExpression()); } else { return this; } }
/** * Compute the cardinality of the sequence returned by evaluating this instruction * * @return the static cardinality */ public int computeCardinality() { int card = 0; boolean includesTrue = false; for (int i = 0; i < size(); i++) { card = Cardinality.union(card, getAction(i).getCardinality()); if (Literal.hasEffectiveBooleanValue(getCondition(i), true)) { includesTrue = true; } } if (!includesTrue) { // we may drop off the end and return an empty sequence (typical for xsl:if) card = Cardinality.union(card, StaticProperty.ALLOWS_ZERO); } return card; }
/** * Compute the cardinality of the sequence returned by evaluating this instruction * * @return the static cardinality */ public int computeCardinality() { int card = 0; boolean includesTrue = false; for (int i = 0; i < size(); i++) { card = Cardinality.union(card, getAction(i).getCardinality()); if (Literal.hasEffectiveBooleanValue(getCondition(i), true)) { includesTrue = true; } } if (!includesTrue) { // we may drop off the end and return an empty sequence (typical for xsl:if) card = Cardinality.union(card, StaticProperty.ALLOWS_ZERO); } return card; }
for (int i = 0; i < size; i++) { Expression condition = getCondition(i); if (!Literal.hasEffectiveBooleanValue(condition, false)) { conditions.add(condition); actions.add(getAction(i)); if (Literal.hasEffectiveBooleanValue(condition, true)) { break; ExpressionTool.copyLocationInfo(this, lit); return lit; } else if (conditions.size() == 1 && Literal.hasEffectiveBooleanValue(conditions.get(0), true)) { return actions.get(0); } else if (conditions.size() != size) { if (size() == 1 && Literal.hasEffectiveBooleanValue(getCondition(0), true)) { return getAction(0); if (Literal.hasEffectiveBooleanValue(getCondition(size - 1), true) && getAction(size - 1) instanceof Choose) { Choose choose2 = (Choose) getAction(size - 1); Literal.isConstantBoolean(getAction(0), true) && Literal.isConstantBoolean(getAction(1), false) && Literal.hasEffectiveBooleanValue(getCondition(1), true)) { TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); if (th.isSubType(getCondition(0).getItemType(), BuiltInAtomicType.BOOLEAN) &&
for (int i = 0; i < size; i++) { Expression condition = getCondition(i); if (!Literal.hasEffectiveBooleanValue(condition, false)) { conditions.add(condition); actions.add(getAction(i)); if (Literal.hasEffectiveBooleanValue(condition, true)) { break; ExpressionTool.copyLocationInfo(this, lit); return lit; } else if (conditions.size() == 1 && Literal.hasEffectiveBooleanValue(conditions.get(0), true)) { return actions.get(0); } else if (conditions.size() != size) { if (size() == 1 && Literal.hasEffectiveBooleanValue(getCondition(0), true)) { return getAction(0); if (Literal.hasEffectiveBooleanValue(getCondition(size - 1), true) && getAction(size - 1) instanceof Choose) { Choose choose2 = (Choose) getAction(size - 1); Literal.isConstantBoolean(getAction(0), true) && Literal.isConstantBoolean(getAction(1), false) && Literal.hasEffectiveBooleanValue(getCondition(1), true)) { TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); if (th.isSubType(getCondition(0).getItemType(), BuiltInAtomicType.BOOLEAN) &&
if (!Literal.hasEffectiveBooleanValue(getCondition(size - 1), true) && !Cardinality.allowsZero(req.getCardinality())) { Expression[] c = new Expression[size + 1];
if (!Literal.hasEffectiveBooleanValue(getCondition(size - 1), true) && !Cardinality.allowsZero(req.getCardinality())) { Expression[] c = new Expression[size + 1];
adoptChildExpression(ebv); if (Literal.hasEffectiveBooleanValue(ebv, true)) { return e2; } else if (Literal.hasEffectiveBooleanValue(ebv, false)) {
adoptChildExpression(ebv); if (Literal.hasEffectiveBooleanValue(ebv, true)) { return e2; } else if (Literal.hasEffectiveBooleanValue(ebv, false)) {
if (Literal.isEmptySequence(getAction(i)) || Literal.hasEffectiveBooleanValue(getCondition(i), false)) { setAction(i, new ErrorExpression(err)); } else {
if (Literal.isEmptySequence(getAction(i)) || Literal.hasEffectiveBooleanValue(getCondition(i), false)) { setAction(i, new ErrorExpression(err)); } else {