@Override public boolean effectiveBooleanValue(XPathContext context) throws XPathException { String s0 = getArg(0).evaluateAsString(context).toString(); String s1 = getArg(1).evaluateAsString(context).toString(); return s0.endsWith(s1); } };
@Override public String toString() { if (original != null) { return original.toString(); } else { return "error(\"" + message + "\")"; } }
/** * Diagnostic print of expression structure. The abstract expression tree * is written to the supplied output destination. */ public void explain(ExpressionPresenter destination) { destination.startElement("path"); start.explain(destination); step.explain(destination); destination.endElement(); }
/** * Compute the static properties. This should only be done once for each * expression. */ public final void computeStaticProperties() { staticProperties = computeDependencies() | computeCardinality() | computeSpecialProperties(); }
@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); } }
public Expression optimize(ExpressionVisitor visitor, ContextItemStaticInfo contextItemType) throws XPathException { optimizeChildren(visitor, contextItemType); if (getSelect().isCallOn(String_1.class)) { SystemFunctionCall sf = (SystemFunctionCall) getSelect(); TypeHierarchy th = visitor.getConfiguration().getTypeHierarchy(); if (th.isSubType(sf.getArg(0).getItemType(), BuiltInAtomicType.STRING) && !Cardinality.allowsMany(sf.getArg(0).getCardinality())) { setSelect(sf.getArg(0)); } } return this; }
@Override public Expression typeCheck(ExpressionVisitor visitor, ContextItemStaticInfo contextInfo) throws XPathException { Expression e = super.typeCheck(visitor, contextInfo); if (e != this) { return e; } return preEvaluate(visitor); }
/** * Determine the cardinality of the function. */ public int getCardinality(Expression[] arguments) { return arguments[0].getCardinality() | StaticProperty.ALLOWS_ZERO_OR_ONE; }
public ItemType getOperandItemType() { if (operandItemType == null) { operandItemType = getBaseExpression().getItemType(); } return operandItemType; }
public static void trace(Configuration config, String message, Expression exp) { if (config.getBooleanProperty(Feature.TRACE_OPTIMIZER_DECISIONS)) { Logger err = config.getLogger(); err.info("OPT : At line " + exp.getLocation().getLineNumber() + " of " + exp.getLocation().getSystemId()); err.info("OPT : " + message); err.info("OPT : Expression after rewrite: " + exp.toString()); exp.verifyParentPointers(); } }
@Override public void refineVariableType(ExpressionVisitor visitor, List<VariableReference> references, Expression returnExpr) { ItemType actualItemType = getSequence().getItemType(); if (actualItemType instanceof ErrorType) { actualItemType = AnyItemType.getInstance(); } for (VariableReference ref : references) { ref.refineVariableType(actualItemType, allowsEmpty ? StaticProperty.ALLOWS_ZERO_OR_ONE : StaticProperty.EXACTLY_ONE, null, getSequence().getSpecialProperties()); } }
/** * Iterate over the results of the function */ public SequenceIterator iterate(XPathContext context) throws XPathException { if (context.getController().isTracing()) { String label = argument[1].evaluateAsString(context).toString(); Value value = Value.asValue(ExpressionTool.eagerEvaluate(argument[0], context)); notifyListener(label, value, context); return value.iterate(); } else { return new TracingIterator(argument[0].iterate(context), argument[1].evaluateAsString(context).toString()); } }
/** * Ask whether a particular "special property" is present for this expression * @param property the property in question, as an integer code in the {@link StaticProperty} class * @return true if the given property is present */ public boolean hasSpecialProperty(int property) { return (getSpecialProperties() & property) != 0; }
/** * Check that any elements and attributes constructed or returned by this expression are acceptable * in the content model of a given complex type. It's always OK to say yes, since the check will be * repeated at run-time. The process of checking element and attribute constructors against the content * model of a complex type also registers the type of content expected of those constructors, so the * static validation can continue recursively. */ public void checkPermittedContents(SchemaType parentType, StaticContext env, boolean whole) throws XPathException { action.checkPermittedContents(parentType, env, false); }
public PathMap.PathMapNodeSet addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet) { PathMap.PathMapNodeSet result = getBaseExpression().addToPathMap(pathMap, pathMapNodeSet); if (result != null) { TypeHierarchy th = getConfiguration().getTypeHierarchy(); ItemType operandItemType = getBaseExpression().getItemType(); if (th.relationship(NodeKindTest.ELEMENT, operandItemType) != TypeHierarchy.DISJOINT || th.relationship(NodeKindTest.DOCUMENT, operandItemType) != TypeHierarchy.DISJOINT) { result.setAtomized(); } } return null; }
private Expression makeGetCall(ExpressionVisitor visitor, BuiltInFunctionSet fnSet, ContextItemStaticInfo contextInfo, Expression[] arguments) throws XPathException { Expression target = arguments[0]; Expression key = ((SquareArrayConstructor)arguments[1]).getOperanda().getOperand(0).getChildExpression(); Expression getter = fnSet.makeFunction("get", 2).makeFunctionCall(target, key); getter.setRetainedStaticContext(target.getRetainedStaticContext()); return getter.typeCheck(visitor, contextInfo); }
public PathMap.PathMapNodeSet addToPathMap(PathMap pathMap, PathMap.PathMapNodeSet pathMapNodeSet) { PathMap.PathMapNodeSet result = operand.addToPathMap(pathMap, pathMapNodeSet); if (result != null) { result.setAtomized(); } return null; }
/** * Compute the dependencies of an expression, as the union of the * dependencies of its subexpressions. (This is overridden for path expressions * and filter expressions, where the dependencies of a subexpression are not all * propogated). This method should be called only once, to compute the dependencies; * after that, getDependencies should be used. * @return the depencies, as a bit-mask */ public int computeDependencies() { return super.computeDependencies(); }
/** * Diagnostic print of expression structure. The abstract expression tree * is written to the supplied outputstream. * @param out the expression presenter used to display the structure */ public final void explain(OutputStream out) { ExpressionPresenter ep = new ExpressionPresenter(getExecutable().getConfiguration(), out); explain(ep); ep.close(); }
/** * Compute the static properties. This should only be done once for each * expression. */ public final void computeStaticProperties() { staticProperties = computeDependencies() | computeCardinality() | computeSpecialProperties(); }