containsKey not found? [message #1298973] |
Wed, 16 April 2014 11:28  |
Eclipse User |
|
|
|
Hi,
I have a variable that holds an instance of a Map (created with var m =
new Map;), but when I try to invoke containsKey on my variable, I get an
error message saying "operation containsKey not found on Map". The
EpsilonBook says the operation should be available.
Do you have a suggestion where the problem might be?
Many thanks,
Steffen
|
|
|
|
Re: containsKey not found? [message #1299852 is a reply to message #1299233] |
Thu, 17 April 2014 02:43   |
Eclipse User |
|
|
|
Hi,
Interestingly, your EOL file runs through without problems on my
machine. I have gone and explored a little more and the problem may be a
little more involved than I first thought.
I attach the two files that I am actually using (I have reduced them a
little to remove stuff that doesn't seem to affect the problem). As you
can see, this is pretty much standard code-skeleton generation for Java,
nothing very fancy. I have a slightly special kind of model in that
attribute names don't need to be unique (long story), so I need to
uniquify them in the code generation. I have set up a map and use it to
get unique IDs for each attribute.
Two things were interesting when doing this:
1. The 'global' variable with the map wasn't actually visible in the
operation so I had to pass it in as a parameter. I assume this is
some scoping rule that I'm unaware of, but perhaps I'm doing
something wrong?
2. Sometimes the code seems to forget the map has a containsKey
operation. I have added some debug code and it is interesting to
observe that the call to containsKey goes through OK the first time
round for every java file being generated, but dies the second time
with something like "Method 'containsKey' not found for: Map {}1".
So the problem only seems to occur when there are more than one
attribute to generate...
I am running Epsilon from source.
Best regards,
Steffen
On 16/04/2014 21:42, Antonio Garcia-Dominguez wrote:
> Hi Steffen,
>
> That looks like a bug, but I haven't been able to reproduce it. Could you run the attached script and let us know what it prints on your machine?
>
> On mine, it prints what one would expect:
>
> m1.containsKey("foo"): true
> m1.containsKey("bar"): false
> m2.containsKey("foo"): true
> m2.containsKey("bar"): false
>
> Cheers,
> Antonio
[%
var uniqueID = new Map;
%]
public class [%=currentClass.name%] {
[%
for (prop : Model!Attribute in currentClass.attributes) {
%]
private [%=prop.type.name%] [%=prop.name + prop.getUniqueID(uniqueID)%] = [%if (prop.type.isKindOf(Model!DataType)) {%] [%=prop.value %] [%} else {%] new [%=prop.type.name%] ();[%}%]
[%
uniqueID = uniqueID + 1;
}
%]
}
[%
operation Model!Attribute getUniqueID(uniqueID) : Integer {
(''+uniqueID.containsKey(self.name)).println;
return 0;
}
%]
[%
var idx = 0;
for (cl in Model!Class.all()) {
var t := TemplateFactory.load('JavaOneClass.egl');
t.populate ('currentClass', cl);
('Starting to generate ' + cl.name + '.java').println();
t.generate ('../src/' + cl.name + idx + '.java');
idx = idx + 1;
}
%]
|
|
|
|
Powered by
FUDForum. Page generated in 0.04063 seconds