|Collections and typecasting... [message #987427]
||Mon, 26 November 2012 15:03
| Carsten Reckord
Registered: June 2012
I'm still having fun with QVT/OCL and UML profiles. I have a profile that
defines a Stereotype MyStereo that has a to-n reference to NamedElement:
usages : NamedElement[*];
Now, in an inplace QVTO transformation I'm working with elements that have
MyStereo applied and I want to 1) access and 2) add to the MyStereo::usages
I've tried several ways, but always hit a dead end at some typecast or
other. I can get the value typed as OclAny with
var stereo := self.getAppliedStereotype("MyProfile::MyStereo");
var value := self.getValue(stereo, "usages");
but then I don't know how to proceed to work with it as a Collection. I can
get a collection of the correct type doing something like
var usages := value.oclAsSet()->flatten()->selectByKind(NamedElement);
But the resulting Set is no longer the original collection. So when adding
an element to it with e.g.
I guess I have to set the resulting collection back on the Stereotype.
Unfortunately, this doesn't work:
self.setValue(stereo, "usages", usages);
"Cannot find operation (setValue(Stereotype, String,
Collection(NamedElement))) for the type Element"
I can't figure out how to cast usages so the setValue() operation is applicable.
Going the other way round by directly casting value to the correct type
doesn't work either. From what I could gather by stepping through the
parser, it's due to the known issues with type expressions. This:
var usages := value.oclAsType(Collection(NamedElement));
gives me "Unrecognized Variable: (Collection)" because it's resolved as a
variable expression instead of a collection type literal.
Do you have any suggestions for another, working way to add something into a
Powered by FUDForum
. Page generated in 0.14530 seconds