Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Writing to helpers in model element context
[ATL] Writing to helpers in model element context [message #65726] Sun, 04 November 2007 11:30 Go to next message
Lorenzo Dalla Vecchia is currently offline Lorenzo Dalla VecchiaFriend
Messages: 58
Registered: July 2009
Member
Hi.

Recently I tried to define attributes (non-functional helpers) in the
context of a model element and then writing to them, but with no success.

I define the helper with code like this:

helper context Metamodel!Element def: attr : Integer = 0;

However, if I try to set the attribute with imperative code like...

foreach (el in Metamodel!Element.allInstances())
{
el.attr <- 1;
}

.... execution fails with error "GRAVE: message: feature attr does not exist
on Metamodel!Element".
In case it matters, I tried setting attributes both in the entrypoint rule
and in rules called by matched rules.

This happens only with attributes having context. I can work around the
problem by using module-level attributes instead, using a Map type to
associate values with elements, but I'm not liking it because the code
becomes bloated.

Is this a bug or am I missing something?
Thanks.

--
Lorenzo
Re: [ATL] Writing to helpers in model element context [message #65751 is a reply to message #65726] Mon, 05 November 2007 08:33 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mddfabro.ilog.fr

Hello,

attribute helpers are side-effect free, which means they can be used
only to get/calculate values.

So, the solution to set up values is to use a Map as you did.

Regards,

Marcos.

Lorenzo Dalla Vecchia wrote:
> Hi.
>
> Recently I tried to define attributes (non-functional helpers) in the
> context of a model element and then writing to them, but with no success.
>
> I define the helper with code like this:
>
> helper context Metamodel!Element def: attr : Integer = 0;
>
> However, if I try to set the attribute with imperative code like...
>
> foreach (el in Metamodel!Element.allInstances())
> {
> el.attr <- 1;
> }
>
> ... execution fails with error "GRAVE: message: feature attr does not
> exist on Metamodel!Element".
> In case it matters, I tried setting attributes both in the entrypoint
> rule and in rules called by matched rules.
>
> This happens only with attributes having context. I can work around the
> problem by using module-level attributes instead, using a Map type to
> associate values with elements, but I'm not liking it because the code
> becomes bloated.
>
> Is this a bug or am I missing something?
> Thanks.
>
> --
> Lorenzo
Re: [ATL] Writing to helpers in model element context [message #66831 is a reply to message #65751] Tue, 27 November 2007 03:32 Go to previous message
Frédéric Jouault is currently offline Frédéric JouaultFriend
Messages: 572
Registered: July 2009
Senior Member
Hello,

Here are some precisions: context-less attribute helpers ("helper def:")
can be set form imperative code. Other attribute helpers ("helper
context MM!CC def:) cannot be set, only queried.

As Marcos said, the reason is that there are declarative, and
side-effect free. However, it should be possible to implement the
behavior your describe when attribute values are cached. If this is not
the case, then a special case could be added: first check if in cache,
else compute value but do not put in cache.

However, I am not sure implementing this feature would be a step in the
"right" (i.e., declarative ;-)) direction.


Regards,

Frédéric Jouault


Marcos Didonet Del Fabro wrote:
> Hello,
>
> attribute helpers are side-effect free, which means they can be used
> only to get/calculate values.
>
> So, the solution to set up values is to use a Map as you did.
>
> Regards,
>
> Marcos.
>
> Lorenzo Dalla Vecchia wrote:
>> Hi.
>>
>> Recently I tried to define attributes (non-functional helpers) in the
>> context of a model element and then writing to them, but with no success.
>>
>> I define the helper with code like this:
>>
>> helper context Metamodel!Element def: attr : Integer = 0;
>>
>> However, if I try to set the attribute with imperative code like...
>>
>> foreach (el in Metamodel!Element.allInstances())
>> {
>> el.attr <- 1;
>> }
>>
>> ... execution fails with error "GRAVE: message: feature attr does not
>> exist on Metamodel!Element".
>> In case it matters, I tried setting attributes both in the entrypoint
>> rule and in rules called by matched rules.
>>
>> This happens only with attributes having context. I can work around
>> the problem by using module-level attributes instead, using a Map type
>> to associate values with elements, but I'm not liking it because the
>> code becomes bloated.
>>
>> Is this a bug or am I missing something?
>> Thanks.
>>
>> --
>> Lorenzo
Previous Topic:[ATL] uml inter-model references problems
Next Topic:[ATL] problem with launcher and UML driver
Goto Forum:
  


Current Time: Sat Apr 20 14:56:00 GMT 2024

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

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

Back to the top