private boolean isPredicatePattern(Expression exp) { if (exp instanceof ItemChecker) { exp = ((ItemChecker)exp).getBaseExpression(); } return exp instanceof FilterExpression && (((FilterExpression)exp).getSelectExpression() instanceof ContextItemExpression); }
/** * The toString() method for an expression attempts to give a representation of the expression * in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath. * In the case of XSLT instructions, the toString() method gives an abstracted view of the syntax */ public String toString() { String typeDesc = requiredItemType.toString(); return "(" + getBaseExpression() + ") treat as " + typeDesc; }
private boolean isPredicatePattern(Expression exp) { if (exp instanceof ItemChecker) { exp = ((ItemChecker)exp).getBaseExpression(); } return exp instanceof FilterExpression && (((FilterExpression)exp).getSelectExpression() instanceof ContextItemExpression); }
/** * The toString() method for an expression attempts to give a representation of the expression * in an XPath-like form, but there is no guarantee that the syntax will actually be true XPath. * In the case of XSLT instructions, the toString() method gives an abstracted view of the syntax */ public String toString() { String typeDesc = requiredItemType.toString(); return "(" + getBaseExpression() + ") treat as " + typeDesc; }
@Override public String toShortString() { return getBaseExpression().toShortString(); }
@Override public String toShortString() { return getBaseExpression().toShortString(); }
public AbstractExpression exprFor (ItemChecker checker) { Expression base = checker.getBaseExpression(); AbstractExpression baseExpr = exprFor(base); return baseExpr; }
/** * Get the mapping function used to implement this item check. This mapping function is applied * to each item in the input sequence. * * @param context The dynamic context used to evaluate the mapping function * @return the mapping function. This will be an identity mapping: the output sequence is the same * as the input sequence, unless the dynamic type checking reveals an error. */ public ItemMappingFunction<Item<?>, Item<?>> getMappingFunction(XPathContext context) { return new ItemTypeCheckingFunction(requiredItemType, role, getBaseExpression(), context.getConfiguration()); }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression */ public Expression copy() { return new ItemChecker(getBaseExpression().copy(), requiredItemType, role); }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression */ public Expression copy() { return new ItemChecker(getBaseExpression().copy(), requiredItemType, role); }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression */ public Expression copy() { return new ItemChecker(getBaseExpression().copy(), requiredItemType, role); }
/** * Get the mapping function used to implement this item check. This mapping function is applied * to each item in the input sequence. * * @param context The dynamic context used to evaluate the mapping function * @return the mapping function. This will be an identity mapping: the output sequence is the same * as the input sequence, unless the dynamic type checking reveals an error. */ public ItemMappingFunction<Item<?>, Item<?>> getMappingFunction(XPathContext context) { return new ItemTypeCheckingFunction(requiredItemType, role, getBaseExpression(), context.getConfiguration()); }
/** * Simplify an expression * */ /*@NotNull*/ public Expression simplify() throws XPathException { Expression operand = getBaseExpression().simplify(); if (requiredItemType instanceof AnyItemType) { return operand; } setBaseExpression(operand); return this; }
/** * Simplify an expression * */ /*@NotNull*/ public Expression simplify() throws XPathException { Expression operand = getBaseExpression().simplify(); if (requiredItemType instanceof AnyItemType) { return operand; } setBaseExpression(operand); return this; }
/** * Iterate over the sequence of values */ /*@NotNull*/ public SequenceIterator<?> iterate(XPathContext context) throws XPathException { SequenceIterator<?> base = getBaseExpression().iterate(context); return new ItemMappingIterator<>(base, getMappingFunction(context), true); }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression * @param rebindings variable bindings that need to be changed */ /*@NotNull*/ public Expression copy(RebindingMap rebindings) { ItemChecker exp = new ItemChecker(getBaseExpression().copy(rebindings), requiredItemType, role); ExpressionTool.copyLocationInfo(this, exp); return exp; }
/** * Iterate over the sequence of values */ /*@NotNull*/ public SequenceIterator<?> iterate(XPathContext context) throws XPathException { SequenceIterator<?> base = getBaseExpression().iterate(context); return new ItemMappingIterator<>(base, getMappingFunction(context), true); }
/** * Copy an expression. This makes a deep copy. * * @return the copy of the original expression * @param rebindings variable bindings that need to be changed */ /*@NotNull*/ public Expression copy(RebindingMap rebindings) { ItemChecker exp = new ItemChecker(getBaseExpression().copy(rebindings), requiredItemType, role); ExpressionTool.copyLocationInfo(this, exp); return exp; }
/** * Diagnostic print of expression structure. The abstract expression tree * is written to the supplied output destination. */ public void export(ExpressionPresenter out) throws XPathException { out.startElement("treat", this); out.emitAttribute("as", requiredItemType.toExportString()); if ("JS".equals(((ExpressionPresenter.ExportOptions) out.getOptions()).target)) { int targetVersion = ((ExpressionPresenter.ExportOptions) out.getOptions()).targetVersion; out.emitAttribute("jsTest", requiredItemType.generateJavaScriptItemTypeTest(getBaseExpression().getItemType(), targetVersion)); } out.emitAttribute("diag", role.save()); getBaseExpression().export(out); out.endElement(); }
/** * Convert this expression to an equivalent XSLT pattern * * @param config the Saxon configuration * @return the equivalent pattern * @throws net.sf.saxon.trans.XPathException if conversion is not possible */ @Override public Pattern toPattern(Configuration config) throws XPathException { SystemFunction fn = getTargetFunction(); if (fn instanceof Root_1) { if (getArg(0) instanceof ContextItemExpression || (getArg(0) instanceof ItemChecker && ((ItemChecker) getArg(0)).getBaseExpression() instanceof ContextItemExpression)) { return new NodeSetPattern(this); } } return super.toPattern(config); }