Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Mono and multi valued attributes
Mono and multi valued attributes [message #1850226] Tue, 22 February 2022 10:18 Go to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi all,

I came across the following paragraph in a research paper.

Since QVT-O distinguish between assignments to mono- or multi-valued properties or variables, this has also to be considered during the processing of attributes. Hence, a simple assignment (':=' operator) is used for the mapping of an attribute with an upper multiplicity of 1. In contrast, attributes with an upper multiplicity of >1 are assigned with a composite assignment ('+=' operator).

From my understanding this means that if the source element is a collection then we use += and if it is not, we use :=.

Is that always the case?
For example if I map
result.multiA += self.multiB -> map ... (this works fine)
result.singleA += self.multiB -> map ... (I get an error "Property singleA must have collection type").


And the rest should be like this?
result.singleA := self.singleB. map
result.multiA := self.singleB .map


Moreover , I have read that when executing the mapping on a single element, after the element we put a dot not an arrow, and executing the mapping on a collection of elements, we put an arrow. But is that for the input or output? So when the input is single/collection or when the output is single/collection?
Re: Mono and multi valued attributes [message #1850229 is a reply to message #1850226] Tue, 22 February 2022 10:45 Go to previous messageGo to next message
Christopher Gerking is currently offline Christopher GerkingFriend
Messages: 116
Registered: April 2011
Senior Member
Hi

John Henbergs wrote on Tue, 22 February 2022 05:18

From my understanding this means that if the source element is a collection then we use += and if it is not, we use :=.

Not entirely. If the source element is a collection then we use either += (to add the element to the collection) or := (to reinitialize the collection with the element, dropping all previous elements). If it is not a collection, we use := because adding is not possible. As you can see, the difference is whether you would like to reset your collection or not. By the way, this is something you could have found out really easily using the QVTo debugger.

John Henbergs wrote on Tue, 22 February 2022 05:18

result.singleA += self.multiB -> map ... (I get an error "Property singleA must have collection type").
But this makes a lot of sense, isn't it? multB is multi-valued. You invoke a mapping on each of these values, resulting in a collection of mapping results. Obviously you can't assign that collection to singleA because it is single-valued. What behavior did you expect instead?


John Henbergs wrote on Tue, 22 February 2022 05:18

Moreover , I have read that when executing the mapping on a single element, after the element we put a dot not an arrow, and executing the mapping on a collection of elements, we put an arrow. But is that for the input or output? So when the input is single/collection or when the output is single/collection?
For the difference between the dot and arrow notations, take a look at this recent topic: https://www.eclipse.org/forums/index.php/t/1109682/


Kind regards
Christopher
Re: Mono and multi valued attributes [message #1850233 is a reply to message #1850229] Tue, 22 February 2022 11:18 Go to previous messageGo to next message
John Henbergs is currently offline John HenbergsFriend
Messages: 239
Registered: October 2020
Senior Member
Hi Christopher,

Regarding the last question, in the older topic you say:

In general, the . operator is used to access properties or invoke operations of a single element, just like you would do in Java. The -> operator is used to invoke a predefined operation (such as collect, select, etc.) on a Collection of multiple elements. These are the general rules, depending on whether the variable on the left is a single element or a Collection.

My confusion starts when you say depending on the variable on the left. The mapping is invoked on the source element right? And the source elements is on the right?
result.target := self.source -> map. ...
So why is it dependant on whether the variable on the left (i.e., target ) is a single element or a collection?

Many thanks!
Re: Mono and multi valued attributes [message #1850236 is a reply to message #1850233] Tue, 22 February 2022 11:32 Go to previous message
Christopher Gerking is currently offline Christopher GerkingFriend
Messages: 116
Registered: April 2011
Senior Member
John Henbergs wrote on Tue, 22 February 2022 06:18
My confusion starts when you say depending on the variable on the left.

I was referring to the left-hand side of the invocation (not the assignment). So it is important what is directly left to the arrow or dot.

John Henbergs wrote on Tue, 22 February 2022 06:18
And the source elements is on the right?
It's on the right of the assignment, but on the left of the invocation.

John Henbergs wrote on Tue, 22 February 2022 06:18
So why is it dependant on whether the variable on the left (i.e., target ) is a single element or a collection?
It isn't. The meaning of the notation depends on what is directly left of the dot or arrow (self.source in your case). What is on the left of the assignment (result.target) is not relevant because there is not necessarily an assignment.
Previous Topic:Replace conditional statements with queries
Next Topic:Qualified name of reference
Goto Forum:
  


Current Time: Wed Sep 18 20:09:34 GMT 2024

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

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

Back to the top