Issue 19177: xcollect is ambiguously flattened (qvt-rtf) Source: Model Driven Solutions (Dr. Edward Willink, ed(at)willink.me.uk) Nature: Clarification Severity: Minor Summary: xcolect is specified to like collect, which flattens, however the xcollect pseudocode does not flatten. Resolution: xcollect is ambiguously flattened xcollect is specified to like collect, which flattens, however the xcollect pseudocode does not flatten. Discussion Ditto xcollectselect, xcollectselectOne Once an attempt is made to put the pseudo-code through Eclipse QVTo, it is quite amazing how many different errors there are. *spurious source/iterator arguments *missing compute open { *increarect non-collection returns *incorrect accommodation of ordered collections *no flattening *no single values *use of mutable Sequence rather than List Revised Text: In 8.2.2.7 ImperativeIterateExp Collection(T)::xcollect(source, iterator, body) replace Collection(T)::xcollect(source, iterator, body) : Sequence(TT) = compute (res:Sequence(TT) := Sequence{}) source->forEach (iterator:T) { var target : TT := body; if (target<>null) res += target; }; Collection(T)::xselect(source, iterator, condition) : Sequence(T) = compute (res:Sequence(T) := Sequence{}) source->forEach (iterator:T) { var target : T := iterator; if (target<>null and condition) res += target; }; Collection(T)::xselectOne(source, iterator, condition) : Sequence(T) = compute (res:Sequence(T) := Sequence{}) source->forEach (iterator:T) { var target : T := iterator; if (target<>null and condition) {res += target; break;} }; Collection(T)::xcollectselect(source, iterator, target, body, condition) : Sequence(TT) = compute (res:Sequence(TT) := Sequence{}) source->forEach (iterator:T) { var target : TT := body; if (target<>null and condition) res += target; }; Collection(T)::xcollectselectOne(source, iterator, target, body, condition) : Sequence(TT) = compute (res:Sequence(TT) := Sequence{}) source->forEach (iterator:T) { var target : TT := body; if (target<>null and condition) {res += target; break;} }; T and TT are respectively the type of the source elements and the type of the target elements. When applying the imperative iterate expression if the source collection is not ordered, it is implicitly converted into the corresponding ordered collection (Set and Bag become respectively OrderedSet and Sequence). If the condition is not given, it should be replaced by true in the definitions above. by Collection(T)::xcollect(BODY) : BagOrSequence(TT) = compute (res : List(TT) := List{}) { self->forEach(COLLECTOR) { BODY->flatten()->forEach(target) { if (target <> null) res += target; }; }; }->asBagOrSequence(); Collection(T)::xselect(CONDITION) : BagOrOrderedSetOrSequenceOrSet(T) = compute (res : List(T) := List{}) { self->forEach(SELECTOR) { if (SELECTOR<> null and CONDITION) res += SELECTOR; }; }->asBagOrOrderedSetOrSequenceOrSet(); Collection(T)::xselectOne(CONDITION) : T = compute (res : T := null) { self->forEach(SELECTOR) { if (SELECTOR<> null and CONDITION) { res := SELECTOR; break; } }; }; Collection(T)::xcollectselect(BODY, CONDITION) : BagOrSequence(TT) = compute (res : List(TT) := List{}) { self->forEach(COLLECTOR) { BODY->flatten()->forEach(SELECTOR) { if (SELECTOR <> null and CONDITION) { res += SELECTOR; } }; }; }->asBagOrSequence(); Collection(T)::xcollectselectOne(BODY, CONDITION) : TT = compute (res : TT := null) { self->forEach(COLLECTOR) { BODY->flatten()->forEach(SELECTOR) { if (SELECTOR <> null and CONDITION) { res := SELECTOR; break; } }; if (res <> null) { break; } }; }; where *BagOrOrderedSetOrSequenceOrSet denotes the Bag, OrderedSet, Sequence or Set kind of the source Collection *BagOrSequence denotes either Bag or Sequence according to whether the source Collection is unordered or ordered *BODY is a TT-valued Imperative OCL expression that may use the COLLECTOR variable *CONDITION is a Boolean-valued Imperative OCL expression that may use the SELECTOR variable Actions taken: January 9, 2014: received issue December 22, 2015: Resolved March 29, 2016: closed issue Discussion: End of Annotations:===== m: webmaster@omg.org Date: 09 Jan 2014 06:38:31 -0500 To: Subject: Issue/Bug Report ******************************************************************************* Name: Edward Willink Employer: mailFrom: ed@willink.me.uk Terms_Agreement: I agree Specification: QVT Section: 8.2.2.7 FormalNumber: 1.1 Version: 1.1 Doc_Year: 2011 Doc_Month: January Doc_Day: 01 Page: 109 Title: xcollect is ambiguously flattened Nature: Clarification Severity: Minor CODE: 3TMw8 B1: Report Issue Remote Name: edwillink.plus.com Remote User: HTTP User Agent: Mozilla/5.0 (Windows NT 6.0; rv:26.0) Gecko/20100101 Firefox/26.0 Time: 06:38 AM Description: xcolect is specified to like collect, which flattens, however the xcollect pseudocode does not flatten.