Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo]Need OCL expert Trick!
[Acceleo]Need OCL expert Trick! [message #548715] Thu, 22 July 2010 17:30 Go to next message
Charlie Mordant is currently offline Charlie MordantFriend
Messages: 88
Registered: July 2010
Member

Hi all,

I read the entire Acceleo and ocl spec, and tried to make my own template.
I just need one more thing to complete it, but I'm not able to find the solution.

I want to generate text only one time when facing one or more *ToMany Association.
For example, importing java.util.Collection when got a toMany relationship.
I tried this:
[if(c.getAssociations().memberEnd->select(p:Property | p.upper <> 1).type->excluding(self)->size() > 0)]
import java.util.Collection;
[/if]

But it fails when I got a reflexive Association (Collection is not printed due to the excluding(self) condition).

Is there a way to solve this?

The ideal would be to know when i'm facing oneToMany relationship or manyToMany relationship, for example, importing javax.annotation.OneToMany or javax.annotation.ManyToMany depending the association upper's opposite.

Thank you in advance, Charlie
Re: [Acceleo]Need OCL expert Trick! [message #548717 is a reply to message #548715] Thu, 22 July 2010 17:43 Go to previous messageGo to next message
Sebastien Roy is currently offline Sebastien RoyFriend
Messages: 51
Registered: November 2009
Member
Hello Charlie,

You can try something like :
[if(c.attribute->exists(prop : Property | not(prop.association.oclIsUndefined()) and prop.upper <> 1))]
import java.util.Collection;
[/if]


Regards

Sebastien
Re: [Acceleo]Need OCL expert Trick! [resolved] [message #548718 is a reply to message #548717] Thu, 22 July 2010 17:53 Go to previous message
Charlie Mordant is currently offline Charlie MordantFriend
Messages: 88
Registered: July 2010
Member

Nice solution!
I never thought about that.

The more I practice and ask for questions, the more I discover elegant solution to problems.

I just didn't realized the power of oclIsUndefined, I'll just have to refactorize some code Wink.

Thank you so much, Charlie
Previous Topic:Problem running WorkflowRunner from java.
Next Topic:[ATL] Problem ATL query with Eclipse helios
Goto Forum:
  


Current Time: Thu Apr 25 05:30:18 GMT 2024

Powered by FUDForum. Page generated in 0.02347 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top