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 06:21  |
Eclipse User |
|
|
|
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 03:42   |
Eclipse User |
|
|
|
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 04:23   |
Eclipse User |
|
|
|
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 #645965 is a reply to message #645952] |
Tue, 21 December 2010 05:58  |
Eclipse User |
|
|
|
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 |
|
|
|
Goto Forum:
Current Time: Tue Jul 01 09:59:07 EDT 2025
Powered by FUDForum. Page generated in 0.49535 seconds
|