Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo 3] write all the imports of a class(getParametersOperations)
[Acceleo 3] write all the imports of a class [message #554861] Tue, 24 August 2010 14:49 Go to next message
Sergio  is currently offline Sergio Friend
Messages: 21
Registered: August 2010
Location: Cardedeu
Junior Member
Hi,

I wanna write all the imports of a class, so I want to get all the classes included in the parameters of the operations.

I tried this:

[query public getParametersOperations(class : Class) : Sequence(T) =
class.getAllOperations().parameterableElements()->select(not oclIsKindOf(Class))/]

[template public importBlock(class : Class)]
// [protected ('for imports')]
[for (at : Parameter | class.getParametersOperations())]
import [packageDomain(class) + at.type.name /];
[/for]
// [/protected]
[/template]

but If the same class is in more than one parameter, I've got a repeated import.

I want to use this in more than one place...
How can I filter the correct classes? Or you know another way to do that?

THANK YOU!!



Sergio Sacristán
http://s2o-bcn.blogspot.com/
Re: [Acceleo 3] write all the imports of a class [message #554870 is a reply to message #554861] Tue, 24 August 2010 15:14 Go to previous messageGo to next message
Stephane Begaudeau is currently offline Stephane BegaudeauFriend
Messages: 458
Registered: April 2010
Location: Nantes (France)
Senior Member

Hi,

The key in your problem here is to use asSet() which will transform your collection into a Set. Because a set cannot have a duplicate element, you just have to create a set of the name of the type and duplicates will be delete. I have created an Acceleo project to show you how you can do it. My example uses Ecore as a metamodel contrary to UML in your example but it doesn't matter for that problem.

http://a.imageshack.us/img529/9133/capturexb.png

You can see that there are two ways to do it, and it is exactly the same mechanism. With OCL you should use "myCollection->collect(a | a.doSomething())" but we also tolerate "myCollection.doSomething()". both operation will create a collection. Then you just have to use asSet() to suppress all duplicates.

Stephane Begaudeau, Obeo
Re: [Acceleo 3] write all the imports of a class [message #555354 is a reply to message #554870] Thu, 26 August 2010 12:10 Go to previous messageGo to next message
Sergio  is currently offline Sergio Friend
Messages: 21
Registered: August 2010
Location: Cardedeu
Junior Member
yeah, thats great. Thank you.

I tried this, but no luck...

[template public parametersOperations(class : Classifier)]

[let packDomain:String = packageDomain(class)]
// [protected ('for imports')]
[for (eOperation : Operation | class.getAllOperations())]
[for (name : String | eOperation.ownedParameter -> collect(param | param.type) -> collect (type | type.name) -> asSet())]
import [packDomain + '.' + name/];
[/for]
[/for]
// [/protected]
[/let]

[/template]

Maybe it's because I'm using Class and not EClass? How can I use EClass from a Class (class.oclAsType(EClass) --> error cast)?



Sergio Sacristán
http://s2o-bcn.blogspot.com/
Re: [Acceleo 3] write all the imports of a class [message #555927 is a reply to message #555354] Mon, 30 August 2010 09:22 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.
--------------070307080402080200060608
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Sergio,

With this, you still have duplicate entries? or the processing fails
before that?

I'd suggest you use this:

[template public parametersOperations(class : Classifier)]
// [protected ('for imports')]
[for (typeName : String |
class.getAllOperations().ownedParameter.type.name->asSet())]
import [packageDomain(class) + '.' + typeName/];
[/for]
// [/protected]
[/template]

Laurent Goubet
Obeo

Sergio wrote:
> yeah, thats great. Thank you.
> I tried this, but no luck...
>
> [template public parametersOperations(class : Classifier)]
>
> [let packDomain:String = packageDomain(class)]
> // [protected ('for imports')]
> [for (eOperation : Operation | class.getAllOperations())]
> [for (name : String | eOperation.ownedParameter -> collect(param |
> param.type) -> collect (type | type.name) -> asSet())]
> import [packDomain + '.' + name/];
> [/for]
> [/for]
> // [/protected]
> [/let]
>
> [/template]
>
> Maybe it's because I'm using Class and not EClass? How can I use EClass
> from a Class (class.oclAsType(EClass) --> error cast)?


--------------070307080402080200060608
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=
--------------070307080402080200060608--
Re: [Acceleo 3] write all the imports of a class [message #636843 is a reply to message #555927] Wed, 03 November 2010 05:23 Go to previous message
Sergio  is currently offline Sergio Friend
Messages: 21
Registered: August 2010
Location: Cardedeu
Junior Member
Thank you!

Yes, the last one was right!

(I left the project in stand by until this month.)



Sergio Sacristán
http://s2o-bcn.blogspot.com/
Previous Topic:[Acceleo 3.1] protected block
Next Topic:[Acceleo] Problem getting Run as | Launch Acceleo
Goto Forum:
  


Current Time: Fri Nov 08 23:24:48 GMT 2024

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

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

Back to the top