Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Iterate through associated classes
| |
Re: [Acceleo] Iterate through associated classes [message #815100 is a reply to message #814328] |
Wed, 07 March 2012 08:26   |
|
Hi,
I do not use UML much and don't really know how to get my way around it, but I think Ed's right on the spot. You might want to import the UML metamodel in your workspace in order to get an idea of how to get from one point to the other. In your eclipse, use :
File > Import > Plug-in Development > Plug-ins and fragments
In the dialog that pops up, select "Projects with source folders" in the bottom pane then hit "Next >". In the next window, select "org.eclipse.uml2.uml" in the left pane and click the "Add ->" button. You can then Finish the wizard.
In your workspace, a new project "org.eclipse.uml2.uml" will have been created. It contains a folder "model" in which is located the model "UML.ecore". This is the metamodel that is use behind the scene by Acceleo, you can then get an overview of the attributes and operations available on all classes.
Laurent Goubet
Obeo
[Updated on: Wed, 07 March 2012 08:26] Report message to a moderator
|
|
| | |
Re: [Acceleo] Iterate through associated classes [message #902594 is a reply to message #816432] |
Sat, 18 August 2012 18:21   |
Luís de Sousa Messages: 214 Registered: July 2009 |
Senior Member |
|
|
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 18:48   |
Ed Willink Messages: 7635 Registered: July 2009 |
Senior Member |
|
|
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 #903071 is a reply to message #903067] |
Tue, 21 August 2012 19:44   |
|
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).
Also you hardly need Java Services. For instance the isNull() service might be replaced with
or
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]
regards
Follow me on Twitter @andreasindico
[Updated on: Tue, 21 August 2012 19:44] Report message to a moderator
|
|
| | |
Re: [Acceleo] Iterate through associated classes [message #903259 is a reply to message #903255] |
Wed, 22 August 2012 18:00   |
Ed Willink Messages: 7635 Registered: July 2009 |
Senior Member |
|
|
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 #903267 is a reply to message #813912] |
Wed, 22 August 2012 18:51   |
|
@Luís, empty(), notEmpty() as well as other services (i.e. strings operations, etc.) shall be invoked through ->
when invoking the getAppliedStereotypes you have to provide the complete stereotype name. What is the "Papyrus Stuff" you say? I guess you have defined a profile containing (at least) the stereotype you aim to recognize. How is this profile structured? there should at least be a package containing it. You have to specify that package too.
Follow me on Twitter @andreasindico
[Updated on: Wed, 22 August 2012 18:52] Report message to a moderator
|
|
| | | |
Re: [Acceleo] Iterate through associated classes [message #906506 is a reply to message #903724] |
Sat, 01 September 2012 17:59   |
Luís de Sousa Messages: 214 Registered: July 2009 |
Senior Member |
|
|
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 18:01] Report message to a moderator
|
|
| |
Goto Forum:
Current Time: Sun Dec 03 02:08:54 GMT 2023
Powered by FUDForum. Page generated in 0.02703 seconds
|