[Acceleo 3] write all the imports of a class [message #554861] |
Tue, 24 August 2010 14:49 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Sergio ![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=extra%40sacristan.com.es) 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 message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
|
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](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 #555927 is a reply to message #555354] |
Mon, 30 August 2010 09:22 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
|
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--
|
|
|
|
Powered by
FUDForum. Page generated in 0.03848 seconds