[Acceleo 3] GetKeywords & GetEannotation [message #543774] |
Wed, 30 June 2010 14:21 |
Laviale Benoit Messages: 25 Registered: April 2010 Location: Paris |
Junior Member |
|
|
hi!
I have some troubles with the getkeywords & GetEannotation methods.
I want to filter my "objects" in my model. I want to get only the objects with a specific keyword ("test") specified in my model .
In a M2T template, i get the model, and after i get all the "ownedelements" of the model.
For each ownedelement i want to know if it have the specific keyword.
When i do my if/else in my template, it doesn't work.
When i just want to print the result of my condition it's print "true" ...
I really don't understand....
the code :
m is the model
[for (el : Element | m.ownedElement) ]
[if el.getEAnnotation('http://www.eclipse.org/uml2/2.0.0/UML').eGet('details').eGet('key').equalsIgnoreCase('test') ]
Condition Eannotation Good
[/if]
[if el.getKeywords().equalsIgnoreCase('test') ]
Condition KeyWord Good
[/if]
Type : [el.getEAnnotation('http://www.eclipse.org/uml2/2.0.0/UML').eGet('details').eGet('key').toString()/] == test
Eannotation => True/False [el.getEAnnotation('http://www.eclipse.org/uml2/2.0.0/UML').eGet('details').eGet('key').equalsIgnoreCase('test')/]
Keyword => True/False [el.getKeywords().equalsIgnoreCase('test')/]
[/for]
The result :
//This one have not the "specific" keyword
Type : org.eclipse.emf.ecore.impl.DynamicEObjectImpl@ebb12c (eClass: org.eclipse.emf.ecore.impl.EClassImpl@1bcd5b7 (name: Invalid_Class) (instanceClassName: null) (abstract: false, interface: false)) == test
Eannotation => True/False org.eclipse.emf.ecore.impl.DynamicEObjectImpl@ebb12c (eClass: org.eclipse.emf.ecore.impl.EClassImpl@1bcd5b7 (name: Invalid_Class) (instanceClassName: null) (abstract: false, interface: false))
Keyword => True/False
#####################################
//this one HAVE the specific keyword
Type : test == test
Eannotation => True/False true
Keyword => True/False true
#####################################
Thank for help
Benoît
Trainee
Thales Communications France
[Updated on: Wed, 30 June 2010 14:28] Report message to a moderator
|
|
|
Re: [Acceleo 3] GetKeywords & GetEannotation [message #543950 is a reply to message #543774] |
Thu, 01 July 2010 07:48 |
|
This is a multi-part message in MIME format.
--------------070708090009090001020804
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Hi Benoit,
"Invalid_Class" in the result means that something during the evaluation
failed (oclIsInvalid() would return true).
e1.getEAnnotation('http://www.eclipse.org/uml2/2.0.0/UML').eGet('details').eGet('key').toString()
All three of "getEAnnotation" and the 2 "eGet" can return null,
subsequent calls resulting in invalid results (the OCL variant of an
NPE). I would have done something like this :
[if (let keyword : String =
el.getEAnnotation('http://www.eclipse.org/uml2/2.0.0/UML').eGet('details').eGet('key')
in not keyword.oclIsInvalid() and keyword.equalsIgnoreCase('test'))]
Let me know if this does the trick.
Laurent Goubet
Obeo
Laviale Benoit wrote:
> hi! I have some troubles with the getkeywords & GetEannotation methods.
>
> I want to filter my "objects" in my model. I want to get only the
> objects with a specific keyword ("test") specified in my model .
>
> In a M2T template, i get the model, and after i get all the
> "ownedelements" of the model.
> For each ownedelement i want to know if it have the specific keyword.
> When i do my if/else in my template, it doesn't work.
> When i just want to print the result of my condition it's print "true" ...
>
> I really don't understand....
> the code : m is the model
>
> [for (el : Element | m.ownedElement) ]
>
> [if
> el.getEAnnotation('http://www.eclipse.org/uml2/2.0.0/UML').eGet('details').eGet('key').equalsIgnoreCase('test')
> ]
> Condition Eannotation Good
> [/if]
>
> [if el.getKeywords().equalsIgnoreCase('test').equalsIgnoreCase(' test') ]
> Condition KeyWord Good
> [/if]
> Type :
> [el.getEAnnotation('http://www.eclipse.org/uml2/2.0.0/UML').eGet('details').eGet('key').toString()/]
> == test
> Eannotation => True/False
> [el.getEAnnotation('http://www.eclipse.org/uml2/2.0.0/UML').eGet('details').eGet('key').equalsIgnoreCase('test')/]
> Keyword => True/False [el.getKeywords().equalsIgnoreCase('test')/]
> [/for]
>
>
>
> The result :
> This one have not the "specific" keyword
>
> Type : org.eclipse.emf.ecore.impl.DynamicEObjectImpl@ebb12c (eClass:
> org.eclipse.emf.ecore.impl.EClassImpl@1bcd5b7 (name: Invalid_Class)
> (instanceClassName: null) (abstract: false, interface: false)) == test
> Eannotation => True/False
> org.eclipse.emf.ecore.impl.DynamicEObjectImpl@ebb12c (eClass:
> org.eclipse.emf.ecore.impl.EClassImpl@1bcd5b7 (name: Invalid_Class)
> (instanceClassName: null) (abstract: false, interface: false)) Keyword
> => True/False #####################################
>
>
> this one HAVE the specific keyword
>
> Type : test == test
> Eannotation => True/False true Keyword => True/False true
> #####################################
>
>
>
> Thank for help
>
> Benoît
--------------070708090009090001020804
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=
--------------070708090009090001020804--
|
|
|
Re: [Acceleo 3] GetKeywords & GetEannotation [message #543966 is a reply to message #543950] |
Thu, 01 July 2010 08:39 |
Laviale Benoit Messages: 25 Registered: April 2010 Location: Paris |
Junior Member |
|
|
We are not on the "same way" i think...
The first result is "good" in my case! Because the current object haven't the specific keyword.
"I don't care" it's make errror or not... I just want to know if it have the "specific" keyword ...
The troubles is in the second result...
In this case, the result is strange because :
- When i compare the strings that's return true ( They are the same)
Keyword => True/False [el.getKeywords().equalsIgnoreCase('test')/]
Make :
Keyword => True/False true
(this result is good, my current object have the specific keyword)
- But when I put the SAME code in the if statement
[if el.getKeywords().equalsIgnoreCase('test') ]
Condition KeyWord Good
[/if]
Its must be print
"Condition KeyWord Good" (strings must always equals?!!)
But nothing is printed!
Why?
Do you have an issue?
I hope to be more "clearer"
Thank you for your help!
Trainee
Thales Communications France
[Updated on: Thu, 01 July 2010 08:42] Report message to a moderator
|
|
|
Re: [Acceleo 3] GetKeywords & GetEannotation [message #543982 is a reply to message #543966] |
Thu, 01 July 2010 09:10 |
|
This is a multi-part message in MIME format.
--------------070804050908070008090106
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Benoit,
I can't really see why the if doesn't work in your case... Might be a
parsing issue : does it still fail if you put the condition in parentheses?
[if (el.getKeywords().equalsIgnoreCase('test')) ]
Laviale Benoit wrote:
> We are not on the "same way" i think... :p
> The first result is "good" in my case! Because the current object
> haven't the specific keyword.
> "I don't care" it's make errror or not... I just want to know if it
> have the "specific" keyword ...
> The troubles is in the second result...
> In this case, the result is strange because : - When i compare the
> strings that's return true ( They are the same)
> Keyword => True/False [el.getKeywords().equalsIgnoreCase('test')/]
>
> Make :
> Keyword => True/False true
> (That's good, my current object have the good specific keyword)
> But when i put my code in the if statement
>
> [if el.getKeywords().equalsIgnoreCase('test') ]
> Condition KeyWord Good
> [/if]
>
> Its must be print "Condition KeyWord Good"
> But nothing is printed!
> I hope to be more "clearer"
>
>
> Thank you for your help!
--------------070804050908070008090106
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=
--------------070804050908070008090106--
|
|
|
|
Re: [Acceleo 3] GetKeywords & GetEannotation [message #543996 is a reply to message #543985] |
Thu, 01 July 2010 09:46 |
|
This is a multi-part message in MIME format.
--------------030500030309070708040708
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Ha ... no it is not.
Take extra care as to what you really have in terms of types...
el.getEAnnotation('http://www.eclipse.org/uml2/2.0.0/UML').eGet('details').eGet('key')
If I am not mistaken, "eGet('details')" returns a list, thus
"eGet('key')" is the same as "->collect(eGet('key'))", and it returns a
list of Strings. Printing a list such as "[Sequence{true}/]" will
generate "true"... yet "Sequence{true} = true" is false (as is
"Sequence{'test'} = 'test'")!
You have to either take only the first returned String or change your
condition.
-----
[if el.getKeywords().equalsIgnoreCase('test')->includes(true) ]
-----
[if el.getKeywords()->first().equalsIgnoreCase('test') ]
-----
Should both do the trick in your case.
Laurent Goubet
Obeo
Laviale Benoit wrote:
> Not it's always not running...... Is it a Bug?
>
> I am for your information, on the new 3.0 Release
--------------030500030309070708040708
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=
--------------030500030309070708040708--
|
|
|
|
Powered by
FUDForum. Page generated in 0.03892 seconds