/** * Get the value represented by this Literal * * @return the constant value */ @Override public StringValue getValue() { return (StringValue)super.getValue(); }
/** * Compute the static properties of this expression (other than its type). For a * Value, the only special property is {@link StaticProperty#NON_CREATIVE}. * @return the value {@link StaticProperty#NON_CREATIVE} */ public int computeSpecialProperties() { if (getValue() instanceof EmptySequence) { // An empty sequence has all special properties except "has side effects". return StaticProperty.SPECIAL_PROPERTY_MASK &~ StaticProperty.HAS_SIDE_EFFECTS; } return StaticProperty.NON_CREATIVE; }
/** * Test whether the literal wraps an atomic value. (Note, if this method returns false, * this still leaves the possibility that the literal wraps a sequence that happens to contain * a single atomic value). * * @param exp an expression * @return true if the expression is a literal and the literal wraps an AtomicValue */ public static boolean isAtomic(Expression exp) { return exp instanceof Literal && ((Literal) exp).getValue() instanceof AtomicValue; }
/** * Test whether the literal wraps an atomic value. (Note, if this method returns false, * this still leaves the possibility that the literal wraps a sequence that happens to contain * a single atomic value). * * @param exp an expression * @return true if the expression is a literal and the literal wraps an AtomicValue */ public static boolean isAtomic(Expression exp) { return exp instanceof Literal && ((Literal) exp).getValue() instanceof AtomicValue; }
/** * Get the value represented by this Literal * * @return the constant value */ @Override public StringValue getValue() { return (StringValue)super.getValue(); }
/** * Compute the static properties of this expression (other than its type). For a * Value, the only special property is {@link StaticProperty#NON_CREATIVE}. * @return the value {@link StaticProperty#NON_CREATIVE} */ public int computeSpecialProperties() { if (getValue() instanceof EmptySequence) { // An empty sequence has all special properties except "has side effects". return StaticProperty.SPECIAL_PROPERTY_MASK &~ StaticProperty.HAS_SIDE_EFFECTS; } return StaticProperty.NON_CREATIVE; }
/** * Test whether the literal wraps an atomic value. (Note, if this method returns false, * this still leaves the possibility that the literal wraps a sequence that happens to contain * a single atomic value). * @param exp an expression * @return if the expression is a literal and the literal wraps an AtomicValue */ public static boolean isAtomic(Expression exp) { return exp instanceof Literal && ((Literal)exp).getValue() instanceof AtomicValue; }
/** * Test whether the literal explicitly wraps an empty sequence. (Note, if this method returns false, * this still leaves the possibility that the literal wraps a sequence that happens to be empty). * * @param exp an expression * @return true if the expression is a literal and the value of the literal is an empty sequence */ public static boolean isEmptySequence(Expression exp) { return exp instanceof Literal && ((Literal) exp).getValue().getLength() == 0; }
/** * Simplify an expression * @param visitor an expression visitor */ public Expression simplify(ExpressionVisitor visitor) throws XPathException { operand = visitor.simplify(operand); if (operand instanceof Literal && ((Literal)(operand)).getValue() instanceof AtomicValue) { return operand; } return this; }
/** * Test whether the literal explicitly wraps an empty sequence. (Note, if this method returns false, * this still leaves the possibility that the literal wraps a sequence that happens to be empty). * * @param exp an expression * @return true if the expression is a literal and the value of the literal is an empty sequence */ public static boolean isEmptySequence(Expression exp) { return exp instanceof Literal && ((Literal) exp).getValue().getLength() == 0; }
/** * Simplify an expression * @param visitor an expression visitor */ public Expression simplify(ExpressionVisitor visitor) throws XPathException { operand = visitor.simplify(operand); if (operand instanceof Literal && ((Literal)(operand)).getValue() instanceof AtomicValue) { return operand; } return this; }
/** * Make an AdjacentTextNodeMerger expression with a given operand, or a simpler equivalent expression if appropriate * * @param base the operand expression * @return an AdjacentTextNodeMerger or equivalent expression */ public static Expression makeAdjacentTextNodeMerger(Expression base) { if (base instanceof Literal && ((Literal) base).getValue() instanceof AtomicSequence) { return base; } else { return new AdjacentTextNodeMerger(base); } }
@Override public Expression simplify() throws XPathException { Expression operand = getBaseExpression(); if (operand instanceof Literal && ((Literal) operand).getValue() instanceof AtomicValue) { return operand; } else { return super.simplify(); } }
/** * Simplify an expression * */ /*@NotNull*/ public Expression simplify() throws XPathException { Expression operand = getBaseExpression().simplify(); if (operand instanceof Literal && ((Literal) operand).getValue() instanceof AtomicValue) { return operand; } setBaseExpression(operand); return this; }
public void localTypeCheck(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { // Do early checking of content if known statically if (select instanceof Literal) { String s = ((Literal)select).getValue().getStringValue(); String s2 = checkContent(s, visitor.getStaticContext().makeEarlyEvaluationContext()); if (!s2.equals(s)) { setSelect(new StringLiteral(s2), visitor.getConfiguration()); } } }
public void localTypeCheck(ExpressionVisitor visitor, ItemType contextItemType) throws XPathException { // Do early checking of content if known statically if (select instanceof Literal) { String s = ((Literal)select).getValue().getStringValue(); String s2 = checkContent(s, visitor.getStaticContext().makeEarlyEvaluationContext()); if (!s2.equals(s)) { setSelect(new StringLiteral(s2), visitor.getConfiguration()); } } }
public void localTypeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { // Do early checking of content if known statically if (getSelect() instanceof Literal) { String s = ((Literal) getSelect()).getValue().getStringValue(); String s2 = checkContent(s, visitor.getStaticContext().makeEarlyEvaluationContext()); if (!s2.equals(s)) { setSelect(new StringLiteral(s2)); } } }
public void localTypeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { // Do early checking of content if known statically if (getSelect() instanceof Literal) { String s = ((Literal) getSelect()).getValue().getStringValue(); String s2 = checkContent(s, visitor.getStaticContext().makeEarlyEvaluationContext()); if (!s2.equals(s)) { setSelect(new StringLiteral(s2)); } } }
@Override public void refineVariableType(ExpressionVisitor visitor, List<VariableReference> references, Expression returnExpr) { final Expression seq = getSequence(); final ItemType actualItemType = seq.getItemType(); for (VariableReference ref : references) { ref.refineVariableType(actualItemType, getSequence().getCardinality(), seq instanceof Literal ? ((Literal) seq).getValue() : null, seq.getSpecialProperties()); ExpressionTool.resetStaticProperties(returnExpr); } }
@Override public void refineVariableType(ExpressionVisitor visitor, List<VariableReference> references, Expression returnExpr) { final ItemType actualItemType = getPredicate().getItemType(); for (VariableReference ref : references) { ref.refineVariableType(actualItemType, getPredicate().getCardinality(), getPredicate() instanceof Literal ? ((Literal) getPredicate()).getValue() : null, getPredicate().getSpecialProperties()); ExpressionTool.resetStaticProperties(returnExpr); } }