Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Null-safe navigator operator
Null-safe navigator operator [message #1840453] Thu, 15 April 2021 15:13 Go to next message
jo ber is currently offline jo berFriend
Messages: 92
Registered: August 2018
Member
Hi

I was wondering if ATLprovides a 'null-safe navigator operator'.

Kind regards,
Re: Null-safe navigator operator [message #1840456 is a reply to message #1840453] Thu, 15 April 2021 16:46 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 581
Registered: September 2012
Location: Belgium
Senior Member

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 #1840460 is a reply to message #1840456] Thu, 15 April 2021 18:05 Go to previous messageGo to next message
jo ber is currently offline jo berFriend
Messages: 92
Registered: August 2018
Member
I also had the idea of using using helper functions, but I specifically would like to use a non-alphabetical symbol such as '?' to name the function.
Re: Null-safe navigator operator [message #1840469 is a reply to message #1840460] Thu, 15 April 2021 21:44 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 581
Registered: September 2012
Location: Belgium
Senior Member

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
Re: Null-safe navigator operator [message #1840508 is a reply to message #1840469] Fri, 16 April 2021 20:32 Go to previous message
jo ber is currently offline jo berFriend
Messages: 92
Registered: August 2018
Member
thank you for your answer
Previous Topic:Listing Format of ATL Rules in Latex
Next Topic:Compilation of rule
Goto Forum:
  


Current Time: Sat Nov 11 08:17:32 GMT 2023

Powered by FUDForum. Page generated in 0.02492 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top