google-code-export / umple

Automatically exported from code.google.com/p/umple
1 stars 0 forks source link

association 0..1 to m multiplicity generating name conflict in set function #645

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Take the following code:

class X {}

class Y {
   0..1 y_1 -- 3X checkX
}

In the generated code, in the Y class, the set method (setCheckX(X... newCheck) 
) contains the following code:

ArrayList<X> checkNewCheckX = newArrayList<X>();
for (X newCheckX: newCheckX) {
...

This is an error!  The proper code should be:
ArrayList<X> checkNewCheckX = newArrayList<X>();
for (X newCheckX: checkNewCheckX ) {
...

With the current code there is a name conflict and the java does not compile.

This does not occur, as far as I've noticed, with any other multiplicities.  I 
discovered it while writing tests for composition - I originally thought the 
error was only for composition, but in fact it occurs for all associations.

Original issue reported on code.google.com by ellen.ar...@gmail.com on 11 Oct 2014 at 1:14

GoogleCodeExporter commented 9 years ago
Ok, so I think I figured it out!  Turns out the problem was in the 
association_SetNToOptionalOne jet file.  In this specific multiplicity 
instance, in the setMany method (taking in an array), the for loop was as 
follows:

for (<%=gen.translate("type",av)%> <%=gen.translate("associationNew",av)%> : 
<%=gen.translate("parameterMany",av)%>)

while, in other multiplicities (for example, MNToOptionalOne), the setMany 
method has the following for loop:

for (<%=gen.translate("type",av)%> <%=gen.translate("parameterOne",av)%> : 
<%=gen.translate("parameterMany",av)%>)

By changing the for loop (and all instances referring to associationNew) 
replacing associationNew with parameterOne, this solves the name conflict.  
I also had to change one of the test template files (OptionalNToOne_One.txt) to 
match the new syntax (in this template, the name error was present).

I also looked at php and ruby to see if the error was present in these 
languages, but, although the for loop naming (using associationNew) is the same 
the syntax error is not present here, due to an 's' at the end of the name of 
the incoming array (method parameter) - so, there is no name conflict.

I will commit a patch tomorrow once I have internet access on my linux 
partition!

Original comment by ellen.ar...@gmail.com on 15 Oct 2014 at 3:08

GoogleCodeExporter commented 9 years ago

Original comment by ellen.ar...@gmail.com on 16 Oct 2014 at 1:53