|[Acceleo] Error Getting Attributes with Specific Stereotypes [message #1232597]
||Fri, 17 January 2014 09:53
| Maya Retno
Registered: January 2014
Supposed I have a class Account in UML Class Diagram with 4 attributes: Integer fee, <<aParam>> Integer amount, <<aParam>> Integer balance, Integer id.
I would like to get the class name and its attributes with stereotypes <<aParam>>.
Here is my Acceleo transformation code:
class [aClass.name/] ([for (att: Property | aClass.getAllAttributes()) separator (',')]
[for (s: Stereotype | att.getAppliedStereotypes()) ? (s.name='aParam')]
[att.type.name/] [att.name/] [/for][/for]);
I hope the output is:
class Account (Integer amount, Integer balance);
but the current output is:
class Account (,,Integer amount,,Integer balance);
Based on the current output, at first it seems that all attributes was retrieved. Then when there is a condition that only attributes with stereotypes 'aParam' that should be retrieved, the attributes without stereotypes 'aParam' is deleted. Therefore, there is still space in the output with empty string (indicated by the comma separator).
Any idea how to solve this problem?
|Re: [Acceleo] Error Getting Attributes with Specific Stereotypes [message #1232725 is a reply to message #1232597]
||Fri, 17 January 2014 15:17
| Sebastien Roy
Registered: November 2009
This behaviour occurs because the attribute loop occurs even if the stereotype is not applied on the attribute.
You should filter in the first loop only attributes that hold the stereotype :
class [aClass.name/] ([for (att: Property | aClass.getAllAttributes()->select(getAppliedStereotypes()->contains(s: Stereotype |s.name='aParam'))) separator (',')]
[att.type.name/] [att.name/] [/for]);
I didn't test that piece of code but it should be close to what you actually need.
[Updated on: Fri, 17 January 2014 15:18]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.20216 seconds