Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Iterate through associated classes
[Acceleo] Iterate through associated classes [message #813912] |
Mon, 05 March 2012 16:01  |
Eclipse User |
|
|
|
Dear all,
I'd like to iterate trough the set of all classes associated to a particular class. I can get a collection of associations with the getAssociations() method, but a similar thing for associated classes I haven't found. How can it be done?
Thank you.
|
|
| | | | |
Re: [Acceleo] Iterate through associated classes [message #902594 is a reply to message #816432] |
Sat, 18 August 2012 14:21   |
Eclipse User |
|
|
|
Dear all,
I'm not able to use the memberEnd property any more to iterate through associated classes. The attached image shows a rather simple model just for testing purposes:

Feeding this model to this sample Acceleo module:
[comment encoding = UTF-8 /]
[module iterateAssociations('http://www.eclipse.org/uml2/3.0.0/UML')/]
[template public iterateAssociations(c : Class) ? (c.hasStereotype('Table'))]
[comment @main /]
[file (c.name.concat('.test'), false, 'UTF-8')]
This class has the stereotype Table applied on: [c.name/]
Start iteration ------------
[for (ass:Association | c.getAssociations()) ]
Association: [ass.name /]
[for (p:Property | ass.memberEnd) ]
[if (p.class.isNull())]
This member end [p.name/] has a null class associated
[else]
The member end [p.name/] as the associated class: [p.class.name /]
[/if]
[/for]
[/for]
[/file]
[/template]
[query public hasStereotype(arg0 : Class, arg1 : String) : Boolean
= invoke('org.eclipse.acceleo.module.sample.services.UML2Services',
'hasStereotype(org.eclipse.uml2.uml.Class, java.lang.String)',
Sequence{arg0, arg1}) /]
[query public isNull(arg0 : Class) : Boolean
= invoke('org.eclipse.acceleo.module.sample.services.UML2Services',
'isNull(org.eclipse.uml2.uml.Class)',
Sequence{arg0}) /]
I get this result:
This class has the stereotype Table applied on: Car
Start iteration ------------
Association: car_wheel
This member end car has a null class associated
The member end wheel as the associated class: Car
There are 2 things here I don't understand:
. the Car class is linked to the wheel end
. the car end links to a null class
I believe this sample module allowed to iterate through associated classes back in March. But I don't have any generated files from then, hence I can't be sure.
Am I doing something wrong? What would then be the correct way to iterate through associated classes?
Thank you in advance.
|
|
|
Re: [Acceleo] Iterate through associated classes [message #902598 is a reply to message #902594] |
Sat, 18 August 2012 14:48   |
Eclipse User |
|
|
|
Hi
What software release are you using?
Regards
Ed Willink
On 18/08/2012 19:21, Luís de Sousa wrote:
> Dear all,
>
> I'm not able to use the memberEnd property any more to iterate through associated classes. The attached image shows a rather simple model just for testing purposes:
>
>
>
> Feeding this model to this sample Acceleo module:
>
> [comment encoding = UTF-8 /]
> [module iterateAssociations('http://www.eclipse.org/uml2/3.0.0/UML')/]
>
> [template public iterateAssociations(c : Class) ? (c.hasStereotype('Table'))]
>
> [comment @main /]
> [file (c.name.concat('.test'), false, 'UTF-8')]
>
> This class has the stereotype Table applied on: [c.name/]
>
> Start iteration ------------
>
> [for (ass:Association | c.getAssociations()) ]
> Association: [ass.name /]
> [for (p:Property | ass.memberEnd) ]
> [if (p.class.isNull())]
> This member end [p.name/] has a null class associated
> [else]
> The member end [p.name/] as the associated class: [p.class.name /]
> [/if]
> [/for]
> [/for]
> [/file]
>
> [/template]
>
> [query public hasStereotype(arg0 : Class, arg1 : String) : Boolean
> = invoke('org.eclipse.acceleo.module.sample.services.UML2Services',
> 'hasStereotype(org.eclipse.uml2.uml.Class, java.lang.String)',
> Sequence{arg0, arg1}) /]
>
> [query public isNull(arg0 : Class) : Boolean
> = invoke('org.eclipse.acceleo.module.sample.services.UML2Services',
> 'isNull(org.eclipse.uml2.uml.Class)',
> Sequence{arg0}) /]
>
>
> I get this result:
>
>
> This class has the stereotype Table applied on: Car
>
> Start iteration ------------
>
> Association: car_wheel
> This member end car has a null class associated
> The member end wheel as the associated class: Car
>
>
> There are 2 things here I don't understand:
> the Car class is linked to the wheel end
> the car end links to a null class
>
> I believe this sample module allowed to iterate through associated classes back in March. But I don't have any generated files from then, hence I can't be sure.
>
> Am I doing something wrong? What would then be the correct way to iterate through associated classes?
>
> Thank you in advance.
|
|
| | | | | | | | | | | |
Re: [Acceleo] Iterate through associated classes [message #903259 is a reply to message #903255] |
Wed, 22 August 2012 14:00   |
Eclipse User |
|
|
|
Hi
What's this isNull stuff?
What's wrong with
rel <> null
rel->isEmpty()
rel->notEmpty()
not rel.oclIsUndefined()
Regards
Ed Willink
On 22/08/2012 18:28, Luís de Sousa wrote:
> Hi Andrea, thank you for your input. Let me go though your comments:
>
> Quote:
>> I don't have the UML superstructure here but as far as I remember it
>> should actually be enough to get the attributes, which are
>> UML::Property elements and check for the "aggregationKind"
>> (meta)attribute. I'll check today but you can check yourself with
>> this doc http://www.omg.org/spec/UML (download the latest
>> stuperstructure).
>
>
> Using the getAssociations() method I'm getting the exact same set of
> properties I get when I iterate with the memberEnd property. You can
> see the results in my previous message.
>
> Quote:
>> Also you hardly need Java Services. For instance the isNull() service
>> might be replaced with
>>
>> [if rel.isEmpty()]
>> or
>>
>> [if rel.isNotEmpty()]
>
>
> I'm getting a "cannot find operation" error with any of these methods,
> and indeed I can't find them with the model browser. But it would be
> great if something like this exists.
>
> Quote:
>> while to check an applied stereotype you may use
>> getAppliedStereotype('completeStereotypeNameWithNameSpace')
>> remember to pass the complete stereotype name like
>> 'package1::package2::stereotypeName'
>> so for instance
>>
>> [if c.getAppliedStereotype('package1::Stereotype').notEmpty()] ... [/if]
>
>
> This method is indeed there, but it always returns null. It might be
> something with the package name, as you suggest, but my project is
> pretty straightforward, there's only a folder called "models" where I
> have all the Papyrus stuff.
>
> I'm using the isNull and hasStereotype services following advice at
> this forum. Naturally I'd rather stick to OMGM2T.
> Regards,
>
> Luís
>
>
|
|
| | | | |
Re: [Acceleo] Iterate through associated classes [message #906506 is a reply to message #903724] |
Sat, 01 September 2012 13:59   |
Eclipse User |
|
|
|
Hi Ed,
First of all thank you for keeping this thread alive; I'm sorry if the questions I'm posting have obvious answers, but I can assure you I'd rather be programming than posting.
Quote:Have you looked in the Operations section of the Acceleo Documentation?
I'd previously went through the Acceleo operations list and I can't find there any reference to services like isEmpty, empty, noEmpty, etc. I'm using this page, perhaps not the right place?
Quote:Have you looked in the OCL Standard Library section of the OCL
documentation?
I haven't read the OCL Standard Library, but at the moment of this writing it doesn't seem to be accessible. I'm using this address, hope it is right.
Quote:Content assist is not always perfect;particularly where there are subtle
language rules involved.
I don't mind that, as long as it is documented somewhere.
Quote:The original problem seemed to be that you were using the wrong access
and so got a subtype response.
Have you looked at oclAsType() ?
Indeed, oclAsType() was what I was looking for. Thank you once more,
Luís
[Updated on: Sat, 01 September 2012 14:01] by Moderator
|
|
| |
Goto Forum:
Current Time: Fri May 09 00:18:56 EDT 2025
Powered by FUDForum. Page generated in 0.25887 seconds
|