Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [xtend] How to write this transformation?
[xtend] How to write this transformation? [message #516438] Tue, 23 February 2010 17:42 Go to next message
No real name is currently offline No real nameFriend
Messages: 62
Registered: July 2009
Member
Hi,

I have to models MODEL1 and MODEL2 with class hierarchies like this:
(Classes are in capital letters, references not)

/-------------------------------------\
| MODEL1: |
| ------- |
| FBTYPE1 |
| inputEvents: List<INPUTEVENT> |
| outputEvents: List<OUTPUTEVENT> |
|-------------------------------------|
| MODEL2: |
| ------- |
| FBTYPE2 |
| interfaceList: INTERFACELIST |
| |
| INTERFACELIST |
| eventInputs: EVENTINPUTS |
| eventOutputs: EVENTOUTPUTS |
| |
| EVENTINPUTS |
| event: List<EVENT> |
| |
| EVENTOUTPUTS |
| event: List<EVENT> |
\-------------------------------------/

I'd like to transform an FBTYPE1 into an FBTYPE2 so that the resulting
FBTYPE2 has one EVENT for every INPUTEVENT or OUTPUTEVENT in FBTYPE1.

I started like this:

/----------------------------------------------------------- ---------\
| create functionblocks::FBType this FBTypeToFBType(cakefeed::FBTYPE |
| fbtype): |
| this.setName(fbtype.name) -> |
| this.setInterfaceList(EventsAndVarsToInterfaceList(fBType)) |
| ; |
| |
| create functionblocks::InterfaceList this |
| EventsAndVarsToInterfaceList(cakefeed::FBType fbtype): |
| this.setEventInputs(InputEventsToEventInputs(fbtype)) -> |
| this.setEventOutputs(OutputEventsToEventOutputs(fbtype)) |
| ; |
| |
| create functionblocks::EventInputs this |
| InputEventsToEventInputs(cakefeed::FBType fbtype): |
| this.setEvent(IFInputEventListToEventList(fbtype)) |
| ; |
| |
| create functionblocks::EventOutputs this |
| OutputEventsToEventOutputs(cakefeed::FBType fbtype): |
| this.setEvent(IFOutputEventListToEventList(fbtype)) |
| ; |
\----------------------------------------------------------- ---------/

In this case, IFInputEventListToEventList would create a list
that contains one Event for every IFInputEvent. However, I do
not know how to implement this. My first try looked like this:

/----------------------------------------------------------- ---------\
| create List this IFInputEventListToEventList(cakefeed::FBType |
| fbtype): |
| this.addAll(fbtype.inputEvents.<...>) |
| ; |
\----------------------------------------------------------- ---------/

In <...> I have to somehow transform every IFInputEvent into an Event.
How could this be done?

Maybe there is even a way to get rid of the list transformation and
instead to write something like
'fbtype.inputEvents.forAll(<add the Event that results from transforming
the IFInputEvent to this.event>)'.

Does anyone have an idea?

Thanks in advance,
Matthias
Re: [xtend] How to write this transformation? [message #516466 is a reply to message #516438] Wed, 24 February 2010 06:42 Go to previous messageGo to next message
Erhard Weinell is currently offline Erhard WeinellFriend
Messages: 39
Registered: January 2010
Location: Kassel, Germany
Member
Wouldn't this get the job done?

create INTERFACELIST FBType1ToInterfaceList(FBTYPE1 in):
eventInputs.addAll(in.inputEvents.FBType1ToEventInputs()) ->
...

create EVENTINPUTS FBType1ToEventInputs(FBType1 in):
event.addAll(in.inputEvents.InputEventToEvent();

create EVENT InputEventToEvent(INPUTEVENT in):
...

note, extensions can be called 'on' any type that fits their first
parameter. Plus, collections of these type are iterated implicitly.

Best regards,
Erhard Weinell
Re: [xtend] How to write this transformation? [message #516731 is a reply to message #516466] Wed, 24 February 2010 17:38 Go to previous message
No real name is currently offline No real nameFriend
Messages: 62
Registered: July 2009
Member
Erhard Weinell wrote:
> note, extensions can be called 'on' any type that fits their first
> parameter. Plus, collections of these type are iterated implicitly.

Oh, I didn't know that. And yes, it works. Thank you very much :)

Regards,
Matthias
Previous Topic:extending Xpand models
Next Topic:UML2 Profile Types Not Found
Goto Forum:
  


Current Time: Fri Apr 26 18:04:01 GMT 2024

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

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

Back to the top