Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » ATL » Is it possible to increment and store a variable in helper context declerative part?
Is it possible to increment and store a variable in helper context declerative part? [message #1853281] Sat, 25 June 2022 22:19 Go to next message
Burak Karaduman is currently offline Burak KaradumanFriend
Messages: 84
Registered: July 2018
Member
Dear all,

Is it possible to increment and store a variable in the helper context declarative part in the EMFVTM version?

The imperative-do part does not update the statement such as ''thisModule.count <- thisModule.count +1;'. Is it also possible to achieve such an operation using helper context?

Thank you.

Best regards.
Re: Is it possible to increment and store a variable in helper context declerative part? [message #1853317 is a reply to message #1853281] Mon, 27 June 2022 17:41 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 581
Registered: September 2012
Location: Belgium
Senior Member

I'm a bit surprised that you code does not work from the "do"-part. That said, there is a way to cause side-effects in helpers using reflective operations, such as this example:
helper def: diff1 : Integer = 0;

-- This helper increments diff1 value
-- CONTEXT: thisModule
-- RETURN:  Integer
helper def: incDiff2() : Integer =
 thisModule.refSetValue('diff2', thisModule.diff2+1).diff2; 


EDIT: not sure this works in EMFTVM, however... Just checked the source code for refSetValue(), and it seems to only support EObjects...


Cheers,
Dennis

[Updated on: Mon, 27 June 2022 17:44]

Report message to a moderator

Re: Is it possible to increment and store a variable in helper context declerative part? [message #1853324 is a reply to message #1853317] Mon, 27 June 2022 19:26 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 581
Registered: September 2012
Location: Belgium
Senior Member

https://github.com/dwagelaar/atl.examples/tree/main/ATLGlobalIncrement demonstrates how EMFTVM does global attribute changes.

Cheers,
Dennis
Re: Is it possible to increment and store a variable in helper context declerative part? [message #1853355 is a reply to message #1853324] Tue, 28 June 2022 21:38 Go to previous messageGo to next message
Burak Karaduman is currently offline Burak KaradumanFriend
Messages: 84
Registered: July 2018
Member
Hi Dennis,

When I try to run the refSetValue, it says "org.eclipse.m2m.atl.emftvm.util.VMException: java.lang.UnsupportedOperationException: static EMFTVM!ExecEnv::refSetValue(String, Integer)
at static EMFTVM!ExecEnv::incDiff2() : Integer#12(platform:/resource//PIMtoPSM/DSML4Riot.atl#[59:29-59:80])
Local variables: []"

Is it related to only supporting the EObjects?

EDIT: static EMFTVM!ExecEnv:: ... problem also happens when I would like to debug something in do part as well such as { thisModule...[anything] < thisModule...[anything] } is there a way to bypass it? I would like to debug and test some operations before assigning them to the properties.

Best regards.

[Updated on: Tue, 28 June 2022 22:54]

Report message to a moderator

Re: Is it possible to increment and store a variable in helper context declerative part? [message #1853414 is a reply to message #1853355] Thu, 30 June 2022 20:14 Go to previous messageGo to next message
Burak Karaduman is currently offline Burak KaradumanFriend
Messages: 84
Registered: July 2018
Member
Hi Dennis,

I inspected the link and examples, also tried to run the example below

helper context OclAny def: makeIdentity() : String =
let i : Integer = thisModule.refSetValue('curId', thisModule.curId + 1).curId
in '10000000-0000-0000-0000-'+
if i<=9 then '00000000000'+i.toString()
else if i<=99 then '0000000000'+i.toString()
else if i<=999 then '000000000'+i.toString()
else '00000000'+i.toString()
endif
endif
endif;

Well, If resolveTemp only supports eObjects, is it possible to create an artificial built-in object that has .counter feature so that I can use resolveTemp function on that artificially created object to increment my counter?

Thank you.

Best regards.
Re: Is it possible to increment and store a variable in helper context declerative part? [message #1853415 is a reply to message #1853414] Thu, 30 June 2022 20:32 Go to previous messageGo to next message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 581
Registered: September 2012
Location: Belgium
Senior Member

I created https://bugs.eclipse.org/bugs/show_bug.cgi?id=580300 for the missing functionality in EMFTVM. Next ATL release should have the fix included.

Quote:
Well, If resolveTemp only supports eObjects, is it possible to create an artificial built-in object that has .counter feature so that I can use resolveTemp function on that artificially created object to increment my counter?


I suppose you mean refSetValue, not resolveTemp? You could indeed create some model element that has an integer attribute, and increment that as you go, but you'll probably end up with your output model containing that extra model element.


Cheers,
Dennis
Re: Is it possible to increment and store a variable in helper context declerative part? [message #1853442 is a reply to message #1853415] Fri, 01 July 2022 18:57 Go to previous messageGo to next message
Burak Karaduman is currently offline Burak KaradumanFriend
Messages: 84
Registered: July 2018
Member
Hi Dennis,

Thank you so much for your help.

Approximately, when the new version is released?

Thank you.
Re: Is it possible to increment and store a variable in helper context declerative part? [message #1855880 is a reply to message #1853415] Tue, 08 November 2022 18:37 Go to previous messageGo to next message
Burak Karaduman is currently offline Burak KaradumanFriend
Messages: 84
Registered: July 2018
Member
Dear Dennis,

Are you sure that this is fixed in the ATL 4.6.0? I still experience the same error.

Thank you.

Best regards.


It works with the nighly verison. Thank you.

I have a new question now, which is an extension of this. Assume that A contains B. For each B element I increase this counter, but for each different A I should reset the counter so that other set of B's can start from 0. I think i need to form a kind of specific endpoint rule.

Best regards.

[Updated on: Tue, 08 November 2022 22:07]

Report message to a moderator

Re: Is it possible to increment and store a variable in helper context declerative part? [message #1856340 is a reply to message #1855880] Sun, 04 December 2022 20:16 Go to previous message
Dennis Wagelaar is currently offline Dennis WagelaarFriend
Messages: 581
Registered: September 2012
Location: Belgium
Senior Member

Burak Karaduman wrote on Tue, 08 November 2022 19:37
Assume that A contains B. For each B element I increase this counter, but for each different A I should reset the counter so that other set of B's can start from 0. I think i need to form a kind of specific endpoint rule.


Can you just use the index at which each B is contained within A, like this:

helper context MM!B def : counter : Integer =
  if self.refImmediateComposite().oclIsUndefined() then
    -1
  else
    self.refImmediateComposite().ownedB->indexOf(self)
  endif;

rule B {
  from
    source : MM!B
  to
    target : MM!B (
      property <- source.counter
    )
}


Cheers,
Dennis
Previous Topic:How to collect all of the iteration results?
Next Topic:Accessing inherited tag values from applied stereotypes
Goto Forum:
  


Current Time: Sat Nov 11 08:16:59 GMT 2023

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

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

Back to the top