Jumping over abstract model elements of source [message #1061281] |
Fri, 31 May 2013 00:22 |
Emre T Messages: 119 Registered: April 2013 |
Senior Member |
|
|
Hello again!
I need to be able to jump over the abstract model elements of the source model, which don't need to be transformed into the target. But their children should be. I will try to sketch it. Hope it helps to understand it easier.
==> ... means inheritance
--> ... means composition
[..] ... means abstract
SOURCE:
Factory --has--> [AbstractVehicle] <== [SecondAbstractVehicle] <== Car / Boat
Here are the Car and Boat both different classes which inherits from SecondAbstractVehicle. And SecondAbstractVehicle inherits from AbstractVehicle. So the factory can have any number of cars or boats.
TARGET:
Something --references--> AnotherThing
And my mappings look like the following:
mapping Factory::toMap() : Something {
references := self.has -> map toMapAgain() -> any(true); // error
}
mapping Car::toMapAgain() : AnotherThing { ... }
And the error it gives is this: Cannot find operation (toMapAgain()) neither for the type (Set(AbstractVehicle)) nor for its element type (AbstractVehicle)
But, when I change the concrete model element Car (the input in toMapAgain()-mapping) into the abstract model element AbstractVehicle, which the factory actually has directly, the error goes away. But then of course, I can't access the properties or references of the model element Car.
Another thing is, don't know if it any differences make, but when I delete the any(true) at the end, I get a second error beside the above one, and that is: Mapping operation expected
Can't see what I am doing wrong. But i guess what I'm trying to do has to be possible. I would be very glad, if you could point me to the right direction and explain how and why it is done that way.
Thanks a lot!
P.S.: I find it very interesting, because with the elements of the target model, I don't get these kind of problems regarding the inherited model elements. I can jump to any target model element in any mapping definition. But it doesn't happen so freely with the source model elements.
|
|
|
Re: Jumping over abstract model elements of source [message #1061301 is a reply to message #1061281] |
Fri, 31 May 2013 05:53 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
Hi
Your question is too hard for me to understand quickly.
Why do you have to sketch it? What is wrong with an Ecore model that I
can look at?
You need to spend more time prepaaring your questions.
Regards
Ed Willink
On 31/05/2013 01:22, Emre Taspolatoglu wrote:
> Hello again!
>
> I need to be able to jump over the abstract model elements of the
> source model, which don't need to be transformed into the target. But
> their children should be. I will try to sketch it. Hope it helps to
> understand it easier. :)
>
> ==> ... means inheritance
> --> ... means composition
> [..] ... means abstract
>
> SOURCE:
> Factory --has--> [AbstractVehicle] <== [SecondAbstractVehicle] <== Car
> / Boat
>
> Here are the Car and Boat both different classes which inherits from
> SecondAbstractVehicle. And SecondAbstractVehicle inherits from
> AbstractVehicle. So the factory can have any number of cars or boats.
> TARGET:
> Something --references--> AnotherThing
>
> And my mappings look like the following:
>
> mapping Factory::toMap() : Something {
>
> references := self.has -> map toMapAgain() -> any(true); // error
>
> }
>
> mapping Car::toMapAgain() : AnotherThing { ... }
>
> And the error it gives is this: Cannot find operation (toMapAgain())
> neither for the type (Set(AbstractVehicle)) nor for its element type
> (AbstractVehicle)
>
> But, when I change the concrete model element Car (the input in
> toMapAgain()-mapping) into the abstract model element AbstractVehicle,
> which the factory actually has directly, the error goes away. But then
> of course, I can't access the properties or references of the model
> element Car.
>
> Another thing is, don't know if it any differences make, but when I
> delete the any(true) at the end, I get a second error beside the above
> one, and that is: Mapping operation expected
>
> Can't see what I am doing wrong. But i guess what I'm trying to do has
> to be possible. I would be very glad, if you could point me to the
> right direction and explain how and why it is done that way.
>
> Thanks a lot!
>
> P.S.: I find it very interesting, because with the elements of the
> target model, I don't get these kind of problems regarding the
> inherited model elements. I can jump to any target model element in
> any mapping definition. But it doesn't happen so freely with the
> source model elements.
>
>
>
>
>
|
|
|
|
|
|
Re: Jumping over abstract model elements of source [message #1061435 is a reply to message #1061418] |
Fri, 31 May 2013 15:34 |
Adolfo Sanchez-Barbudo Herrera Messages: 260 Registered: July 2009 |
Senior Member |
|
|
By some reasons, replying via newsgroup didn't update the forum.... I should have done something wrong
Replying via Web browser:
Cheers,
Adolfo.
-----
Hi Emre,
A couple of comments:
> mapping Factory::toMap() : Something {
>
> references := self.has -> map toMapAgain() -> any(true); // error
>
> }
Because of the fact that Factory::has is a mono-valued reference, you should rather call the mapping as follows:
references := self.has.map toMapAgain()
avoiding the implicit collection creation (self.has->) and hence avoiding use the additional -> any(true):
> And the error I get is: Cannot find operation (toMapAgain()) neither for
> the type (Set(AbstractVehicle)) nor for its element type (AbstractVehicle)
As the error says your toMapAgain() is not defined on the AbstractVehicle class, so a mapping defined over your car can't be invoked. A typical way to resolve that is taking advantage of the virtual mapping calling capability of QVTo. So, creating an abstract mapping over the AbstractVehicle like the following one should work for you:
abstract mapping AbstractVehicle::toMapAgain() : AnotherThing;
mapping Car::toMapAgain() : AnotherThing { ... }
mapping Boat::toMapAgain() : AnotherThing { ... }
Using disjunct mappings is also another alternative (See the QVTo Specification or the slides in the Eclipse Help -> QVT Operational Developer Guide -> Overview)
Cheers,
Adolfo.
[Updated on: Fri, 31 May 2013 15:35] Report message to a moderator
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04768 seconds