|
Re: Null-safe navigator operator [message #1840456 is a reply to message #1840453] |
Thu, 15 April 2021 16:46 |
|
ATL/EMFTVM allows you to define helper attributes and operations on OclAny, which also work for OclUndefined (ATL's null), e.g.:
--- Default implementation for allValues, also for OclUndefined.
helper context OclAny def : allValues : String =
'';
--- Implementation for (non-OclUndefined) INMM!Child instances.
helper context INMM!Child def : allValues : String =
self.value1 + ',' + self.value2;
rule Test {
from
s : INMM!Parent
to
t : OUTMM!Element (
value <- s.optionalChild.allValues)
}
This is possible because of the dynamic (multiple) dispatch mechanism implemented in EMFTVM.
Cheers,
Dennis
|
|
|
|
Re: Null-safe navigator operator [message #1840469 is a reply to message #1840460] |
Thu, 15 April 2021 21:44 |
|
While it is possible to use '?' as the name of a helper by putting double quotes around it (e.g. "?" or "?allValues"), it is not possible to define a generic null-safe navigator helper function that takes the remainder of the OCL expression as an argument (as described in https://www.oracle.com/technical-resources/articles/java/java8-optional.html).
Just in case you were going to ask: you could try to whip something up in SimpleOCL, which supports Lambda type parameters in helper funtions and also compiles to EMFTVM, but it would look very artificial, e.g.:
context OclAny def : "?"(f : Lambda(OclAny) : OclAny) : OclAny =
if self.oclIsUndefined() then
OclUndefined
else
f(self)
endif;
context OclAny def : "?:"(other : OclAny) : OclAny =
if self.oclIsUndefined() then
other
else
self
endif;
...which could be used as follows:
s.optionalChild->"?"(c | c.allValues)."?:"('')
While this probably implements the ? and ?: operators you had in mind, the syntax to use them in ATL as it is now is just horrible.
Cheers,
Dennis
|
|
|
|
Powered by
FUDForum. Page generated in 0.02492 seconds