Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Epsilon » containsKey not found?
containsKey not found? [message #1298973] Wed, 16 April 2014 15:28 Go to next message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 228
Registered: July 2009
Senior Member
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 #1299233 is a reply to message #1298973] Wed, 16 April 2014 20:42 Go to previous messageGo to next message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 310
Registered: January 2010
Senior Member
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 17 times)
Re: containsKey not found? [message #1299852 is a reply to message #1299233] Thu, 17 April 2014 06:43 Go to previous messageGo to next message
Steffen Zschaler is currently offline Steffen ZschalerFriend
Messages: 228
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 Go to previous message
Antonio Garcia-Dominguez is currently offline Antonio Garcia-DominguezFriend
Messages: 310
Registered: January 2010
Senior Member
Steffen Zschaler wrote on Thu, 17 April 2014 02:43
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.


It's rather simpler than that Wink. 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:
    uniqueID = uniqueID + 1;


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 Wink. 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.
Previous Topic:[Eugenia-newbie]: Compile errors in generated code?
Next Topic:[ECL module] Cannot determine stereotype property
Goto Forum:
  


Current Time: Sun Dec 21 10:42:18 GMT 2014

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

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