[xtend] How to write this transformation? [message #516438] |
Tue, 23 February 2010 12:42  |
Eclipse User |
|
|
|
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 #516731 is a reply to message #516466] |
Wed, 24 February 2010 12:38  |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.41485 seconds