ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Reilly <peter.rei...@corvil.com>
Subject Re: Macrodef @{x}
Date Thu, 04 Dec 2003 08:42:52 GMT
The ${x} gets evaluated at the point of use not at the point
of definition.

For the text part of elements it is up to the tasks to do this.
Ant core has no say in this. Normally tasks call
"getProject().replaceProperties(text)" in the addText() method (although
some do this later (sql for example)).

Some tasks do not do this - script, scriptdef are examples.

Expansion of properties for attributes is done by ant core. It
would be possible for macrodef (and presetdef which has a similar
issue) to modify the code for attributes, however with the addText()
expansion outside its control, this would not make sense.

The @{x} expansion is independent of the ${x} expansion and is done
by the macrodef at the point of use for attribute values and for text 
values.

Peter

Dominique Devienne wrote:

>The answer I would have expected is:
>
>@{prop} is 'property', value of ${property} is '${property}'
>
>Why? Because as I said many times, I want ${name} to behave as expected,
>i.e. be evaluated at the point of use, i.e. in <macrodef> itself, instead of
>being evaluated at the point(s) the macro is used. At the definition point,
>the '@{prop}' property (without the surounding single quotes) is not
>defined, so the ${@{prop}} literal stays unchanged, and @{prop} is later
>textually substituted, thus resulting in ${property}.
>
>The whole point of using the new @{name} notation was to be able to keep the
>normal behavior for ${name}.
>
>Note that I can see some value to be able to access a property at macro use
>time, where the property name is based on one or more attributes of the
>macro, but <copyproperty> already provides me that.
>
>So once more I think the semantic of ${name} is being abused by the latest
>patch of <macrodef>. Unless I've misunderstood something of course.
>
>Sorry for being a party pooper. --DD
> 
>
>-----Original Message-----
>From: Peter Reilly
>To: Ant Developers List; Ant Users List
>Sent: 12/3/2003 7:37 AM
>Subject: Macrodef @{x}
>
>I have committed the changes to change from ${x} to @{x} for
>macro attributes substitution.
>
>Usage of macrodef is now as follows:
><macrodef name="example">
>   <attribute name="x"/>
>   <sequential>
>      <echo>The attribute has the value '@{x}'</echo>
>  </sequential>
></macrodef>
>
>This can be called as follows:
><example x="a value"/>
>
>The escape sequence @@{ may be used to escape the substitution:
>
><macrodef name="example">
>   <attribute name="x"/>
>   <sequential>
>      <echo>The attribute @@{x} has the value '@{x}'</echo>
>  </sequential>
></macrodef>
>
><example x="a value"/>
>
>Will result in:
>     [echo] The attribute @{x} has the value 'a value'
>
>The mechanisms for substition are different for properties and
>macrodef attributes so one may now do the following:
>
>    <macrodef name="double">
>      <attribute name="prop"/>
>      <sequential>
>        <echo>@@{prop} is '@{prop}', value of $${@{prop}} is 
>'${@{prop}}'</echo>
>      </sequential>
>    </macrodef>
>    <property name="property" value="A property value"/>
>    <double prop="property"/>
>
>resulting in:
>     [echo] @{prop} is 'property', value of ${property} is 'A property 
>value'
>
>These changes will be available for the next ant 1.6 beta build.
>
>Peter
>
>
>  
>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message