[Uml-devel] [Bug 72042] code generation ignores unidirectional association

Oliver Kellogg okellogg at users.sourceforge.net
Sat Feb 24 07:22:13 UTC 2007


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
         
http://bugs.kde.org/show_bug.cgi?id=72042         
okellogg users sourceforge net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED



------- Additional Comments From okellogg users sourceforge net  2007-02-24 08:22 -------
SVN commit 636790 by okellogg:

Attachment 19796 from Antoine Dopffer adds code generation for UniAssociation
 in C++and Java.  I modified the patch for role B as described in comment #8.
Many thanks Antoine for your work.
BUG:72042


 M  +1 -0      ChangeLog  
 M  +29 -0     umbrello/classifier.cpp  
 M  +5 -0      umbrello/classifier.h  
 M  +4 -1      umbrello/codegenerators/classifierinfo.cpp  
 M  +1 -0      umbrello/codegenerators/classifierinfo.h  
 M  +10 -0     umbrello/codegenerators/cppwriter.cpp  
 M  +7 -3      umbrello/codegenerators/javawriter.cpp  


--- branches/KDE/3.5/kdesdk/umbrello/ChangeLog #636789:636790
 @ -4,6 +4,7  @
 * C# Code Generation and export (53368)
 * Java interface inheritance, abstract classes and generics in code generation
   (53376)
+* Code generation ignores unidirectional association (72042)
 * %date% and %time% not being parsed (96612)
 * Operations of the Interface are not implemented in the class automatically
   (111593)
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/classifier.cpp #636789:636790
 @ -833,6 +833,33  @
     return m_isRef;
 }
 
+UMLAssociationList  UMLClassifier::getUniAssociationToBeImplemented() {
+    UMLAssociationList associations = getSpecificAssocs(Uml::at_UniAssociation);
+    UMLAssociationList uniAssocListToBeImplemented;
+
+    for(UMLAssociation *a = associations.first(); a; a = associations.next()) {
+        if (a->getObjectId(Uml::B) == getID())
+            continue;  // we need to be at the A side
+
+        QString roleNameB = a->getRoleName(Uml::B);
+        if (!roleNameB.isEmpty()) {
+            UMLAttributeList atl = getAttributeList();
+            bool found = false;
+            //make sure that an attribute with the same name doesn't already exist 
+            for (UMLAttribute *at = atl.first(); at ; at = atl.next()) {
+                if (at->getName() == roleNameB) {
+                    found = true;
+                    break;
+                }
+            }
+            if (!found) {
+                uniAssocListToBeImplemented.append(a);
+            }
+        }
+    }
+    return uniAssocListToBeImplemented;
+}
+
 void UMLClassifier::saveToXMI(QDomDocument & qDoc, QDomElement & qElement) {
     QString tag;
     switch (m_BaseType) {
 @ -986,4 +1013,6  @
     return totalSuccess;
 }
 
+
+
 #include "classifier.moc"
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/classifier.h #636789:636790
 @ -436,6 +436,11  @
      */
     UMLClassifierListItem* makeChildObject(const QString& xmiTag);
 
+    /**
+     * Return the list of unidirectional association that should show up in the code
+     */
+    virtual UMLAssociationList  getUniAssociationToBeImplemented();
+
 signals:
     /** Signals that a new UMLOperation has been added to the classifer.
      */
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/classifierinfo.cpp #636789:636790
 @ -85,6 +85,9  @
     plainAssociations = c->getSpecificAssocs(Uml::at_Association); // BAD! only way to get "general" associations.
     plainAssociations.setAutoDelete(false);
 
+    uniAssociations = c->getUniAssociationToBeImplemented();
+    uniAssociations.setAutoDelete(false);
+
     aggregations = c->getAggregations();
     aggregations.setAutoDelete(false);
 
 @ -92,7 +95,7  @
     compositions.setAutoDelete(false);
 
     // set some summary information about the classifier now
-    hasAssociations = plainAssociations.count() > 0 || aggregations.count() > 0 || compositions.count() > 0;
+    hasAssociations = plainAssociations.count() > 0 || aggregations.count() > 0 || compositions.count() > 0 || uniAssociations.count() > 0;
     hasAttributes = atpub.count() > 0 || atprot.count() > 0 || atpriv.count() > 0
                     || static_atpub.count() > 0
                     || static_atprot.count() > 0
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/classifierinfo.h #636789:636790
 @ -65,6 +65,7  @
      * Lists of types of associations this classifier has
      */
     UMLAssociationList plainAssociations;
+    UMLAssociationList uniAssociations;
     UMLAssociationList aggregations;
     UMLAssociationList compositions;
 
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/cppwriter.cpp #636789:636790
 @ -183,6 +183,8  @
     // associations
     writeAssociationMethods(m_classifierInfo->plainAssociations, permitScope,
                             true, INLINE_ASSOCIATION_METHODS, true, c->getID(), stream);
+    writeAssociationMethods(m_classifierInfo->uniAssociations, permitScope,
+                            true, INLINE_ASSOCIATION_METHODS, true, c->getID(), stream);
     writeAssociationMethods(m_classifierInfo->aggregations, permitScope,
                             true,  INLINE_ASSOCIATION_METHODS, true, c->getID(), stream);
     writeAssociationMethods(m_classifierInfo->compositions, permitScope,
 @ -200,6 +202,7  @
 
     // associations
     writeAssociationDecls(m_classifierInfo->plainAssociations, permitScope, c->getID(), stream);
+    writeAssociationDecls(m_classifierInfo->uniAssociations, permitScope, c->getID(), stream);
     writeAssociationDecls(m_classifierInfo->aggregations, permitScope, c->getID(), stream);
     writeAssociationDecls(m_classifierInfo->compositions, permitScope, c->getID(), stream);
 
 @ -279,6 +282,8  @
     // public
     writeAssociationMethods(m_classifierInfo->plainAssociations, Uml::Visibility::Public, false,
                             !INLINE_ASSOCIATION_METHODS, true, c->getID(), cpp);
+    writeAssociationMethods(m_classifierInfo->uniAssociations, Uml::Visibility::Public, false,
+                            !INLINE_ASSOCIATION_METHODS, true, c->getID(), cpp);
     writeAssociationMethods(m_classifierInfo->aggregations, Uml::Visibility::Public, false,
                             !INLINE_ASSOCIATION_METHODS, true, c->getID(), cpp);
     writeAssociationMethods(m_classifierInfo->compositions, Uml::Visibility::Public, false,
 @ -287,6 +292,8  @
     // protected
     writeAssociationMethods(m_classifierInfo->plainAssociations, Uml::Visibility::Protected, false,
                             !INLINE_ASSOCIATION_METHODS, true, c->getID(), cpp);
+    writeAssociationMethods(m_classifierInfo->uniAssociations, Uml::Visibility::Protected, false,
+                            !INLINE_ASSOCIATION_METHODS, true, c->getID(), cpp);
     writeAssociationMethods(m_classifierInfo->aggregations, Uml::Visibility::Protected, false,
                             !INLINE_ASSOCIATION_METHODS, true, c->getID(), cpp);
     writeAssociationMethods(m_classifierInfo->compositions, Uml::Visibility::Protected, false,
 @ -296,6 +303,8  @
     // private
     writeAssociationMethods(m_classifierInfo->plainAssociations, Uml::Visibility::Private, false,
                             !INLINE_ASSOCIATION_METHODS, true, c->getID(), cpp);
+    writeAssociationMethods(m_classifierInfo->uniAssociations, Uml::Visibility::Private, false,
+                            !INLINE_ASSOCIATION_METHODS, true, c->getID(), cpp);
     writeAssociationMethods(m_classifierInfo->aggregations, Uml::Visibility::Private, false,
                             !INLINE_ASSOCIATION_METHODS, true, c->getID(), cpp);
     writeAssociationMethods(m_classifierInfo->compositions, Uml::Visibility::Private, false,
 @ -349,6 +358,7  @
     {
         // write all includes we need to include other classes, that arent us.
         printAssociationIncludeDecl (m_classifierInfo->plainAssociations, c->getID(), cpp);
+        printAssociationIncludeDecl (m_classifierInfo->uniAssociations, c->getID(), cpp);
         printAssociationIncludeDecl (m_classifierInfo->aggregations, c->getID(), cpp);
         printAssociationIncludeDecl (m_classifierInfo->compositions, c->getID(), cpp);
 
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/javawriter.cpp #636789:636790
 @ -115,10 +115,12  @
 
     // another preparation, determine what we have
     UMLAssociationList associations = c->getSpecificAssocs(Uml::at_Association); // BAD! only way to get "general" associations.
+    UMLAssociationList uniAssociations = c->getUniAssociationToBeImplemented();
+    
     UMLAssociationList aggregations = c->getAggregations();
     UMLAssociationList compositions = c->getCompositions();
 
-    bool hasAssociations = aggregations.count() > 0 || associations.count() > 0 || compositions.count() > 0;
+    bool hasAssociations = aggregations.count() > 0 || associations.count() > 0 || compositions.count() > 0 || uniAssociations.count() > 0;
     bool hasAttributes = (atl.count() > 0);
     bool hasAccessorMethods = hasAttributes || hasAssociations;
     bool hasOperationMethods = (c->getOpList().count() > 0);
 @ -188,6 +190,7  @
     writeAttributeDecls(atpub, atprot, atpriv, java);
 
     writeAssociationDecls(associations, c->getID(), java);
+    writeAssociationDecls(uniAssociations, c->getID(), java);
     writeAssociationDecls(aggregations, c->getID(), java);
     writeAssociationDecls(compositions, c->getID(), java);
 
 @ -232,6 +235,7  @
 
     // first: determine the name of the other class
     writeAssociationMethods(associations, c, java);
+    writeAssociationMethods(uniAssociations, c, java);
     writeAssociationMethods(aggregations, c, java);
     writeAssociationMethods(compositions, c, java);
 
 @ -527,7 +531,7  @
     // multiplicity object that we don't have to figure out what it means via regex.
     if(multi.isEmpty() || multi.contains(QRegExp("^[01]$")))
     {
-        QString fieldVarName = roleName.replace(0, 1, roleName.left(1).lower());
+        QString fieldVarName = "m_" + roleName.replace(0, 1, roleName.left(1).lower());
         java<<startline<<scope<<" "<<fieldClassName<<" "<<fieldVarName<<";";
     }
     else
 @ -586,7 +590,7  @
 {
     if(multi.isEmpty() || multi.contains(QRegExp("^[01]$")))
     {
-        QString fieldVarName = "m_" + roleName.lower();
+        QString fieldVarName = "m_" + roleName.replace(0, 1, roleName.left(1).lower());
         writeSingleAttributeAccessorMethods(fieldClassName, fieldVarName, roleName,
                                             description, visib, change, false, java);
     }




More information about the umbrello-devel mailing list