[QVTo] 'null' as a result object [message #516612] |
Wed, 24 February 2010 10:09  |
Eclipse User |
|
|
|
Hello again everybody,
QVTo and me, we get used to each other, so far.
Doing some more work of coding M2M-Tranformations using QVTo, I found the following issue:
I am using the following code. (Ideas as comments inline.)
mapping ARSEPGenIA::ARPackage::arpackage2module() : Module {
name := self.sName;
declarations:= self.elements.map packageableElements2moduleElement(result)->asOrderedSet();
}
/** Here we check the Type of each PackageableElement and choose the mapping which fits best. PackageableElement is an Interface or Abstract Class, ModuleElement is an Abstract Class.
**/
mapping ARSEPGenI::PackageableElement::packageableElements2moduleElement(inout module:Module) : ModuleElement{
// we need to do this in the init-part due to initialize a non-abstract return object:
init {
//case 1:
if(self.oclIsTypeOf(SenderReceiverInterface))
then {
result := self.oclAsType(SenderReceiverInterface).map senderReceiverInterface2messagePortType(); //object MessagePortType{}
}
else //case 2:
if (self.oclIsTypeOf(ARSEPComponents::AtomicSCT))
then {
result := self.oclAsType(AtomicSCT).map atomicSCT2Component(); //object Component{}
}
//so far everything works fine!
else // default case for all types of PackageableElements not explicitly mapped above
if(true)
then {
result := null; //THIS DOES NOT WORK!!!
module.annotations += object TS::SampleAnnotation{value := "No mapping rule exist for the following PackageableElement: "+self.shortName+" of type "+self.metaClassName()+" details: "+self.repr()};
}
endif
endif
endif;
}
}
The idea was: tranforming a ARPackage to a Module, we would like to add an annotation for each not mapped member of 'elements' (all not directly mapped subtypes of PackageableElement).
In "Meta Object Facility (MOF) 2.0 Query/View/Transformation
Specification - final adopted specification", chapter 8.1.17 says: "The literal null is a specific literal value that complies to any type. It can be explicitly returned by an operation (...)" but using it, as seen above, the QVT interpreter returns inc onsole:
" org.eclipse.m2m.internal.qvt.oml.evaluator.QvtRuntimeExcepti on: Cannot instantiate type ModuleElement
at ArtopToTS3::PackageableElement::packageableElements2moduleEl ement(ArtopToTS3.qvto:61) (...)"
line 61 is marked in the code above with "THIS DOES NOT WORK!!!"
Any ideas how to solve this?
Is my intention and understanding of the Specification correct?
Is this a challenge to QVTo-plugin?
Is there an other cause for this error?
Thanks again for your help!
Cheers,
Chris
[Updated on: Wed, 24 February 2010 10:11] by Moderator
|
|
|
Re: [QVTo] 'null' as a result object [message #516674 is a reply to message #516612] |
Wed, 24 February 2010 13:05   |
Eclipse User |
|
|
|
Hi Chris,
As far as I know, one can assign the "null"-value to any object. I assigned null to a result of one of my own mappings, it did work without any problems.
Therefore I think the problem lies with your datatype, ModuleElement. You wrote that this is an abstract class, I am not sure whether one can assign values to such a class. Maybe it is in the QVT or OCL documentation, I will take a look at it.
Furthermore, your "else if then" construct is a bit long-winded. You can just use "else { ... }" instead of "else if(true) then { ... } endif;". However, maybe the "if(true)" part is a simplified version of your code to test the code after that, I don't know.
Pieter
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 1.29559 seconds