Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] eInverse() and other functions(I cant find documentation of Acceleo functions)
[Acceleo] eInverse() and other functions [message #499713] Mon, 23 November 2009 19:58 Go to next message
Andre is currently offline Andre
Messages: 29
Registered: November 2009
Location: Brazil
Junior Member
I'm studying Acceleo, but i cant find documentation about many functions like eInverse, ancestors, siblings.

Does anyone know where i can find documentation about theses functions?

thanks

Andre Silva
Brazil


Andre Silva
Natal-RN
Brazil
Re: [Acceleo] eInverse() and other functions [message #499810 is a reply to message #499713] Tue, 24 November 2009 09:08 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020506060105080204030006
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Andre,

The documentation on non standard services is currently being reviewed
and should be accessible in the next integration build through the
Eclipse help (Help => Help Contents). It is not present at the time of
writing though :'(.

If needed, don't hesitate to post questions here about the services you
need help understanding. For those you posted the names here,

1) "self.eInverse()" returns all elements that reference "self" (inverse
references)
2) "self.ancestors()" returns all ancestors of "self" (tree-wise) : if
package A contains package B which itself contains class C,
"C.ancestors()" will return B and A in this order.
3) "self.siblings()" is once again a tree-wise operation : it will
return all elements standing at the same level as "self" under the same
parent.

Laurent Goubet
Obeo

Andre wrote:
> I'm studying Acceleo, but i cant find documentation about many functions
> like eInverse, ancestors, siblings.
>
> Does anyone know where i can find documentation about theses functions?
>
> thanks
>
> Andre Silva
> Brazil


--------------020506060105080204030006
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------020506060105080204030006--
Re: [Acceleo] eInverse() and other functions [message #499888 is a reply to message #499810] Tue, 24 November 2009 13:25 Go to previous messageGo to next message
Andre is currently offline Andre
Messages: 29
Registered: November 2009
Location: Brazil
Junior Member
Hi Laurent

thanks for aswering

i hope this documentation be ready as soon as possible

one more question: how can i obtain the ancestors in reverse order? if package A contains package B which itself contains class C, "C.ancestors()" will return A and B in this order

Andre Silva
Brazil


Andre Silva
Natal-RN
Brazil
Re: [Acceleo] eInverse() and other functions [message #499925 is a reply to message #499888] Tue, 24 November 2009 14:12 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010305000909090100030908
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Andre,

We wanted to add a "reverse()" operation on ordered collection types to
allow just that ... yet such an operation has been planned for the next
version of OCL and thus we decided on not adding a duplicate in.

Till the next version of MDT OCL is out, your only choice to reverse a
list is to create your own 'reverse()' query :

[query reverse(toReverse : Collection(T)) : Sequence(T) =
toReverse->iterate(item; res : Sequence(T) = Sequence{} |
res->prepend(item))/]

Laurent Goubet
Obeo

Andre wrote:
> Hi Laurent
>
> thanks for aswering
>
> i hope this documentation be ready as soon as possible
>
> one more question: how can i obtain the ancestors in reverse order? if
> package A contains package B which itself contains class C,
> "C.ancestors()" will return A and B in this order
>
> Andre Silva
> Brazil


--------------010305000909090100030908
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------010305000909090100030908--
Re: [Acceleo] eInverse() and other functions [message #500060 is a reply to message #499925] Tue, 24 November 2009 20:08 Go to previous messageGo to next message
Andre is currently offline Andre
Messages: 29
Registered: November 2009
Location: Brazil
Junior Member
Hi Laurent

Your query really worked!! thanks a lot!

can you answer one more question? is it possible on Acceleo to declare a String variable and manipulate it?

Something like this:
String x = "something";
x.concat("another");

thanks


Andre Silva
Natal-RN
Brazil
Re: [Acceleo] eInverse() and other functions [message #500171 is a reply to message #500060] Wed, 25 November 2009 09:05 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090905090309050804030705
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Andre,

Unfortunately, the MTL specification does not provide a
"generation-free" type of block that would allow to manipulate a
variable without generating the result of this manipulation. You can
declare variables within "init sections" of some blocks (template,
query, for, ... see the specification for details). Manipulating these
variables will always generate the result :

[template test(c : EClass) {x : String = 'something';}]
[x.concat(' another')/]
[x.concat(' once more')/]
[/template]

Will generate the text : "something another\nsomething once more". As a
side note, there is no "affectation operator" in OCL. The "=" operator
is a comparison except in variable initialisation, thus there is no way
to alter the value of a primitve variable beside initialisation.

I raised an OMG issue against the specification for this ... yet
received no word from the MTL task force since then.

Laurent Goubet
Obeo

Andre wrote:
> Hi Laurent
>
> Your query really worked!! thanks a lot!
>
> can you answer one more question? is it possible on Acceleo to declare a
> String variable and manipulate it?
>
> Something like this:
> String x = "something";
> x.concat("another");
>
> thanks


--------------090905090309050804030705
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------090905090309050804030705--
Re: [Acceleo] eInverse() and other functions [message #500387 is a reply to message #500171] Wed, 25 November 2009 20:58 Go to previous messageGo to next message
Sebastien Roy is currently offline Sebastien Roy
Messages: 51
Registered: November 2009
Member
I am not sure that to be able to do something like a = a + b is absolutely necessary.
A behaviour similar to the xslt one would be nice.
You cannot modify a variable but recursive mechanisms allow to do everything you need.
An initialisation part at each block level (not only template) would also be a nice thing...
Re: [Acceleo] eInverse() and other functions [message #500420 is a reply to message #500171] Thu, 26 November 2009 02:52 Go to previous messageGo to next message
Andre is currently offline Andre
Messages: 29
Registered: November 2009
Location: Brazil
Junior Member
Hi Laurent

Another question: how can i obtain the same result of ancestors() using only standard OCL services? is it too complicated?

thanks


Andre Silva
Natal-RN
Brazil
Re: [Acceleo] eInverse() and other functions [message #500469 is a reply to message #500387] Thu, 26 November 2009 09:52 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010202030601060806050204
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Sebastien,

I am not that familiar with XSLT. Could you elaborate on the behavior
you'd like to see within Acceleo? We are not limited to what the
specification allows us to do; we are free to try and make the
specification evolve. If you see a nice way if providing such
functionalities, don't hesitate to report it to us :).

Laurent Goubet
Obeo

Sebastien Roy wrote:
> I am not sure that to be able to do something like a = a + b is
> absolutely necessary.
> A behaviour similar to the xslt one would be nice.
> You cannot modify a variable but recursive mechanisms allow to do
> everything you need.
> An initialisation part at each block level (not only template) would
> also be a nice thing...


--------------010202030601060806050204
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------010202030601060806050204--
Re: [Acceleo] eInverse() and other functions [message #500475 is a reply to message #500420] Thu, 26 November 2009 10:01 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------060102090700050303050804
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Andre,

This isn't impossible with pure OCL, we simply decided to provide
simplifications when we thought something would be too cumbersome for
users. In OCL, you can simply make use of the fact everything is an
EObject and use the usual "eContainer()" EOperation, along with some
recursion. That would give something like :

[query public getAncestors(o : OclAny) : Sequence(T) = let container :
EObject = o.oclAsType(ecore::EObject).eContainer() in
Sequence{container}.append(container.getAncestors())/]

Laurent Goubet
Obeo

Andre wrote:
> Hi Laurent
>
> Another question: how can i obtain the same result of ancestors() using
> only standard OCL services? is it too complicated?
>
> thanks
>


--------------060102090700050303050804
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------060102090700050303050804--
Re: [Acceleo] eInverse() and other functions [message #500508 is a reply to message #500475] Thu, 26 November 2009 13:17 Go to previous messageGo to next message
Andre is currently offline Andre
Messages: 29
Registered: November 2009
Location: Brazil
Junior Member
Laurent,

Is the 'eContainer()' operation an OCL standard? why can't i see it on OMG OCL documentation and on Acceleo sintax?

thanks


Andre Silva
Natal-RN
Brazil
Re: [Acceleo] eInverse() and other functions [message #500529 is a reply to message #500508] Thu, 26 November 2009 14:34 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent Goubet
Messages: 1632
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040506060603040009030501
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Andre,

eContainer() is an EOperation defined on the ecore metamodel. The query
I gave you here takes advantage of the fact any model modelled through
EMF contains instances of EObjects :). The query won't do the trick,
however, if you decided not to extend "EObject" in the genmodel you used
to generate your metamodel code.

If you haven't used a genmodel, then the model you use for generation is
most likely a ".ecore" model or ".uml" model, the elements of which both
extend EObject.

Laurent Goubet
Obeo

Andre wrote:
> Laurent,
>
> Is the 'eContainer()' operation an OCL standard? why can't i see it on
> OMG OCL documentation and on Acceleo sintax?
>
> thanks


--------------040506060603040009030501
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------040506060603040009030501--
Re: [Acceleo] eInverse() and other functions [message #500585 is a reply to message #499713] Thu, 26 November 2009 21:28 Go to previous message
Sebastien Roy is currently offline Sebastien Roy
Messages: 51
Registered: November 2009
Member
Laurent Goubet wrote on Thu, 26 November 2009 04:52

Sebastien,

I am not that familiar with XSLT. Could you elaborate on the behavior
you'd like to see within Acceleo? We are not limited to what the
specification allows us to do; we are free to try and make the
specification evolve. If you see a nice way if providing such
functionalities, don't hesitate to report it to us Smile.

Laurent Goubet
Obeo



Well, basically, the XSLT and M2T paradygm and goal are quite similar :



  • They take as input an xml document (specialised for M2T)
  • They parse this document and transform its elements in text elements as output.
  • The process is absolutely static : there is no dynamic behaviour : no event, no time. The result of the process only depends on the initial inputs.
  • You can navigate into the structure of the input document using a specific language : XPath for xslt, ocl for M2T.


The data beeing static, there is no need to dynamic modification of variable.
In xslt, the variable are mainly used as shortcuts. This prevents the developer to have too long or complex expressions and/or copy paste these long and complex expressions in different parts of the code. This is specifically usefull when the variables are used to gather a set of elements that will be used later in the code.
Actually, the variables are not evaluated when they are declared, but when they are used.

example :
<xsl:variable name="foo" select="aVeryComplexExpression($templateParameter1, $currentNode)"/>
<xsl:variable name="result1" select="aTransformation($foo)"/>
<xsl:variable name="result2" select="anotherTransformation($foo)"/>
<xsl:value-of  select="$result1"/>
<xsl:value-of select="$result2"/>

is similar to
<xsl:value-of  select="aTransformation(aVeryComplexExpression($templateParameter1, $currentNode))"/>
<xsl:value-of select="anotherTransformation(aVeryComplexExpression($templateParameter1, $currentNode))"/>

The results are identical but the second expression is harder to write, to read and to maintain when the syntax is a little bit long.

In xslt, you can define variables anywhere in the code. That allow to define variables depending on the current node in a for-each loop, for instance.
(The equivalent in M2T of the "current-node" would be the iteration variable of the "for" loop).

The only drawback of not be able to modify variable is that the computations based on iterations for instance are sometimes more tedious. They have to be performed using recursive algorithms instead.

So, simply allowing to define new variable anywhere in the code would dramatically ease the use of complex expression without breaking the M2T paradigm.




Previous Topic:[Acceleo] NullPointer while launching a transformation via API
Next Topic:Xpand: Cannot resolve the reference to a dependent model
Goto Forum:
  


Current Time: Sat Oct 25 12:42:07 GMT 2014

Powered by FUDForum. Page generated in 0.02141 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software