/** * Pre-evaluate a function at compile time. Functions that do not allow * pre-evaluation, or that need access to context information, can override this method. * * @param visitor an expression visitor * @return the result of the early evaluation, or the original expression, or potentially * a simplified expression * @throws net.sf.saxon.trans.XPathException if evaluation fails */ public Expression preEvaluate(ExpressionVisitor visitor) throws XPathException { if ((getIntrinsicDependencies() & ~StaticProperty.DEPENDS_ON_STATIC_CONTEXT) != 0) { return this; } try { Literal lit = Literal.makeLiteral(iterate(visitor.getStaticContext().makeEarlyEvaluationContext()).materialize(), this); Optimizer.trace(visitor.getConfiguration(), "Pre-evaluated function call " + toShortString(), lit); return lit; } catch (NoDynamicContextException e) { // early evaluation failed, usually because implicit timezone required return this; } catch (UnsupportedOperationException e) { //e.printStackTrace(); if (e.getCause() instanceof NoDynamicContextException) { return this; } else { throw e; } } }
/** * Pre-evaluate a function at compile time. Functions that do not allow * pre-evaluation, or that need access to context information, can override this method. * * @param visitor an expression visitor * @return the result of the early evaluation, or the original expression, or potentially * a simplified expression * @throws net.sf.saxon.trans.XPathException if evaluation fails */ public Expression preEvaluate(ExpressionVisitor visitor) throws XPathException { if ((getIntrinsicDependencies() & ~StaticProperty.DEPENDS_ON_STATIC_CONTEXT) != 0) { return this; } try { Literal lit = Literal.makeLiteral(iterate(visitor.getStaticContext().makeEarlyEvaluationContext()).materialize(), this); Optimizer.trace(visitor.getConfiguration(), "Pre-evaluated function call " + toShortString(), lit); return lit; } catch (NoDynamicContextException e) { // early evaluation failed, usually because implicit timezone required return this; } catch (UnsupportedOperationException e) { //e.printStackTrace(); if (e.getCause() instanceof NoDynamicContextException) { return this; } else { throw e; } } }