Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [ATL] Adding entries to a Map attribute from imperative code
[ATL] Adding entries to a Map attribute from imperative code [message #645744] Mon, 20 December 2010 11:21 Go to next message
Tassilo Horn is currently offline Tassilo Horn
Messages: 93
Registered: July 2009
Member
Hi all,

in a transformation, I have a attribute helper defined in the context of
the module. The User Guide tells me, that one can use those attributes
as a kind of global variable and explains that using an integer counter.

Now I'd like to do something like that using a Map.

--8<---------------cut here---------------start------------->8---
helper def: family2AddressMap : Genealogy!Address = Map(Families!Family, Genealogy!Address);

rule getAddress(f : Families!Family) {
to
a : Genealogy!Address (
street <- f.street,
town <- f.town
)
do {
thisModule.family2AddressMap <- (f, a);
a;
}
}
--8<---------------cut here---------------end--------------->8---

The attribute definition seems to be ok, but the assignment to the map
doesn't work. There are "no viable alternative at input" errors for the
"t" starting "thisModule" as well as for "f" and "a".

So how do I add an entry to a map?

In case you can see that I'm trying to reimplement the behavior of a
unique lazu rule, you are absolutily right. This is just for
educational purposes, and of course totally flawed. ;-)

Bye,
Tassilo
--
Dipl.-Inform. Tassilo Horn | Room: B015
University of Koblenz-Landau, Campus Koblenz | Phone: +49 (261) 287-2745
Institute for Software Technology | Mail: horn@uni-koblenz.de
Universitätsstr. 1, 56070 Koblenz, Germany |
Re: [ATL] Adding entries to a Map attribute from imperative code [message #645927 is a reply to message #645744] Tue, 21 December 2010 08:42 Go to previous messageGo to next message
Vincent MAHE is currently offline Vincent MAHE
Messages: 129
Registered: July 2009
Senior Member
Le 20/12/2010 12:21, Tassilo Horn a écrit :
> Hi all,
>
> in a transformation, I have a attribute helper defined in the context of
> the module. The User Guide tells me, that one can use those attributes
> as a kind of global variable and explains that using an integer counter.
>
> Now I'd like to do something like that using a Map.
>
> --8<---------------cut here---------------start------------->8---
> helper def: family2AddressMap : Genealogy!Address = Map(Families!Family, Genealogy!Address);

May I suggest 'addressMap' as a name for the Map?

>
> rule getAddress(f : Families!Family) {
> to
> a : Genealogy!Address (
> street<- f.street,
> town<- f.town
> )
> do {
> thisModule.family2AddressMap<- (f, a);

thisModule.addressMap->put(f, a)

> a;
> }
> }
> --8<---------------cut here---------------end--------------->8---
>
> The attribute definition seems to be ok, but the assignment to the map
> doesn't work. There are "no viable alternative at input" errors for the
> "t" starting "thisModule" as well as for "f" and "a".
>
> So how do I add an entry to a map?
>
> In case you can see that I'm trying to reimplement the behavior of a
> unique lazu rule, you are absolutily right. This is just for
> educational purposes, and of course totally flawed. ;-)
>
> Bye,
> Tassilo


--
Cordialement

Vincent MAHÉ

Ingénieur Expert - Projet IDM++ - Équipe AtlanMod
École des Mines de Nantes
La Chantrerie - 4, rue Alfred Kastler
B.P. 20722 - F-44307 NANTES Cedex 3
Tel: (33)2 51 85 81 00
Re: [ATL] Adding entries to a Map attribute from imperative code [message #645936 is a reply to message #645927] Tue, 21 December 2010 09:23 Go to previous messageGo to next message
Tassilo Horn is currently offline Tassilo Horn
Messages: 93
Registered: July 2009
Member
Vincent MAHE <vmahe@irisa.fr> writes:

Hi Vincent,

>> --8<---------------cut here---------------start------------->8---
>> helper def: family2AddressMap : Genealogy!Address = Map(Families!Family, Genealogy!Address);
>
> May I suggest 'addressMap' as a name for the Map?

Of course you may.

>> rule getAddress(f : Families!Family) {
>> to
>> a : Genealogy!Address (
>> street<- f.street,
>> town<- f.town
>> )
>> do {
>> thisModule.family2AddressMap<- (f, a);
>
> thisModule.addressMap->put(f, a)

Oh, that was clearly to obvious to me yesterday afternoon! ;-)

The ATL User Guide states that there are some further operations get(),
including(), union(), getKeys(), getValues() beside the "common
operations". What's "common" here?

Thanks,
Tassilo
--
Dipl.-Inform. Tassilo Horn | Room: B015
University of Koblenz-Landau, Campus Koblenz | Phone: +49 (261) 287-2745
Institute for Software Technology | Mail: horn@uni-koblenz.de
Universitätsstr. 1, 56070 Koblenz, Germany |
Re: [ATL] Adding entries to a Map attribute from imperative code [message #645952 is a reply to message #645936] Tue, 21 December 2010 10:19 Go to previous messageGo to next message
Vincent MAHE is currently offline Vincent MAHE
Messages: 129
Registered: July 2009
Senior Member
Le 21/12/2010 10:23, Tassilo Horn a écrit :
> The ATL User Guide states that there are some further operations get(),
> including(), union(), getKeys(), getValues() beside the "common
> operations". What's "common" here?
>
The operations inherited from OclAny upperclass (oclXxx and refXxx
methods, debug(), toString())
--
Cordialement

Vincent MAHÉ

Ingénieur Expert - Projet IDM++ - Équipe AtlanMod
École des Mines de Nantes
La Chantrerie - 4, rue Alfred Kastler
B.P. 20722 - F-44307 NANTES Cedex 3
Tel: (33)2 51 85 81 00
Re: [ATL] Adding entries to a Map attribute from imperative code [message #645965 is a reply to message #645952] Tue, 21 December 2010 10:58 Go to previous message
Tassilo Horn is currently offline Tassilo Horn
Messages: 93
Registered: July 2009
Member
Vincent MAHE <vmahe@irisa.fr> writes:

Hi Vincent,

>> The ATL User Guide states that there are some further operations
>> get(), including(), union(), getKeys(), getValues() beside the
>> "common operations". What's "common" here?
>>
> The operations inherited from OclAny upperclass (oclXxx and refXxx methods,
> debug(), toString())

Ah, I see. I had the impression that "common" refers to the Java Map
interface linked shortly above that sentence, and so I wondered why
there are getKeys() and getValues() where Map already declares keySet()
and values().

But then, put() should be listed in the user guide.

Bye,
Tassilo
--
Dipl.-Inform. Tassilo Horn | Room: B015
University of Koblenz-Landau, Campus Koblenz | Phone: +49 (261) 287-2745
Institute for Software Technology | Mail: horn@uni-koblenz.de
Universitätsstr. 1, 56070 Koblenz, Germany |
Previous Topic:[QVTo] Failed to resolve metamodel - in running Java application
Next Topic:MOF to EMF using ATL
Goto Forum:
  


Current Time: Wed Oct 22 23:58:58 GMT 2014

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

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