|
Re: [QVTO] cloning self [message #488294 is a reply to message #488201] |
Sun, 27 September 2009 18:50 |
Eclipse User |
|
|
|
Originally posted by: dvorak.radek.gmail.com
Hi Derek,
I can imagine a single cause of this behavior, which
is self being of undefined value.
You can try to debug the invocation and set a break point at
org.eclipse.m2m.internal.qvt.oml.stdlib.ElementOperations.CL ONE.new
CallHandler() {...}.invoke(ModuleInstance, Object, Object[],
QvtOperationalEvaluationEnv)
Regards,
/Radek
On Sat, 26 Sep 2009 00:00:07 +0200, Derek Palma <derek.palma@gmail.com>
wrote:
> Hi,
>
> I am trying to clone self. I am not getting the result I expect so I
> thought I'd verify I am using it correctly. I need a copy of self since
> the container of self needs to owns its own copy. I just expect a
> shallow clone (versus deep). However, I appear to get nothing returned
> from clone(). Here is what I am doing:
>
> var cloned : WebAppArchive := self.clone();
> log("Dumping cloned: ", cloned);
>
> The log output is:
> Dumping cloned: , data: <Invalid>
>
> Thanks in advance.
> Derek
>
|
|
|
Re: [QVTO] cloning self [message #488298 is a reply to message #488294] |
Sun, 27 September 2009 19:07 |
Derek Palma Messages: 141 Registered: July 2009 |
Senior Member |
|
|
Hi Radek,
Thanks for the tip. I'll do it. In this particular case I am pretty sure
self is valid because I am able to extract properties from it and assign
them to result. In fact I created a variable which was an alias to self and
pretended it was cloned and I saw the right side-effect in my model (I just
lost the original self of course).
A corrollary question: Is checking if '<someVar> = null' the right way to
check programatically in QVT if self is null? I ran into this in other cases
where I was trying to assign to members of an undefined object. For example,
I have class A { B b; } and class B { C c; } and I was assigning to a.b.c
but since b was not yet created I the rest of my initialization did not
work. I guess I am somewhat surprised QVT does not have NullPointer
execption-like runtime failure. As a result I just need to assert the
correrct preconditions so I detect this since it usually gets caught down
stream.
Derek
"radek dvorak" <dvorak.radek@gmail.com> wrote in message
news:op.u0xink1212y5f2@kliste.local...
> Hi Derek,
>
> I can imagine a single cause of this behavior, which
> is self being of undefined value.
> You can try to debug the invocation and set a break point at
> org.eclipse.m2m.internal.qvt.oml.stdlib.ElementOperations.CL ONE.new
> CallHandler() {...}.invoke(ModuleInstance, Object, Object[],
> QvtOperationalEvaluationEnv)
>
> Regards,
> /Radek
>
>
> On Sat, 26 Sep 2009 00:00:07 +0200, Derek Palma <derek.palma@gmail.com>
> wrote:
>
>> Hi,
>>
>> I am trying to clone self. I am not getting the result I expect so I
>> thought I'd verify I am using it correctly. I need a copy of self since
>> the container of self needs to owns its own copy. I just expect a
>> shallow clone (versus deep). However, I appear to get nothing returned
>> from clone(). Here is what I am doing:
>>
>> var cloned : WebAppArchive := self.clone();
>> log("Dumping cloned: ", cloned);
>>
>> The log output is:
>> Dumping cloned: , data: <Invalid>
>>
>> Thanks in advance.
>> Derek
>>
|
|
|
Re: [QVTO] cloning self [message #488303 is a reply to message #488298] |
Sun, 27 September 2009 20:37 |
Eclipse User |
|
|
|
Originally posted by: dvorak.radek.gmail.com
>
> A corrollary question: Is checking if '<someVar> = null' the right way
> to check programatically in QVT if self is null?
Yes. You can also make use of OCL defined operations,
OclAny::oclIsUndefined() and
OclAny::oclIsInvalid().
> I ran into this in other cases where I was trying to assign to members
> of an undefined object. For example, I have class A { B b; } and class B
> { C c; } and I was assigning to a.b.c but since b was not yet created I
> the rest of my initialization did not work. I guess I am somewhat
> surprised QVT does not have NullPointer execption-like runtime failure.
> As a result I just need to assert the correrct preconditions so I detect
> this since it usually gets caught down stream.
>
It's not QVT but OCL which defines this behavior. BTW, it's pretty useful
feature as
you can write a complex navigation path and do not have to perform multiple
checks for undefined references. Just a single check whether the final
target
of the navigation is available or not, which reduces verbosity pretty well.
Imagine how much work you have to do in Java to avoid NPE.
On the other hand, the user is still allowed to decompose the navigation
expression and perform multiple checks as needed.
Also, you can always write something like below:
var c := a.b.c;
assert fatal (not c.oclIsUndefined()); -- this may throw runtime
exception
Perhaps, it might be useful to add a custom evaluation option to raise a
runtime
exception if the left side of an assignment is undefined, though the OMG
spec
does not say anything about that.
Regards,
/Radek
|
|
|
Powered by
FUDForum. Page generated in 0.04274 seconds