Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » List or something
List or something [message #664046] Thu, 07 April 2011 09:53 Go to next message
Klausen  is currently offline Klausen Friend
Messages: 4
Registered: April 2011
Junior Member
Hi,

I'd like to write a little java code generator. Therefore my template hsould genearte the "import"s as well. The only issue is, that it might happen, that I generate generate several identical import, as 'm just looping over a list of ERFeferences. Is there any way to define a list or anything like that, where I can put the generated imports to check via contaions(..) if I have already genearted the4 import?

Kind Regards,

klausen
Re: List or something [message #664290 is a reply to message #664046] Fri, 08 April 2011 09:39 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
You should mentioned which template language you use.
If it's Xpand you can use contains or even use a set.
The list literal is []
If you want a set its [].toSet()

Sven

Am 4/7/11 11:53 AM, schrieb Klausen:
> Hi,
>
> I'd like to write a little java code generator. Therefore my template
> hsould genearte the "import"s as well. The only issue is, that it might
> happen, that I generate generate several identical import, as 'm just
> looping over a list of ERFeferences. Is there any way to define a list
> or anything like that, where I can put the generated imports to check
> via contaions(..) if I have already genearted the4 import?
>
> Kind Regards,
>
> klausen


--
Need professional support for Xtext or other Eclipse Modeling technologies?
Go to: http://xtext.itemis.com
Twitter : @svenefftinge
Blog : http://blog.efftinge.de
Re: List or something [message #664315 is a reply to message #664046] Fri, 08 April 2011 11:20 Go to previous messageGo to next message
Klausen  is currently offline Klausen Friend
Messages: 4
Registered: April 2011
Junior Member
I'm using the normal Acceleo Templates. The meta model is ECORE.
Re: List or something [message #664327 is a reply to message #664315] Fri, 08 April 2011 11:56 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

If you put your imports in a Set duplicates should be removed
automatically, but this slightly implies that you need two passes; one
to prepare for code generation and another to code generate. If
preparation gets non-trivial, you might consider an M2M to prepare and
then a simpler M2T to generate.

Regards

Ed Willink

On 08/04/2011 12:20, Klausen wrote:
> I'm using the normal Acceleo Templates. The meta model is ECORE.
Re: List or something [message #664356 is a reply to message #664327] Fri, 08 April 2011 14:13 Go to previous messageGo to next message
Klausen  is currently offline Klausen Friend
Messages: 4
Registered: April 2011
Junior Member
ok, but how do a put the imports in a set? My curernt code looks like this

[for (e : EClass | p.eContents())]
import [p.name/].I[e.name/];
[/for]

Do I have to use a let clause?
Re: List or something [message #664373 is a reply to message #664356] Fri, 08 April 2011 14:54 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050103090901000905020808
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi,

You can use something like this :

[for (e : EClass | p.eContents()->filter(EClass)->asSet())]
import [allClasses.name]
[/for]

Laurent Goubet
Obeo

On 08/04/2011 16:13, Klausen wrote:
> ok, but how do a put the imports in a set? My curernt code looks like this
>
> [for (e : EClass | p.eContents())]
> import [p.name/].I[e.name/];
> [/for]
>
> Do I have to use a let clause?


--------------050103090901000905020808
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=
--------------050103090901000905020808--
Re: List or something [message #664374 is a reply to message #664356] Fri, 08 April 2011 14:56 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 7655
Registered: July 2009
Senior Member
Hi

Generically you could try something like

[for (s : String | p->collect(e : EClass | p.name + '.I' +
e.name)->asOrderedSet()->sortedBy(s : String | s))]
import [s/];
[/for]

but your problem seems much simpler with a fixed package prefix try

[for (e : EClass | p.eContents()->asOrderedSet()->sortedBy(name))]
import [p.name/].I[e.name/];
[/for]

Regards

Ed Willink


On 08/04/2011 15:13, Klausen wrote:
> ok, but how do a put the imports in a set? My curernt code looks like
> this
>
> [for (e : EClass | p.eContents())]
> import [p.name/].I[e.name/];
> [/for]
>
> Do I have to use a let clause?
Re: List or something [message #664375 is a reply to message #664373] Fri, 08 April 2011 14:57 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090408030405060108000300
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Without the copy/pasting errors, this gives :

[for (e : EClass | p.eContents()->filter(EClass)->asSet())]
import [p.name/].I[e.name/];
[/for]

:)

Laurent Goubet
Obeo

On 08/04/2011 16:54, Laurent Goubet wrote:
> [for (e : EClass | p.eContents()->filter(EClass)->asSet())]
> import [allClasses.name]
> [/for]


--------------090408030405060108000300
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=
--------------090408030405060108000300--
Re: List or something [message #664380 is a reply to message #664375] Fri, 08 April 2011 15:17 Go to previous messageGo to next message
Klausen  is currently offline Klausen Friend
Messages: 4
Registered: April 2011
Junior Member
Thx,

But my eclipse complain about the asSet() call. Which version of Eclispe / Acceleo do I need?

I'm running

Version: Helios Service Release 1
Build id: 20100917-0705
Acceleo SDK : 3.0.1.v201009150438

Cheers,

Klaus
Re: List or something [message #664562 is a reply to message #664046] Mon, 11 April 2011 07:51 Go to previous message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

There was a bug with the "filter" operation which returned a Collection and not the same kind of collection as the source of the operation like:

mySet->filter(...) : Set
mySequence->filter(...) : Sequence
myBag->filter(...) : Bag
myOrderedSet>filter(...) : OrderedSet

And since the "asSet()" operation does not exists on "Collection", it didn't compile.

This bug has been fixed, you should update with the Acceleo update site: http://download.eclipse.org/modeling/m2t/acceleo/updates/rel eases/3.0


Stephane Begaudeau, Obeo

--
Twitter: @sbegaudeau
Acceleo wiki: http://wiki.eclipse.org/Acceleo
Blogs: http://stephanebegaudeau.tumblr.com & http://sbegaudeau.tumblr.com

[Updated on: Mon, 11 April 2011 07:52]

Report message to a moderator

Previous Topic:[Xtext] syntax errors while running the generator workflow
Next Topic:[JET] How to load a java file with a fully qualified name?
Goto Forum:
  


Current Time: Thu Apr 25 08:18:12 GMT 2024

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

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

Back to the top