[QVTo] 'null' as a result object [message #516612] |
Wed, 24 February 2010 15:09 |
C. Kopf Messages: 37 Registered: November 2009 |
Member |
|
|
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 15:11] Report message to a moderator
|
|
|
Re: [QVTo] 'null' as a result object [message #516674 is a reply to message #516612] |
Wed, 24 February 2010 18:05 |
PBarendrecht Messages: 36 Registered: November 2009 Location: Eindhoven, Netherlands |
Member |
|
|
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
|
|
|
Re: [QVTo] 'null' as a result object [message #516753 is a reply to message #516612] |
Thu, 25 February 2010 00:10 |
Alex Mising name Messages: 51 Registered: August 2009 |
Member |
|
|
QVTo is attempting to instantiate ModuleElement because at the end of the "init" section "result" is null. This behavior is prescribed by the QVT spec. It fails because ModuleElement is abstract and thus cannot be instantiated. If you want to skip mapping for a particular condition you are better off using a "when" guard. Direct return from mapping might be another way, but this is not supported in QVTo yet. The only other (ugly) workaround I am aware of would be to assign something temporary to result in the "init" section (to defeat auto-instantiation) and cleanup / assign null in "end" section.
[Updated on: Thu, 25 February 2010 00:13] Report message to a moderator
|
|
|
Re: [QVTo] 'null' as a result object [message #516827 is a reply to message #516753] |
Thu, 25 February 2010 09:55 |
Eclipse User |
|
|
|
Originally posted by: Alexander.Igdalov.gmail.com
Hi All,
Alex, I agree. An alternative workaround could be skipping the mapping
invocation in the calling code, i.e. in
mapping ARSEPGenIA::ARPackage::arpackage2module(). The code would then
look like:
mapping ARSEPGenIA::ARPackage::arpackage2module() : Module {
name := self.sName;
if (self.oclIsTypeOf(SenderReceiverInterface) or
self.oclIsTypeOf(ARSEPComponents::AtomicSCT)) {
declarations:= self.elements.map
packageableElements2moduleElement(result)->asOrderedSet();
} else {
declarations:=null;
annotations += object TTCN3::SampleAnnotation{value := "No mapping
rule exist for the following PackageableElement: "+self.shortName+" of
type "+metaClassName()+" details: "+repr()};
}
}
Perhaps, the mapping
ARSEPGenI::PackageableElement::packageableElements2moduleEle ment() could
be completely eliminated with its logic moved to
mapping ARSEPGenIA::ARPackage::arpackage2module()...
Cheers,
- Alex.
Alex wrote:
> QVTo is attempting to instantiate ModuleElement because at the end of
> the "init" section "result" is null. This is the behavior prescribed by
> QVT spec. If you want to skip mapping for a particular condition you are
> better off using a "when" guard. Direct return from mapping might be
> another way, but this is not supported in QVTo yet. The only other
> (ugly) workaround I am aware of would be to assign something temporary
> to result in the "init" section (to defeat auto-instantiation) and
> cleanup / assign null in "end" section.
|
|
|
|
Powered by
FUDForum. Page generated in 0.03849 seconds