https://saxonica.plan.io/https://saxonica.plan.io/favicon.ico2022-01-18T12:00:45ZSaxonica Developer CommunitySaxon - Support #5209: Should net.sf.saxon.expr.Expression.extraProperties be also copied when the net.sf.saxon.expr.Expression.copy(RebindingMap) method is invoked?https://saxonica.plan.io/issues/5209?journal_id=190262022-01-18T12:00:45ZMichael Kaymike@saxonica.com
<ul></ul><p>Good question with no easy answer. Most of the properties on the expression tree, including most of the extraProperties, are computed lazily and will be re-computed if not present. Not copying the property is therefore probably safer in general, because an expression copy is always happening in the middle of an expression rewrite that has the potential to change the value of the properties. But obviously some properties, like your link back to the source tree, are not like that, and cannot be reconstituted if lost.</p>
<p>I wonder if you wouldn't be better off relying on the Location object for a link back to the source element?</p>
<p>I think that if you set <code>Feature.RETAIN_NODE_FOR_DIAGNOSTICS</code>, the <code>Location</code> of expressions should be an <code>AttributeLocation</code> in which the elementNode property points to the source element. Give it a try, anyway!</p> Saxon - Support #5209: Should net.sf.saxon.expr.Expression.extraProperties be also copied when the net.sf.saxon.expr.Expression.copy(RebindingMap) method is invoked?https://saxonica.plan.io/issues/5209?journal_id=190372022-01-19T08:30:52ZRadu Coravuradu_coravu@sync.ro
<ul></ul><p>Thanks for the feedback Michael.
About using on the trace listener the Location of the Traceable to get to the StyleElement, it depends, sometimes it is an instance of "net.sf.saxon.expr.instruct.TemplateRule" and sometimes it is an "net.sf.saxon.expr.parser.XPathParser.NestedLocation"
The "NestedLocation" is indeed wrapped around an AttributeLocation which could give us access to the node info.
So an interesting idea, in at least some cases (maybe most cases) we could use the location to map the Traceable to the style element.
Anyway I guess this can be closed for now.</p> Saxon - Support #5209: Should net.sf.saxon.expr.Expression.extraProperties be also copied when the net.sf.saxon.expr.Expression.copy(RebindingMap) method is invoked?https://saxonica.plan.io/issues/5209?journal_id=190382022-01-19T08:41:22ZRadu Coravuradu_coravu@sync.ro
<ul></ul><p>Also sometimes the locations are instance of "net.sf.saxon.expr.parser.Loc" but this seems to occur when they are not really connected to a NodeInfo.
For example in this case:</p>
<pre><code><xsl:template match="parent">
<xsl:element name="name1">
<a>
<b>
textr
</b>
</a>
</xsl:element>
</code></pre>
<p>for that "textr" node the trace listener receives a "net.sf.saxon.expr.instruct.ValueOf" with a "net.sf.saxon.expr.parser.Loc" but in a way this probably makes sense as there is no StyleElement associated to the text node.</p> Saxon - Support #5209: Should net.sf.saxon.expr.Expression.extraProperties be also copied when the net.sf.saxon.expr.Expression.copy(RebindingMap) method is invoked?https://saxonica.plan.io/issues/5209?journal_id=194682022-02-11T16:54:56ZMichael Kaymike@saxonica.com
<ul><li><strong>Status</strong> changed from <i>New</i> to <i>Closed</i></li><li><strong>Assignee</strong> set to <i>Michael Kay</i></li></ul><p>Closing this with no further action.</p>
<p>I think it's safer for expressions NOT to copy the extraProperties, and I would recommend using the Location property to hold information enabling you to trace back to the source code.</p>