/** * Call this method to generate C++ code for a UMLClassifier. * @param c the class you want to generate code for */ void PythonWriter::writeClass(UMLClassifier *c) { if (!c) { uDebug() << "Cannot write class of NULL concept!"; return; } QString classname = cleanName(c->name()); UMLClassifierList superclasses = c->getSuperClasses(); UMLAssociationList aggregations = c->getAggregations(); UMLAssociationList compositions = c->getCompositions(); m_bNeedPass = true; //find an appropriate name for our file QString fileName = findFileName(c, QLatin1String(".py")); if (fileName.isEmpty()) { emit codeGenerated(c, false); return; } QFile fileh; if (!openFile(fileh, fileName)) { emit codeGenerated(c, false); return; } QTextStream h(&fileh); ////////////////////////////// //Start generating the code!! ///////////////////////////// //try to find a heading file (license, coments, etc) QString str; str = getHeadingFile(QLatin1String(".py")); if (!str.isEmpty()) { str.replace(QRegExp(QLatin1String("%filename%")), fileName); str.replace(QRegExp(QLatin1String("%filepath%")), fileh.fileName()); h<<str<<m_endl; } h << "# coding=" << h.codec()->name() << m_endl; // generate import statement for superclasses and take packages into account str = cleanName(c->name()); QString pkg = cleanName(c->package()); if (!pkg.isEmpty()) str.prepend(pkg + QLatin1Char('.')); QStringList includesList = QStringList(str); //save imported classes int i = superclasses.count(); foreach (UMLClassifier *classifier, superclasses) { str = cleanName(classifier->name()); pkg = cleanName(classifier->package()); if (!pkg.isEmpty()) str.prepend(pkg + QLatin1Char('.')); includesList.append(str); h << "from " << str << " import *" << m_endl; i--; }
/** * Call this method to generate sql code for a UMLClassifier. * @param c the class to generate code for */ void SQLWriter::writeClass(UMLClassifier *c) { UMLEntity* e = c->asUMLEntity(); if (!e) { uError() << "Invalid cast from" << c->baseTypeStr() << "'" << c->name() << "' to UMLEntity*"; return; } m_pEntity = e; QString entityname = cleanName(m_pEntity->name()); //find an appropriate name for our file QString fileName = findFileName(m_pEntity, QLatin1String(".sql")); if (fileName.isEmpty()) { emit codeGenerated(m_pEntity, false); return; } QFile file; if (!openFile(file, fileName)) { emit codeGenerated(m_pEntity, false); return; } //Start generating the code!! QTextStream sql(&file); //try to find a heading file (license, coments, etc) QString str; str = getHeadingFile(QLatin1String(".sql")); if (!str.isEmpty()) { str.replace(QRegExp(QLatin1String("%filename%")), fileName); str.replace(QRegExp(QLatin1String("%filepath%")), file.fileName()); sql << str << m_endl; } //Write class Documentation if there is somthing or if force option if (forceDoc() || !m_pEntity->doc().isEmpty()) { sql << m_endl << "--" << m_endl; sql << "-- TABLE: " << entityname << m_endl; sql << formatDoc(m_pEntity->doc(),QLatin1String("-- ")); sql << "-- " << m_endl << m_endl; } // write all entity attributes UMLEntityAttributeList entAttList = m_pEntity->getEntityAttributes(); sql << "CREATE TABLE " << entityname << " ("; printEntityAttributes(sql, entAttList); sql << m_endl << ");" << m_endl; // auto increments UMLEntityAttributeList autoIncrementList; foreach(UMLEntityAttribute* entAtt, entAttList) { autoIncrementList.append(entAtt); }
/** * Write the header file for this classifier. */ void CppWriter::writeHeaderFile (UMLClassifier *c, QFile &file) { // open stream for writing QTextStream h (&file); // up the indent level to one m_indentLevel = 1; // write header blurb QString str = getHeadingFile(".h"); if (!str.isEmpty()) { str.replace(QRegExp("%filename%"), fileName_ + ".h"); str.replace(QRegExp("%filepath%"), file.fileName()); h << str<< m_endl; } // Write the hash define stuff to prevent multiple parsing/inclusion of header QString hashDefine = className_.toUpper().simplified().replace(QRegExp(" "), "_"); writeBlankLine(h); h << "#ifndef "<< hashDefine + "_H" << m_endl; h << "#define "<< hashDefine + "_H" << m_endl; writeClassDecl(c, h); // last thing..close our hashdefine h << m_endl << "#endif // " << hashDefine + "_H" << m_endl; }
void TclWriter::writeHeaderFile(UMLClassifier * c, QFile & fileh) { // open stream for writing QTextStream stream(&fileh); mStream = &stream; // reset the indent level m_indentLevel = 0; // write header blurb QString str = getHeadingFile(".tcl"); if (!str.isEmpty()) { str.replace(QRegExp("%filename%"), fileName_); str.replace(QRegExp("%filepath%"), fileh.fileName()); writeCode(str); } // set current namespace writeCode("namespace eval " + mNamespace + " {"); m_indentLevel++; // check on already existing writeComm("Do not load twice"); writeCode("if {[namespace exist " + className_ + "]} return"); // source used superclass files UMLClassifierList superclasses = c->getSuperClasses(); if (superclasses.count() > 0) { writeComm ("Source found and used class files and import class command if necessary"); foreach (UMLClassifier * classifier , superclasses ) { writeUse(classifier); }
/** * Call this method to generate Pascal code for a UMLClassifier. * @param c the class to generate code for */ void PascalWriter::writeClass(UMLClassifier *c) { if (!c) { uDebug() << "Cannot write class of NULL concept!"; return; } const bool isClass = !c->isInterface(); QString classname = cleanName(c->name()); QString fileName = qualifiedName(c).toLower(); fileName.replace(QLatin1Char('.'), QLatin1Char('-')); //find an appropriate name for our file fileName = overwritableName(c, fileName, QLatin1String(".pas")); if (fileName.isEmpty()) { emit codeGenerated(c, false); return; } QFile file; if (!openFile(file, fileName)) { emit codeGenerated(c, false); return; } // Start generating the code. QTextStream pas(&file); //try to find a heading file(license, comments, etc) QString str; str = getHeadingFile(QLatin1String(".pas")); if (!str.isEmpty()) { str.replace(QRegExp(QLatin1String("%filename%")), fileName); str.replace(QRegExp(QLatin1String("%filepath%")), file.fileName()); pas << str << endl; } QString unit = qualifiedName(c); pas << "unit " << unit << ";" << m_endl << m_endl; pas << "INTERFACE" << m_endl << m_endl; // Use referenced classes. UMLPackageList imports; findObjectsRelated(c, imports); if (imports.count()) { pas << "uses" << m_endl; bool first = true; foreach (UMLPackage* con, imports) { if (con->baseType() != UMLObject::ot_Datatype) { if (first) first = false; else pas << "," << m_endl; pas << " " << qualifiedName(con); } } pas << ";" << m_endl << m_endl; }
/** * Call this method to generate Actionscript code for a UMLClassifier. * @param c the class you want to generate code for */ void ASWriter::writeClass(UMLClassifier *c) { if (!c) { uDebug()<<"Cannot write class of NULL concept!"; return; } QString classname = cleanName(c->name()); QString fileName = c->name().toLower(); //find an appropriate name for our file fileName = findFileName(c, QLatin1String(".as")); if (fileName.isEmpty()) { emit codeGenerated(c, false); return; } QFile fileas; if (!openFile(fileas, fileName)) { emit codeGenerated(c, false); return; } QTextStream as(&fileas); ////////////////////////////// //Start generating the code!! ///////////////////////////// //try to find a heading file (license, coments, etc) QString str; str = getHeadingFile(QLatin1String(".as")); if (!str.isEmpty()) { str.replace(QRegExp(QLatin1String("%filename%")), fileName + QLatin1String(".as")); str.replace(QRegExp(QLatin1String("%filepath%")), fileas.fileName()); as << str << m_endl; } //write includes UMLPackageList includes; findObjectsRelated(c, includes); foreach (UMLPackage* conc, includes) { QString headerName = findFileName(conc, QLatin1String(".as")); if (!headerName.isEmpty()) { as << "#include \"" << findFileName(conc, QLatin1String(".as")) << "\"" << m_endl; } }
/** * Call this method to generate d code for a UMLClassifier. * @param c the class to generate code for */ void DWriter::writeClass(UMLClassifier *c) { if (!c) { uDebug() << "Cannot write class of NULL concept!"; return; } isInterface = c->isInterface(); QString fileName = cleanName(c->name().toLower()); //find an appropriate name for our file fileName = findFileName(c, QLatin1String(".d")); if (fileName.isEmpty()) { emit codeGenerated(c, false); return; } // check that we may open that file for writing QFile file; if (!openFile(file, fileName)) { emit codeGenerated(c, false); return; } // open text stream to file QTextStream d(&file); //try to find a heading file (license, coments, etc) QString str; str = getHeadingFile(QLatin1String(".d")); if (!str.isEmpty()) { str.replace(QRegExp(QLatin1String("%filename%")), fileName); str.replace(QRegExp(QLatin1String("%filepath%")), file.fileName()); d<<str<<m_endl; } // source file begins with the module declaration writeModuleDecl(c, d); // imports writeModuleImports(c, d); // write the opening declaration for the class incl any documentation, // interfaces and/or inheritence issues we have writeClassDecl(c, d); // start body of class d << " {" << m_endl; // Preparations // // sort attributes by Scope UMLAttributeList atl; UMLAttributeList atpub, atprot, atpriv, atpkg, atexport; UMLAttributeList final_atpub, final_atprot, final_atpriv, final_atpkg, final_atexport; if (!isInterface) { UMLAttributeList atl = c->getAttributeList(); foreach (UMLAttribute* at, atl) { switch(at->visibility()) { case Uml::Visibility::Public: if (at->isStatic()) final_atpub.append(at); else atpub.append(at); break; case Uml::Visibility::Protected: if (at->isStatic()) final_atprot.append(at); else atprot.append(at); break; case Uml::Visibility::Private: if (at->isStatic()) final_atpriv.append(at); else atpriv.append(at); break;/* TODO: requires support from the gui & other structures case Uml::Visibility::Package: if (at->getStatic()) final_atpkg.append(at); else atpkg.append(at); break; case Uml::Visibility::Export: if (at->getStatic()) final_atexport.append(at); else atexport.append(at); break;*/ default: break; } } }
void CSharpWriter::writeClass(UMLClassifier *c) { if (!c) { kDebug()<<"Cannot write class of NULL concept!" << endl; return; } QString classname = cleanName(c->getName()); //find an appropriate name for our file QString fileName = findFileName(c, ".cs"); if (fileName.isEmpty()) { emit codeGenerated(c, false); return; } QFile filecs; if (!openFile(filecs, fileName)) { emit codeGenerated(c, false); return; } QTextStream cs(&filecs); ////////////////////////////// //Start generating the code!! ///////////////////////////// //try to find a heading file (license, coments, etc) QString str; str = getHeadingFile(".cs"); if (!str.isEmpty()) { str.replace(QRegExp("%filename%"),fileName); str.replace(QRegExp("%filepath%"),filecs.name()); cs<<str<<m_endl; } UMLDoc *umldoc = UMLApp::app()->getDocument(); UMLFolder *logicalView = umldoc->getRootFolder(Uml::mt_Logical); // write generic includes cs << "using System;" << m_endl; cs << "using System.Text;" << m_endl; cs << "using System.Collections;" << m_endl; cs << "using System.Collections.Generic;" << m_endl << m_endl; //write includes and namespace UMLPackage *container = c->getUMLPackage(); if (container == logicalView) container = NULL; UMLPackageList includes; findObjectsRelated(c, includes); m_seenIncludes.clear(); //m_seenIncludes.append(logicalView); if (includes.count()) { UMLPackage *p; for (UMLPackageListIt it(includes); (p = it.current()) != NULL; ++it) { UMLClassifier *cl = dynamic_cast<UMLClassifier*>(p); if (cl) p = cl->getUMLPackage(); if (p != logicalView && m_seenIncludes.findRef(p) == -1 && p != container) { cs << "using " << p->getFullyQualifiedName(".") << ";" << m_endl; m_seenIncludes.append(p); } } cs << m_endl; } m_container_indent = ""; if (container) { cs << "namespace " << container->getFullyQualifiedName(".") << m_endl; cs << "{" << m_endl << m_endl; m_container_indent = m_indentation; m_seenIncludes.append(container); } //Write class Documentation if there is somthing or if force option if (forceDoc() || !c->getDoc().isEmpty()) { cs << m_container_indent << "/// <summary>" << m_endl; cs << formatDoc(c->getDoc(), m_container_indent + "/// " ); cs << m_container_indent << "/// </summary>" << m_endl ; } UMLClassifierList superclasses = c->getSuperClasses(); UMLAssociationList aggregations = c->getAggregations(); UMLAssociationList compositions = c->getCompositions(); UMLAssociationList realizations = c->getRealizations(); bool isInterface = c->isInterface(); m_unnamedRoles = 1; cs << m_container_indent << "public "; //check if it is an interface or regular class if (isInterface) { cs << "interface " << classname; } else { //check if class is abstract and / or has abstract methods if (c->getAbstract() || c->hasAbstractOps()) cs << "abstract "; cs << "class " << classname << (superclasses.count() > 0 ? " : ":""); // write baseclass, ignore interfaces, write error on multiple inheritance if (superclasses.count() > 0) { UMLClassifier *obj; int supers = 0; for (obj = superclasses.first(); obj; obj = superclasses.next()) { if (!obj->isInterface()) { if (supers > 0) { cs << " // AND "; } cs << cleanName(obj->getName()); supers++; } } if (supers > 1) { cs << m_endl << "//WARNING: C# does not support multiple inheritance but there is more than 1 superclass defined in your UML model!" << m_endl; } } //check for realizations UMLAssociationList realizations = c->getRealizations(); UMLAssociation *a; if (!realizations.isEmpty()) { for (a = realizations.first(); a; a = realizations.next()) { UMLClassifier *real = (UMLClassifier*)a->getObject(Uml::B); if(real != c) { // write list of realizations cs << ", " << real->getName(); } } } } cs << m_endl << m_container_indent << '{' << m_endl; //associations if (forceSections() || !aggregations.isEmpty()) { cs << m_endl << m_container_indent << m_indentation << "#region Aggregations" << m_endl << m_endl; writeAssociatedAttributes(aggregations, c, cs); cs << m_endl << m_container_indent << m_indentation << "#endregion" << m_endl; } //compositions if (forceSections() || !compositions.isEmpty()) { cs << m_endl << m_container_indent << m_indentation << "#region Compositions" << m_endl << m_endl; writeAssociatedAttributes(compositions, c, cs); cs << m_endl << m_container_indent << m_indentation << "#endregion" << m_endl; } //attributes // FIXME: C# allows Properties in interface! if (!isInterface) writeAttributes(c, cs); //operations writeOperations(c, cs); //finish file cs << m_endl << m_container_indent << "}" << m_endl << m_endl; // close class if (container) { cs << "} // end of namespace " << container->getFullyQualifiedName(".") << m_endl << m_endl; } //close files and notfiy we are done filecs.close(); emit codeGenerated(c, true); }
void JSWriter::writeClass(UMLClassifier *c) { if(!c) { kDebug()<<"Cannot write class of NULL concept!" << endl; return; } QString classname = cleanName(c->getName()); QString fileName = c->getName().lower(); //find an appropriate name for our file fileName = findFileName(c,".js"); if (fileName.isEmpty()) { emit codeGenerated(c, false); return; } QFile filejs; if(!openFile(filejs, fileName)) { emit codeGenerated(c, false); return; } QTextStream js(&filejs); ////////////////////////////// //Start generating the code!! ///////////////////////////// //try to find a heading file (license, coments, etc) QString str; str = getHeadingFile(".js"); if(!str.isEmpty()) { str.replace(QRegExp("%filename%"),fileName); str.replace(QRegExp("%filepath%"),filejs.name()); js << str << m_endl; } //write includes UMLPackageList includes; findObjectsRelated(c,includes); for (UMLPackage *conc = includes.first(); conc; conc = includes.next()) { QString headerName = findFileName(conc, ".js"); if ( !headerName.isEmpty() ) { js << "#include \"" << headerName << "\"" << m_endl; } } js << m_endl; //Write class Documentation if there is somthing or if force option if(forceDoc() || !c->getDoc().isEmpty()) { js << m_endl << "/**" << m_endl; js << " * class " << classname << m_endl; js << formatDoc(c->getDoc()," * "); js << " */" << m_endl << m_endl; } //check if class is abstract and / or has abstract methods if(c->getAbstract() && !hasAbstractOps(c)) js << "/******************************* Abstract Class ****************************" << m_endl << " " << classname << " does not have any pure virtual methods, but its author" << m_endl << " defined it as an abstract class, so you should not use it directly." << m_endl << " Inherit from it instead and create only objects from the derived classes" << m_endl << "*****************************************************************************/" << m_endl << m_endl; js << classname << " = function ()" << m_endl; js << "{" << m_endl; js << m_indentation << "this._init ();" << m_endl; js << "}" << m_endl; js << m_endl; UMLClassifierList superclasses = c->getSuperClasses(); for (UMLClassifier *obj = superclasses.first(); obj; obj = superclasses.next()) { js << classname << ".prototype = new " << cleanName(obj->getName()) << " ();" << m_endl; } js << m_endl; if (! c->isInterface()) { UMLAttributeList atl = c->getAttributeList(); js << "/**" << m_endl; QString temp = "_init sets all " + classname + " attributes to their default value." " Make sure to call this method within your class constructor"; js << formatDoc(temp, " * "); js << " */" << m_endl; js << classname << ".prototype._init = function ()" << m_endl; js << "{" << m_endl; for(UMLAttribute *at = atl.first(); at ; at = atl.next()) { if (forceDoc() || !at->getDoc().isEmpty()) { js << m_indentation << "/**" << m_endl << formatDoc(at->getDoc(), m_indentation + " * ") << m_indentation << " */" << m_endl; } if(!at->getInitialValue().isEmpty()) { js << m_indentation << "this.m_" << cleanName(at->getName()) << " = " << at->getInitialValue() << ";" << m_endl; } else { js << m_indentation << "this.m_" << cleanName(at->getName()) << " = \"\";" << m_endl; } } } //associations UMLAssociationList aggregations = c->getAggregations(); if (forceSections() || !aggregations.isEmpty ()) { js << m_endl << m_indentation << "/**Aggregations: */" << m_endl; writeAssociation(classname, aggregations , js ); } UMLAssociationList compositions = c->getCompositions(); if( forceSections() || !compositions.isEmpty()) { js << m_endl << m_indentation << "/**Compositions: */" << m_endl; writeAssociation(classname, compositions , js ); } js << m_endl; js << "}" << m_endl; js << m_endl; //operations UMLOperationList ops(c->getOpList()); writeOperations(classname, &ops, js); js << m_endl; //finish file //close files and notfiy we are done filejs.close(); emit codeGenerated(c, true); }
void SQLWriter::writeClass(UMLClassifier *c) { if(!c) { kDebug()<<"Cannot write class of NULL concept!" << endl; return; } const bool isClass = !c->isInterface(); QString classname = cleanName(c->getName()); //find an appropriate name for our file QString fileName = findFileName(c, ".sql"); if (fileName.isEmpty()) { emit codeGenerated(c, false); return; } QFile file; if( !openFile(file, fileName) ) { emit codeGenerated(c, false); return; } //Start generating the code!! QTextStream sql(&file); //try to find a heading file (license, coments, etc) QString str; str = getHeadingFile(".sql"); if(!str.isEmpty()) { str.replace(QRegExp("%filename%"),fileName); str.replace(QRegExp("%filepath%"),file.name()); sql<<str<<m_endl; } //Write class Documentation if there is somthing or if force option if(forceDoc() || !c->getDoc().isEmpty()) { sql << m_endl << "--" << m_endl; sql<<"-- TABLE: "<<classname<<m_endl; sql<<formatDoc(c->getDoc(),"-- "); sql << "-- " << m_endl << m_endl; } sql << "CREATE TABLE "<< classname << " ( " << m_endl; if (isClass) writeAttributes(c, sql); sql << m_endl << ");" << m_endl; QMap<UMLAssociation*,UMLAssociation*> constraintMap; // so we don't repeat constraint UMLAssociationList aggregations = c->getAggregations(); if( forceSections() || !aggregations.isEmpty() ) { for(UMLAssociation* a = aggregations.first(); a; a = aggregations.next()) { UMLObject *objA = a->getObject(Uml::A); UMLObject *objB = a->getObject(Uml::B); if (objA->getID() == c->getID() && objB->getID() != c->getID()) continue; constraintMap[a] = a; } } QMap<UMLAssociation*,UMLAssociation*>::Iterator itor = constraintMap.begin(); for (;itor != constraintMap.end();itor++) { UMLAssociation* a = itor.data(); sql << "ALTER TABLE "<< classname << " ADD CONSTRAINT " << a->getName() << " FOREIGN KEY (" << a->getRoleName(Uml::B) << ") REFERENCES " << a->getObject(Uml::A)->getName() << " (" << a->getRoleName(Uml::A) << ");" << m_endl; } file.close(); emit codeGenerated(c, true); }
/** * Call this method to generate C++ code for a UMLClassifier. * @param c the class you want to generate code for. */ void RubyWriter::writeClass(UMLClassifier *c) { if (!c) { uDebug() << "Cannot write class of NULL concept!"; return; } UMLClassifierList superclasses = c->getSuperClasses(); UMLAssociationList aggregations = c->getAggregations(); UMLAssociationList compositions = c->getCompositions(); //find an appropriate name for our file fileName_ = findFileName(c, QLatin1String(".rb")); if (fileName_.isEmpty()) { emit codeGenerated(c, false); return; } QFile fileh; if (!openFile(fileh, fileName_)) { emit codeGenerated(c, false); return; } QTextStream h(&fileh); className_ = cleanName(c->name()); ////////////////////////////// //Start generating the code!! ///////////////////////////// //try to find a heading file (license, coments, etc) QString str; str = getHeadingFile(QLatin1String(".rb")); if (!str.isEmpty()) { str.replace(QRegExp(QLatin1String("%filename%")), fileName_); str.replace(QRegExp(QLatin1String("%filepath%")), fileh.fileName()); h << str << m_endl; } if (forceDoc() || !c->doc().isEmpty()) { QString docStr = c->doc(); docStr.replace(QRegExp(QLatin1String("\\n")), QLatin1String("\n# ")); docStr.remove(QLatin1String("@ref ")); docStr.replace(QLatin1String("@see"), QLatin1String("_See_")); docStr.replace(QLatin1String("@short"), QLatin1String("_Summary_")); docStr.replace(QLatin1String("@author"), QLatin1String("_Author_")); h << "#" << m_endl; h << "# " << docStr << m_endl; h << "#" << m_endl << m_endl; } // write inheritances out UMLClassifier *concept; h << "class " << cppToRubyType(className_) << (superclasses.count() > 0 ? QLatin1String(" < ") : QString()); int i = 0; foreach (concept, superclasses) { if (i == 0) { h << cppToRubyType(concept->name()) << m_endl; } else { // Assume ruby modules that can be mixed in, after the first // superclass name in the list h << m_indentation << "include " << cppToRubyType(concept->name()) << m_endl; } i++; } h << m_endl; // write comment for sub-section IF needed if (forceDoc() || c->hasAccessorMethods()) { h << m_indentation << "#" << m_endl; h << m_indentation << "# Accessor Methods" << m_endl; h << m_indentation << "#" << m_endl << m_endl; // Accessor methods for attributes writeAttributeMethods(c->getAttributeList(Uml::Visibility::Public), Uml::Visibility::Public, h); writeAttributeMethods(c->getAttributeList(Uml::Visibility::Protected), Uml::Visibility::Protected, h); writeAttributeMethods(c->getAttributeList(Uml::Visibility::Private), Uml::Visibility::Private, h); h << m_endl; } //operations writeOperations(c, h); //finish files h << "end" << m_endl << m_endl; //close files and notfiy we are done fileh.close(); emit codeGenerated(c, true); }
/** * Write the source code body file for this classifier. */ void CppWriter::writeSourceFile(UMLClassifier *c, QFile &file) { // open stream for writing QTextStream cpp (&file); // set the starting indentation at zero m_indentLevel = 0; //try to find a heading file (license, coments, etc) QString str; str = getHeadingFile(".cpp"); if (!str.isEmpty()) { str.replace(QRegExp("%filename%"), fileName_ + ".cpp"); str.replace(QRegExp("%filepath%"), file.fileName()); cpp << str << m_endl; } // IMPORT statements // Q: Why all utils? Isnt just List and Vector the only classes we are using? // Our import *should* also look at operations, and check that objects being // used arent in another package (and thus need to be explicitly imported here). cpp << "#include \"" << className_ << ".h\"" << m_endl; writeBlankLine(cpp); if (c->visibility() == Uml::Visibility::Implementation) { writeClassDecl(c, cpp); } // Start body of class // Constructors: anything we more we need to do here ? // if (!c->isInterface()) writeConstructorMethods(c, cpp); // METHODS // // write comment for section IF needed QString indnt = indent(); if (forceDoc() || c->hasAccessorMethods() || c->hasOperationMethods()) { writeComment(" ", indnt, cpp); writeComment("Methods", indnt, cpp); writeComment(" ", indnt, cpp); writeBlankLine(cpp); writeBlankLine(cpp); } // write comment for sub-section IF needed if (forceDoc() || c->hasAccessorMethods() ) { writeComment("Accessor methods", indnt, cpp); writeComment(" ", indnt, cpp); writeBlankLine(cpp); } // Accessor methods for attributes const bool bInlineAccessors = policyExt()->getAccessorsAreInline(); if (!bInlineAccessors && c->hasAttributes()) { writeAttributeMethods(c->getAttributeListStatic(Uml::Visibility::Public), Uml::Visibility::Public, false, true, !bInlineAccessors, cpp); writeAttributeMethods(c->getAttributeList(Uml::Visibility::Public), Uml::Visibility::Public, false, false, !bInlineAccessors, cpp); writeAttributeMethods(c->getAttributeListStatic(Uml::Visibility::Protected), Uml::Visibility::Protected, false, true, !bInlineAccessors, cpp); writeAttributeMethods(c->getAttributeList(Uml::Visibility::Protected), Uml::Visibility::Protected, false, false, !bInlineAccessors, cpp); writeAttributeMethods(c->getAttributeListStatic(Uml::Visibility::Private), Uml::Visibility::Private, false, true, !bInlineAccessors, cpp); writeAttributeMethods(c->getAttributeList(Uml::Visibility::Private), Uml::Visibility::Private, false, false, !bInlineAccessors, cpp); } // accessor methods for associations // public writeAssociationMethods(c->getSpecificAssocs(Uml::at_Association), Uml::Visibility::Public, false, !INLINE_ASSOCIATION_METHODS, true, c->id(), cpp); writeAssociationMethods(c->getUniAssociationToBeImplemented(), Uml::Visibility::Public, false, !INLINE_ASSOCIATION_METHODS, true, c->id(), cpp); writeAssociationMethods(c->getAggregations(), Uml::Visibility::Public, false, !INLINE_ASSOCIATION_METHODS, true, c->id(), cpp); writeAssociationMethods(c->getCompositions(), Uml::Visibility::Public, false, !INLINE_ASSOCIATION_METHODS, true, c->id(), cpp); // protected writeAssociationMethods(c->getSpecificAssocs(Uml::at_Association), Uml::Visibility::Protected, false, !INLINE_ASSOCIATION_METHODS, true, c->id(), cpp); writeAssociationMethods(c->getUniAssociationToBeImplemented(), Uml::Visibility::Protected, false, !INLINE_ASSOCIATION_METHODS, true, c->id(), cpp); writeAssociationMethods(c->getAggregations(), Uml::Visibility::Protected, false, !INLINE_ASSOCIATION_METHODS, true, c->id(), cpp); writeAssociationMethods(c->getCompositions(), Uml::Visibility::Protected, false, !INLINE_ASSOCIATION_METHODS, true, c->id(), cpp); // private writeAssociationMethods(c->getSpecificAssocs(Uml::at_Association), Uml::Visibility::Private, false, !INLINE_ASSOCIATION_METHODS, true, c->id(), cpp); writeAssociationMethods(c->getUniAssociationToBeImplemented(), Uml::Visibility::Private, false, !INLINE_ASSOCIATION_METHODS, true, c->id(), cpp); writeAssociationMethods(c->getAggregations(), Uml::Visibility::Private, false, !INLINE_ASSOCIATION_METHODS, true, c->id(), cpp); writeAssociationMethods(c->getCompositions(), Uml::Visibility::Private, false, !INLINE_ASSOCIATION_METHODS, true, c->id(), cpp); writeBlankLine(cpp); // Other operation methods -- all other operations are now written // // write comment for sub-section IF needed if (forceDoc() || c->hasOperationMethods()) { writeComment("Other methods", indnt, cpp); writeComment(" ", indnt, cpp); writeBlankLine(cpp); } if (!policyExt()->getOperationsAreInline()) { writeOperations(c,false,Uml::Visibility::Public,cpp); writeOperations(c,false,Uml::Visibility::Protected,cpp); writeOperations(c,false,Uml::Visibility::Private,cpp); } // Yep, bringing up the back of the bus, our initialization method for attributes writeInitAttributeMethod(c, cpp); writeBlankLine(cpp); }
// main method for invoking.. void XMLSchemaWriter::writeClass(UMLClassifier *c) { if (!c) { kDebug()<<"Cannot write class of NULL classifier!\n"; return; } // find an appropriate name for our file QString fileName = findFileName(c,".xsd"); if (fileName.isEmpty()) { emit codeGenerated(c, false); return; } // check that we may open that file for writing QFile file; if ( !openFile(file, fileName) ) { emit codeGenerated(c, false); return; } QTextStream XMLschema(&file); // set package namespace tag appropriately if(!c->getPackage().isEmpty()) packageNamespaceTag = c->getPackage(); // START WRITING // 0. FIRST THING: open the xml processing instruction. This MUST be // the first thing in the file XMLschema<<"<?xml version=\"1.0\"?>"<<m_endl; // 1. create the header QString headerText = getHeadingFile(".xsd"); if(!headerText.isEmpty()) { headerText.replace(QRegExp("%filename%"),fileName); headerText.replace(QRegExp("%filepath%"),file.name()); } if(!headerText.isEmpty()) XMLschema<<headerText<<m_endl; // 2. Open schema element node with appropriate namespace decl XMLschema<<"<"<<makeSchemaTag("schema"); // common namespaces we know will be in the file.. XMLschema<<" targetNamespace=\""<<packageNamespaceURI+packageNamespaceTag<<"\""<<m_endl; XMLschema<<" xmlns:"<<schemaNamespaceTag<<"=\""<<schemaNamespaceURI<<"\""; XMLschema<<" xmlns:"<<packageNamespaceTag<<"=\""<<packageNamespaceURI+packageNamespaceTag<<"\""; XMLschema<<">"<<m_endl; // close opening declaration m_indentLevel++; // 3? IMPORT statements -- do we need to do anything here? I suppose if // our document has more than one package, which is possible, we are missing // the correct import statements. Leave that for later at this time. /* //only import classes in a different package as this class UMLPackageList imports; findObjectsRelated(c,imports); for(UMLPackage *con = imports.first(); con ; con = imports.next()) if(con->getPackage() != c->getPackage()) XMLschema<<"import "<<con->getPackage()<<"."<<cleanName(con->getName())<<";"<<m_endl; */ // 4. BODY of the schema. // start the writing by sending this classifier, the "root" for this particular // schema, to writeClassifier method, which will subsequently call itself on all // related classifiers and thus populate the schema. writeClassifier(c, XMLschema); // 5. What remains is to make the root node declaration XMLschema<<m_endl; writeElementDecl(getElementName(c), getElementTypeName(c), XMLschema); // 6. Finished: now we may close schema decl m_indentLevel--; XMLschema<<getIndent()<<"</"<<makeSchemaTag("schema")<<">"<<m_endl; // finished.. close schema node // bookeeping for code generation emit codeGenerated(c, true); // tidy up. no dangling open files please.. file.close(); // need to clear HERE, NOT in the destructor because we want each // schema that we write to have all related classes. writtenClassifiers.clear(); }