google-code-export / umple

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

Having two sorted associations in the same class generates two sort methods, which fails to compile #362

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

// This example demonstrates sorted associations
// The main program adds items out of order
// But when they are printed the output will be sorted
//

class Academy {
  1 -- * Course sorted {code};
  1 -- * Student registrants sorted {id};
  public static void main(String [ ] args) {
    Academy ac = new Academy();
    ac.addRegistrant(12,"Jim");
    ac.addRegistrant(4,"Ali");
    ac.addRegistrant(8,"Mary");
    ac.addRegistrant(3,"Francois");
    ac.addCourse("CS191");
    ac.addCourse("SE200");
    ac.addCourse("EN100");
    System.out.println(ac);
  }
  public String toString() {
    String result="";
    for (Student s: getRegistrants()) {
      result+=s+"\n";
    }
    return result;
  }
}

class Student {
  Integer id;
  name;
  public String toString() {return("Student="+id+"["+name+"]");}
}

class Course {
  code;
  public String toString() {return("Course="+code);}
}

class Registration {
  // Derived delegated attribute used for sorting
  Integer id = {getStudent().getId()}

  // Derived delegated attribute used for sorting
  code = {getCourse().getCode()}

  * sorted {id}-- 1 Student;
  * sorted {code} -- 1 Course;
}

What is the expected output? What do you see instead?

The following error is generated when compiling the Java:
"m.ump":237: error: method sort(List,String) is already defined in class Academy
  public void sort(List toSort, final String thePriority)
              ^

It should be fairly easy to ensure that only one sort method is output per 
class, with the above as a test case. Check the same test case in PHP, Ruby etc.

Original issue reported on code.google.com by TimothyCLethbridge on 3 Jan 2013 at 3:41

GoogleCodeExporter commented 9 years ago
By the way, it should be possible to have two sorted associations in a class, 
so don't just raise an Umple error here.

Original comment by TimothyCLethbridge on 3 Jan 2013 at 3:42

GoogleCodeExporter commented 9 years ago
Assigned to Geoffrey Guest since he has started work and reports he has made 
significant progress.

Original comment by TimothyCLethbridge on 6 Jan 2013 at 1:47

GoogleCodeExporter commented 9 years ago
I have attached a zip folder with a jet file that fixes this problem. It goes 
in the UmpleToTemplate project's templates. Also included are 4 test cases I 
have tried(with varying number of associations 0 to 3).

I tried to create a patch using:
svn diff -x --ignore-eol-style > 
~/patchGUEST-362-added_boolean_to_ensure_one_sort_method.diff

hope it worked, there were no messages.

Original comment by RedEyedM...@gmail.com on 7 Jan 2013 at 2:50

Attachments:

GoogleCodeExporter commented 9 years ago
Fixed a of r2371 - patch by Geoffrey Guest (not the one in the last comment, 
but a more recent one).

Original comment by TimothyCLethbridge on 7 Jan 2013 at 7:14