Version: 1.5.7 (using KDE KDE 3.5.6) Installed from: Ubuntu Packages OS: Linux * generate correct type and field name for associations * use rolenames for field name associations * use attributes in role (AS) * insert docs
Created attachment 20435 [details] js/as code generation patch
SVN commit 658784 by okellogg: Apply attachment 20435 [details] by Jose Gutierrez: > * generate correct type and field name for associations > * use rolenames for field name associations > * use attributes in role (AS) > * insert docs Thanks Jose for contributing. BUG:144788 M +1 -0 ChangeLog M +56 -17 umbrello/codegenerators/aswriter.cpp M +12 -2 umbrello/codegenerators/aswriter.h M +46 -22 umbrello/codegenerators/jswriter.cpp M +11 -2 umbrello/codegenerators/jswriter.h --- branches/KDE/3.5/kdesdk/umbrello/ChangeLog #658783:658784 @@ -34,6 +34,7 @@ * Sequence diagram crashes during message inserting (144293) * No synchronisation of comments when round-tripping (144346) * Crash when loading xmi with actor as object of sequence diagram (144442) +* ActionScript/JavaScript association code generation error (144788) Version 1.5.61 --- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/aswriter.cpp #658783:658784 @@ -156,30 +156,19 @@ if (forceSections() || !aggregations.isEmpty ()) { as << 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()) - as << m_indentation << "this.m_" << nm << " = new " << nm << " ();" << m_endl; - else - as << m_indentation << "this.m_" << nm.lower() << " = new Array ();" << m_endl; - } + writeAssociation(classname, aggregations , as ); + } + if( forceSections() || !compositions.isEmpty()) { as << 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()) - as << m_indentation << "this.m_" << nm << " = new " << nm << " ();" << m_endl; - else - as << m_indentation << "this.m_" << nm.lower() << " = new Array ();" << m_endl; - } + writeAssociation(classname, compositions , as ); } + as << m_endl; + as << m_indentation << "/**Protected: */" << m_endl; - as << m_indentation << "/**Protected: */" << m_endl; if (isClass) { UMLAttributeList atl = c->getAttributeList(); for (UMLAttribute *at = atl.first(); at ; at = atl.next()) @@ -239,6 +228,56 @@ //////////////////////////////////////////////////////////////////////////////////// // Helper Methods + +void ASWriter::writeAssociation(QString& classname, UMLAssociationList& assocList , QTextStream &as ) +{ + for(UMLAssociation *a = assocList.first(); a; a = assocList.next()) + { + // association side + Uml::Role_Type role = a->getObject(Uml::A)->getName() == classname ? Uml::B:Uml::A; + + QString roleName(cleanName(a->getRoleName(role))); + + if (!roleName.isEmpty()) { + + // association doc + if (forceDoc() || !a->getDoc().isEmpty()) { + as << m_indentation << "/**" << m_endl + << formatDoc(a->getDoc(), m_indentation + " * ") + << m_indentation << " */" << m_endl; + } + + // role doc + if (forceDoc() || !a->getRoleDoc(role).isEmpty()) { + as << m_indentation << "/**" << m_endl + << formatDoc(a->getRoleDoc(role), m_indentation + " * ") + << m_indentation << " */" << m_endl; + } + + bool okCvt; + int nMulti = a->getMulti(role).toInt(&okCvt,10); + bool isNotMulti = a->getMulti(role).isEmpty() || (okCvt && nMulti == 1); + + QString typeName(cleanName(a->getObject(role)->getName())); + + if (isNotMulti) + as << m_indentation << "this.m_" << roleName << " = new " << typeName << "();" << m_endl; + else + as << m_indentation << "this.m_" << roleName << " = new Array();" << m_endl; + + // role visibility + if (a->getVisibility(role) == Uml::Visibility::Private) + { + as << m_indentation << "ASSetPropFlags (this, \"m_" << roleName << "\", 7);" << m_endl; + } + else if (a->getVisibility(role)== Uml::Visibility::Protected) + { + as << m_indentation << "ASSetPropFlags (this, \"m_" << roleName << "\", 1);" << m_endl; + } + } + } +} + void ASWriter::writeOperations(QString classname, UMLOperationList *opList, QTextStream &as) { UMLOperation *op; --- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/aswriter.h #658783:658784 @@ -20,6 +20,7 @@ #include "simplecodegenerator.h" #include "../umloperationlist.h" +#include "../umlassociationlist.h" /** * class ASWriter is a ActionScript code generator for UMLClassifier objects @@ -63,8 +64,17 @@ * @param opList the list of operations * @param as output stream for the AS file */ - void writeOperations(QString classname, UMLOperationList *opList, - QTextStream &as); + void writeOperations(QString classname, UMLOperationList *opList, QTextStream &as); + + /** + * write a list of associations + * + * @param classname the name of the class + * @param assocList the list of associations + * @param as output stream for the AS file + */ + void writeAssociation(QString& classname, UMLAssociationList& assoclist , QTextStream &as); + }; #endif //ASWRITER --- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/jswriter.cpp #658783:658784 @@ -153,33 +153,15 @@ if (forceSections() || !aggregations.isEmpty ()) { js << m_endl << m_indentation << "/**Aggregations: */" << m_endl; - for (UMLAssociation* a = aggregations.first(); a; a = aggregations.next()) - { - 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; - } + writeAssociation(classname, aggregations , js ); + } UMLAssociationList compositions = c->getCompositions(); if( forceSections() || !compositions.isEmpty()) { js << m_endl << m_indentation << "/**Compositions: */" << m_endl; - for (UMLAssociation *a = compositions.first(); a; a = compositions.next()) - { - 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; - } + writeAssociation(classname, compositions , js ); + } js << m_endl; js << "}" << m_endl; @@ -201,6 +183,48 @@ //////////////////////////////////////////////////////////////////////////////////// // Helper Methods +void JSWriter::writeAssociation(QString& classname, UMLAssociationList& assocList , QTextStream &js) +{ + for (UMLAssociation *a = assocList.first(); a; a = assocList.next()) { + // association side + Uml::Role_Type role = (a->getObject(Uml::A)->getName() == classname ? Uml::B : Uml::A); + + QString roleName(cleanName(a->getRoleName(role))); + + if (!roleName.isEmpty()) { + + // association doc + if (forceDoc() || !a->getDoc().isEmpty()) + { + js << m_indentation << "/**" << m_endl + << formatDoc(a->getDoc(), m_indentation + " * ") + << m_indentation << " */" << m_endl; + } + + // role doc + if (forceDoc() || !a->getRoleDoc(role).isEmpty()) + { + js << m_indentation << "/**" << m_endl + << formatDoc(a->getRoleDoc(role), m_indentation + " * ") + << m_indentation << " */" << m_endl; + } + + bool okCvt; + int nMulti = a->getMulti(role).toInt(&okCvt,10); + bool isNotMulti = a->getMulti(role).isEmpty() || (okCvt && nMulti == 1); + + QString typeName(cleanName(a->getObject(role)->getName())); + + if (isNotMulti) + js << m_indentation << "this.m_" << roleName << " = new " << typeName << "();" << m_endl; + else + js << m_indentation << "this.m_" << roleName << " = new Array();" << m_endl; + + // role visibility + } + } +} + void JSWriter::writeOperations(QString classname, UMLOperationList *opList, QTextStream &js) { UMLOperation *op; --- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/jswriter.h #658783:658784 @@ -20,6 +20,7 @@ #include "simplecodegenerator.h" #include "../umloperationlist.h" +#include "../umlassociationlist.h" /** * class JSWriter is a JavaScript code generator for UMLClassifier objects @@ -62,8 +63,16 @@ * @param opList the list of operations * @param js output stream for the JS file */ - void writeOperations(QString classname, UMLOperationList *opList, - QTextStream &js); + void writeOperations(QString classname, UMLOperationList *opList, QTextStream &js); + + /** + * write a list of associations + * + * @param classname the name of the class + * @param assocList the list of associations + * @param as output stream for the AS file + */ + void writeAssociation(QString& classname, UMLAssociationList& assoclist , QTextStream &js); }; #endif //JSWRITER