|
Re: containsKey not found? [message #1299233 is a reply to message #1298973] |
Wed, 16 April 2014 20:42 |
|
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
-
Attachment: example.eol
(Size: 0.31KB, Downloaded 131 times)
|
|
|
Re: containsKey not found? [message #1299852 is a reply to message #1299233] |
Thu, 17 April 2014 06:43 |
Steffen Zschaler Messages: 266 Registered: July 2009 |
Senior Member |
|
|
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;
}
%]
|
|
|
Re: containsKey not found? [message #1301841 is a reply to message #1299852] |
Fri, 18 April 2014 10:42 |
|
Steffen Zschaler wrote on Thu, 17 April 2014 02:43Hi,
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.
It's rather simpler than that . See below.
[%
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;
}
%]
}
See this line:
You seem to be reassigning uniqueID to itself, by adding 1 to it. EOL is being awfully helpful by converting both operands to a String and then assigning the result to uniqueID . Remember that EOL is a dynamically-typed language, so it can't know if this is what you really want to do or not.
As for the scoping, you're right: global variables are usually not visible from functions. I recall having some discussions in the forum previously about this, and IIRC, we reached the conclusion that this was for the best.
|
|
|
Powered by
FUDForum. Page generated in 0.02913 seconds