|
Re: [QVTo] Recursive extension of targetelement's parent element [message #521819 is a reply to message #521730] |
Thu, 18 March 2010 19:32 |
PBarendrecht Messages: 36 Registered: November 2009 Location: Eindhoven, Netherlands |
Member |
|
|
Hmm are you allowed to post pictures of the meta-model?
Some time ago I noticed weird behaviour of returning sets of elements, see this topic: http://www.eclipse.org/forums/index.php?t=msg&goto=51746 0&#msg_517460
The main problem is, that returning sets are returned as siblings instead of children.
If I understand your case correctly, all Packages and their Sub-Packages should be mapped to Modules, these modules all on the same level.
There is a nice function to accomplish this:
self.allSubobjectsOfType(Package) returns a set of all Packages, it works recursively. Maybe you could use this function?
[Edit]
I understand your first piece of code, however I'm not sure whether it is possible to return other objects in a mapping than the result-objects. Maybe you could add the "modules"-object as result object? I don't have any experience with this.
It is always useful to add some log()-functions to your mappings, to check whether things are still working OK. By assigning an unique name to your module, you can check whether it is still the right module you add the packages to.
Your second piece only works for a input model with just two levels of Packages, but you indicated that yourself already.
[Updated on: Thu, 18 March 2010 19:46] Report message to a moderator
|
|
|
|
Re: [QVTo] Recursive extension of targetelement's parent element [message #524592 is a reply to message #524251] |
Thu, 01 April 2010 14:32 |
C. Kopf Messages: 37 Registered: November 2009 |
Member |
|
|
Quote: | I think it should be possible to write a work-around for my issue using
Quote: | allSubobjectsOfType(Package)->oclAsType(Package).map ...
|
So you made my day again! Pretty cool, thanks.
|
Well, as far as I can see my workaround works fine, so I though I should at least share it with you. I will post some more semantics than before, maybe it makes it easier to understand what I wanted to do. I took out the log-statements, but be sure: I used them a lot . So her it is:
mapping ARSEPGenIA::ARSEP::arsep2specification() : Specification {
result.modules := self.allSubobjectsOfType(Package)->oclAsType(Package)->select(p|not p.emptyPackage()).map package2module()->asOrderedSet();
}
where emptyPackage is a simple helper (i know I should have used reject instead of the select, but anyway it does the same ):
helper ARPackage::emptyPackage() : Boolean {
if ( self.subobjects() -> select(e|not (e.oclIsTypeOf(ARPackage))) -> isEmpty() ) then {
return true;
}
endif;
return false;
}
for completion here is the mapping for the Packages (here also some refactoring shall be done [e.g. if-cascade -> generalized mapping] ) :
mapping ARSEPGenIA::Package::package2module() : Module {
name := createPackageName(self);
self.elements->forEach(elem) {
if (elem.oclIsKindOf(Interface)) then {
... -- not of interest ;)
}
endif;
};
}
well ok, and createPackageName is a query for generating a name of the modules where all the 'parent packages' names are aggregated. It looks like this (pPackage points to the overlaying Package):
query createPackageName(in pack:Package) : String {
var name:String := pack.shortName;
var curPack:Package := pack;
while ((curPack.pPackage <> null)and(curPack.pPackage <> curPack)) {
curPack := curPack.pPackage;
name := curPack.shortName+"."+name;
};
return name;
}
So thanks again P!
Anyway the issue mentioned, as already said, still exists, so probably, someone familiar with the QVTo implementation in Eclipse might know some solution or look for one.
|
|
|
Powered by
FUDForum. Page generated in 0.04265 seconds