void DWriter::writeModuleImports(UMLClassifier *c, QTextStream &d) { // another preparation, determine what we have UMLAssociationList associations = c->getSpecificAssocs(Uml::AssociationType::Association); // BAD! only way to get "general" associations. UMLAssociationList uniAssociations = c->getUniAssociationToBeImplemented(); UMLAssociationList aggregations = c->getAggregations(); UMLAssociationList compositions = c->getCompositions(); bool hasAssociations = aggregations.count() + associations.count() + compositions.count() + uniAssociations.count() > 0; if (hasAssociations) { // import tango, if that mode is set writeBlankLine(d); } //only import classes in a different package as this class UMLPackageList imports; findObjectsRelated(c, imports); foreach (UMLPackage* con, imports) { if (con->baseType() == UMLObject::ot_Datatype) continue; QString pkg = con->package(); if (!pkg.isEmpty() && pkg != c->package()) d << "import " << pkg << "." << cleanName(con->name()) << ";" << m_endl; } writeBlankLine(d); }
/** * 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; } }
bool PerlWriter::GetUseStatements(UMLClassifier *c, QString &Ret, QString &ThisPkgName) { if (!c){ return(false); } UMLPackageList includes; findObjectsRelated(c,includes); QString AV = QChar('@'); QString SV = QChar('$'); QString HV = QChar('%'); foreach (UMLPackage* conc, includes ) { if (conc->baseType() == Uml::ot_Datatype) continue; QString neatName = cleanName(conc->name()); if (neatName != AV && neatName != SV && neatName != HV) { QString OtherPkgName = conc->package("."); OtherPkgName.replace(QRegExp("\\."),"::"); QString OtherName = OtherPkgName + "::" + cleanName(conc->name()); // Only print out the use statement if the other package isn't the // same as the one we are working on. (This happens for the // "Singleton" design pattern.) if (OtherName != ThisPkgName){ Ret += "use "; Ret += OtherName; Ret += ';'; Ret += m_endl; } } } UMLClassifierList superclasses = c->getSuperClasses(); if (superclasses.count()) { Ret += m_endl; Ret += "use base qw( "; foreach (UMLClassifier *obj , superclasses ) { QString packageName = obj->package("."); packageName.replace(QRegExp("\\."),"::"); Ret += packageName + "::" + cleanName(obj->name()) + ' '; }
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); }