Bug 135527 - Javascript wrong Code Generation
Summary: Javascript wrong Code Generation
Status: RESOLVED FIXED
Alias: None
Product: umbrello
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: unspecified Linux
: NOR normal
Target Milestone: ---
Assignee: Umbrello Development Group
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-12 19:52 UTC by ediaz666@gmail.com
Modified: 2007-02-16 19:37 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description ediaz666@gmail.com 2006-10-12 19:52:55 UTC
Version:           1.5.5 (using KDE 3.5.5 "release 19.1" , openSUSE )
Compiler:          Target: x86_64-suse-linux
OS:                Linux (x86_64) release 2.6.16.13-4-default

Hi again
I generate javascript code and the result was not good: When you create a composition between class A and class B, the generator returns this:
  function A() {
    ....
    this.m_B = new B();
    ....
  }

  function B() {
    ....
    this.m_A = new A();
    ....
  }
 and it was suppose to instance only class B in class A.
 It also returns a lot of instance of class A itself:

  function A() {
   ...
   this.m_B = new B();
   this.m_B = new B();
   this.m_A = new A();
   this.m_B = new B();
   this.m_B = new B();
   this.m_A = new A();
   ...
  }
Comment 1 Antoine Dopffer 2007-02-15 22:54:26 UTC
I can't exactly reproduce this bug in version 1.5.6.
Here is what I get:
Given a class A and a class B, I draw a composition between A and B
----         ------
| A | <>-----|  B  |
-----        ------- 
The generated javascript code is
File A.js:
----------------------------------
**
  * class A
  */

A = function ()
{
  this._init ();
}


/**
 * _init sets all A attributes to their default value. Make sure to call this
 * method within your class constructor
 */
A.prototype._init = function ()
{

  /**Aggregations: */

  /**Compositions: */
  this.m_A = new A ();

}
-----------------------

File B.js:

-----------------------
**
  * class A
  */

A = function ()
{
  this._init ();
}


/**
 * _init sets all A attributes to their default value. Make sure to call this
 * method within your class constructor
 */
A.prototype._init = function ()
{

  /**Aggregations: */

  /**Compositions: */
  this.m_A = new A ();

}
--------------------------------

According to me, there are two errors:
1) There shouldn't be a composant m_A in class B but a composant m_B in class A (In this case, the C++ generated code doesn't generate any composants in any classes. The C++ generated code generates a composant m_B if only I add a attribute of class B in class A)
2) There shouldn't be a composant m_A in class A. In my example, there is only one composant m_A in class A. That's better than many  but still incorrect

PS : The generated code is identical in trunk
Comment 2 Oliver Kellogg 2007-02-16 19:37:06 UTC
SVN commit 634263 by okellogg:

writeClass (aggregations, compositions): Do not generate code when `cĀ“ is at role B.
 Generate code for the role B object.
BUG:135527


 M  +1 -0      ChangeLog  
 M  +10 -4     umbrello/codegenerators/jswriter.cpp  


--- branches/KDE/3.5/kdesdk/umbrello/ChangeLog #634262:634263
@@ -3,6 +3,7 @@
 * Bugs fixed from http://bugs.kde.org:
 * %date% and %time% not being parsed (96612)
 * Relationships for entities do not live outside of an entity relationship diagram (125146)
+* Javascript wrong Code Generation (135527)
 * Javascript Code Generation creates bad format methods (135540)
 * Crash when deleting the link between a package and a class (141602)
 * Ada95 Code Generation Errors for Aggregation (141644)
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/jswriter.cpp #634262:634263
@@ -155,8 +155,11 @@
         js << m_endl << m_indentation << "/**Aggregations: */" << m_endl;
         for (UMLAssociation* a = aggregations.first(); a; a = aggregations.next())
         {
-            QString nm(cleanName(a->getObject(Uml::A)->getName()));
-            if (a->getMulti(Uml::A).isEmpty())
+            UMLObject *b = a->getObject(Uml::B);
+            if (b == c)
+                continue;   // we need to be at the "A" side and the other guy at "B"
+            QString nm(cleanName(b->getName()));
+            if (a->getMulti(Uml::B).isEmpty())
                 js << m_indentation << "this.m_" << nm << " = new " << nm << " ();" << m_endl;
             else
                 js << m_indentation << "this.m_" << nm.lower() << " = new Array ();" << m_endl;
@@ -168,8 +171,11 @@
         js << m_endl << m_indentation << "/**Compositions: */" << m_endl;
         for (UMLAssociation *a = compositions.first(); a; a = compositions.next())
         {
-            QString nm(cleanName(a->getObject(Uml::A)->getName()));
-            if(a->getMulti(Uml::A).isEmpty())
+            UMLObject *b = a->getObject(Uml::B);
+            if (b == c)
+                continue;   // we need to be at the "A" side and the other guy at "B"
+            QString nm(cleanName(b->getName()));
+            if (a->getMulti(Uml::B).isEmpty())
                 js << m_indentation << "this.m_" << nm << " = new "<< nm << " ();" << m_endl;
             else
                 js << m_indentation << "this.m_" << nm.lower() << " = new Array ();" << m_endl;