UMLAttributeList XMLSchemaWriter::findAttributes (UMLClassifier *c) { // sort attributes by Scope UMLAttributeList attribs; attribs.setAutoDelete(false); if (!c->isInterface()) { UMLAttributeList atl = c->getAttributeList(); for(UMLAttribute *at=atl.first(); at ; at=atl.next()) { switch(at->getVisibility()) { case Uml::Visibility::Public: case Uml::Visibility::Protected: attribs.append(at); break; case Uml::Visibility::Private: // DO NOTHING! no way to print in the schema break; default: break; } } } return attribs; }
void SQLWriter::writeAttributes(UMLClassifier *c, QTextStream &sql) { UMLAttributeList atpub, atprot, atpriv, atimp; atpub.setAutoDelete(false); atprot.setAutoDelete(false); atpriv.setAutoDelete(false); atimp.setAutoDelete(false); //sort attributes by scope and see if they have a default value UMLAttributeList atl = c->getAttributeList(); for(UMLAttribute* at=atl.first(); at ; at=atl.next()) { switch(at->getVisibility()) { case Uml::Visibility::Public: atpub.append(at); break; case Uml::Visibility::Protected: atprot.append(at); break; case Uml::Visibility::Private: atpriv.append(at); break; case Uml::Visibility::Implementation: atimp.append(at); break; } } // now print the attributes; they are sorted by there scope // in front of the first attribute shouldn't be a , -> so we need to find // out, when the first attribute was added bool first = true; if (atpub.count() > 0) { printAttributes(sql, atpub, first); first = false; } if (atprot.count() > 0) { printAttributes(sql, atprot, first); first = false; } if (atpriv.count() > 0) { printAttributes(sql, atpriv, first); first = false; } if (atimp.count() > 0) { printAttributes(sql, atimp, first); first = false; } return; }
void JSWriter::writeOperations(QString classname, UMLOperationList *opList, QTextStream &js) { UMLOperation *op; UMLAttribute *at; for(op = opList->first(); op; op = opList->next()) { UMLAttributeList atl = op->getParmList(); //write method doc if we have doc || if at least one of the params has doc bool writeDoc = forceDoc() || !op->getDoc().isEmpty(); for (at = atl.first(); at; at = atl.next()) writeDoc |= !at->getDoc().isEmpty(); if( writeDoc ) //write method documentation { js << "/**" << m_endl << formatDoc(op->getDoc()," * "); for (at = atl.first(); at; at = atl.next()) //write parameter documentation { if(forceDoc() || !at->getDoc().isEmpty()) { js << " * @param " + cleanName(at->getName())<<m_endl; js << formatDoc(at->getDoc()," * "); } }//end for : write parameter documentation js << " */" << m_endl; }//end if : write method documentation js << classname << ".prototype." << cleanName(op->getName()) << " = function " << "("; int i = atl.count(); int j=0; for (at = atl.first(); at ;at = atl.next(),j++) { js << cleanName(at->getName()) << (!(at->getInitialValue().isEmpty()) ? (QString(" = ")+at->getInitialValue()) : QString("")) << ((j < i-1)?", ":""); } js << ")" << m_endl << "{" << m_endl << m_indentation << m_endl << "}" << m_endl; js << m_endl << m_endl; }//end for }
void XMLSchemaWriter::writeAttributeDecls(UMLAttributeList &attribs, QTextStream &XMLschema ) { UMLAttribute *at; for(at=attribs.first(); at; at=attribs.next()) { writeAttributeDecl(at,XMLschema); } }
void CSharpWriter::writeAttributes(UMLClassifier *c, QTextStream &cs) { UMLAttributeList atpub, atprot, atpriv, atdefval; atpub.setAutoDelete(false); atprot.setAutoDelete(false); atpriv.setAutoDelete(false); atdefval.setAutoDelete(false); //sort attributes by scope and see if they have a default value UMLAttributeList atl = c->getAttributeList(); UMLAttribute *at; for (at = atl.first(); at ; at = atl.next()) { if (!at->getInitialValue().isEmpty()) atdefval.append(at); switch (at->getVisibility()) { case Uml::Visibility::Public: atpub.append(at); break; case Uml::Visibility::Protected: atprot.append(at); break; case Uml::Visibility::Private: atpriv.append(at); break; default: break; } } if (forceSections() || atl.count()) cs << m_endl << m_container_indent << m_indentation << "#region Attributes" << m_endl << m_endl; // write public attributes if (forceSections() || atpub.count()) { writeAttributes(atpub,cs); } // write protected attributes if (forceSections() || atprot.count()) { writeAttributes(atprot,cs); } // write private attributes if (forceSections() || atpriv.count()) { writeAttributes(atpriv,cs); } if (forceSections() || atl.count()) cs << m_endl << m_container_indent << m_indentation << "#endregion" << m_endl << m_endl; }
void CSharpWriter::writeAttributes(UMLAttributeList &atList, QTextStream &cs) { for (UMLAttribute *at = atList.first(); at ; at = atList.next()) { bool asProperty = true; if (at->getVisibility() == Uml::Visibility::Private) { asProperty = false; } writeAttribute(at->getDoc(), at->getVisibility(), at->getStatic(), makeLocalTypeName(at), at->getName(), at->getInitialValue(), asProperty, cs); cs << m_endl; } // end for return; }
void UMLAttributeList::copyInto(UMLAttributeList *rhs) const { // Don't copy yourself. if (rhs == this) return; rhs->clear(); // Suffering from const; we shall not modify our object. UMLAttributeList *tmp = new UMLAttributeList(*this); UMLAttribute *item; for (item = tmp->first(); item; item = tmp->next() ) { rhs->append((UMLAttribute*)item->clone()); } delete tmp; }
void SQLWriter::printAttributes(QTextStream& sql, UMLAttributeList attributeList, bool first) { QString attrDoc = ""; UMLAttribute* at; for (at=attributeList.first();at;at=attributeList.next()) { // print , after attribute if (first == false) { sql <<","; } else { first = false; } // print documentation/comment of last attribute at end of line if (attrDoc.isEmpty() == false) { sql << " -- " << attrDoc << m_endl; } else { sql << m_endl; } // write the attribute sql << m_indentation << cleanName(at->getName()) << " " << at->getTypeName() << " " << (at->getInitialValue().isEmpty()?QString(""):QString(" DEFAULT ")+at->getInitialValue()); // now get documentation/comment of current attribute attrDoc = at->getDoc(); } // print documentation/comment at end of line if (attrDoc.isEmpty() == false) { sql << " -- " << attrDoc << m_endl; } else { sql << m_endl; } return; }
/** * update the start and end text for this ownedhierarchicalcodeblock. */ void XMLElementCodeBlock::updateContent ( ) { QString endLine = getNewLineEndingChars(); QString nodeName = getNodeName(); // Now update START/ENDING Text QString startText = '<' + nodeName; QString endText = ""; UMLAttributeList * alist = getAttributeList(); for (UMLAttribute *at = alist->first(); at; at=alist->next()) { if(at->getInitialValue().isEmpty()) kWarning()<<" XMLElementCodeBlock : cant print out attribute that lacks an initial value"<<endl; else { startText.append(" " +at->getName()+"=\""); startText.append(at->getInitialValue()+"\""); } } // now set close of starting/ending node, the style depending on whether we have child text or not if(getTextBlockList()->count()) { startText.append(">"); endText = "</" + nodeName + '>'; } else { startText.append("/>"); endText = ""; } setStartText(startText); setEndText(endText); }
void XMLSchemaWriter::writeAttributeGroupDecl (const QString &elementName, UMLAttributeList &attribs, QTextStream &XMLschema ) { if (attribs.count()> 0) { // write a little documentation writeComment("attributes for element "+elementName,XMLschema); // open attribute group XMLschema<<getIndent()<<"<"<<makeSchemaTag("attributeGroup")<<" name=\""<<elementName+"AttribGroupType"<<"\">"<<m_endl; m_indentLevel++; for( UMLAttribute *at=attribs.first(); at; at=attribs.next()) { writeAttributeDecl(at,XMLschema); } m_indentLevel--; // close attrib group node XMLschema<<getIndent()<<"</"<<makeSchemaTag("attributeGroup")<<">"<<m_endl; } }
ClassifierInfo::ClassifierInfo( UMLClassifier *classifier) { classifier_ = classifier; // set default class, file names className = classifier->getName(); fileName = classifier->getName().lower(); // determine up-front what we are dealing with isInterface = classifier->isInterface(); // sort attributes by Scope if(!isInterface) { UMLAttributeList atl = classifier->getAttributeList(); for(UMLAttribute *at=atl.first(); at ; at=atl.next()) { switch(at->getVisibility()) { case Uml::Visibility::Public: if(at->getStatic()) static_atpub.append(at); else atpub.append(at); break; case Uml::Visibility::Protected: if(at->getStatic()) static_atprot.append(at); else atprot.append(at); break; case Uml::Visibility::Private: case Uml::Visibility::Implementation: if(at->getStatic()) static_atpriv.append(at); else atpriv.append(at); break; } } } // inheritance issues superclasses = classifier->getSuperClasses(); // list of what we inherit from subclasses = classifier->getSubClasses(); // list of what inherits from us // another preparation, determine what we have plainAssociations = classifier->getSpecificAssocs(Uml::at_Association); // BAD! only way to get "general" associations. uniAssociations = classifier->getUniAssociationToBeImplemented(); aggregations = classifier->getAggregations(); compositions = classifier->getCompositions(); // set some summary information about the classifier now 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 || static_atpriv.count() > 0; hasStaticAttributes = static_atpub.count() > 0 || static_atprot.count() > 0 || static_atpriv.count() > 0; hasAccessorMethods = hasAttributes || hasAssociations; hasOperationMethods = classifier->getOpList().last() ? true : false; hasMethods = hasOperationMethods || hasAccessorMethods; // this is a bit too simplistic..some associations are for // SINGLE objects, and WONT be declared as Vectors, so this // is a bit overly inclusive (I guess that's better than the other way around) hasVectorFields = hasAssociations ? true : false; }
void CSharpWriter::writeOperations(UMLOperationList opList, QTextStream &cs, bool isInterface /* = false */, bool isOverride /* = false */, bool generateErrorStub /* = false */) { for (UMLOperation *op=opList.first(); op ; op=opList.next()) { UMLAttributeList atl = op->getParmList(); UMLAttribute *at; //write method doc if we have doc || if at least one of the params has doc bool writeDoc = forceDoc() || !op->getDoc().isEmpty(); for (at = atl.first(); at; at = atl.next()) { writeDoc |= !at->getDoc().isEmpty(); } //write method documentation if (writeDoc && !isOverride) { cs << m_container_indent << m_indentation << "/// <summary>" << m_endl; cs << formatDoc(op->getDoc(), m_container_indent + m_indentation + "/// "); cs << m_container_indent << m_indentation << "/// </summary>" << m_endl; //write parameter documentation for (at = atl.first(); at; at = atl.next()) { if (forceDoc() || !at->getDoc().isEmpty()) { cs << m_container_indent << m_indentation << "/// <param name=\"" << cleanName(at->getName()) << "\">"; //removing newlines from parameter doc cs << formatDoc(at->getDoc(), "").replace("\n", " ").remove('\r').replace(QRegExp(" $"), ""); cs << "</param>" << m_endl; } } // FIXME: "returns" should contain documentation, not type. cs << m_container_indent << m_indentation << "/// <returns>"; if (! op->getTypeName().isEmpty()) { cs << makeLocalTypeName(op); } cs << "</returns>" << m_endl; } // method visibility cs << m_container_indent << m_indentation; if (!isInterface) { if (!isOverride) { if (op->getAbstract()) cs << "abstract "; cs << op->getVisibility().toString() << " "; if (op->getStatic()) cs << "static "; } else { // method overriding an abstract parent cs << op->getVisibility().toString() << " override "; if (op->getStatic()) cs << "static "; } } // return type (unless constructor, destructor) if (!op->isLifeOperation()) { if (op->getTypeName().isEmpty()) { cs << "void "; } else { cs << makeLocalTypeName(op) << " "; } } // method name cs << cleanName(op->getName()) << "("; // method parameters int i= atl.count(); int j=0; for (at = atl.first(); at; at = atl.next(), j++) { cs << makeLocalTypeName(at) << " " << cleanName(at->getName()); // no initial values in C# //<< (!(at->getInitialValue().isEmpty()) ? // (QString(" = ")+at->getInitialValue()) : // QString("")) cs << ((j < i-1)?", ":""); } cs << ")"; //FIXME: how to control generation of error stub? if (!isInterface && (!op->getAbstract() || isOverride)) { cs << m_endl << m_container_indent << m_indentation << "{" << m_endl; if (generateErrorStub) { cs << m_container_indent << m_indentation << m_indentation; cs << "throw new Exception(\"The method or operation is not implemented.\");" << m_endl; } cs << m_container_indent << m_indentation << "}" << m_endl; } else { cs << ';' << m_endl; } cs << m_endl; } }
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 UMLOperationDialog::setupDialog() { int margin = fontMetrics().height(); QVBoxLayout * topLayout = new QVBoxLayout( plainPage() ); m_pGenGB = new QGroupBox(i18n("General Properties"), plainPage() ); QGridLayout * genLayout = new QGridLayout(m_pGenGB, 3, 4 ); genLayout -> setColStretch(1, 1); genLayout -> setColStretch(3, 1); genLayout -> addColSpacing(1, 200); genLayout -> addColSpacing(3, 200); genLayout -> setMargin(margin); genLayout -> setSpacing(10); Dialog_Utils::makeLabeledEditField( m_pGenGB, genLayout, 0, m_pNameL, i18n("&Name:"), m_pNameLE, m_pOperation->getName() ); m_pRtypeL = new QLabel(i18n("&Type:"), m_pGenGB ); genLayout -> addWidget(m_pRtypeL, 0, 2); m_pRtypeCB = new KComboBox(true, m_pGenGB ); genLayout -> addWidget(m_pRtypeCB, 0, 3); m_pRtypeL->setBuddy(m_pRtypeCB); m_pStereoTypeL = new QLabel( i18n("Stereotype name:"), m_pGenGB ); genLayout -> addWidget(m_pStereoTypeL, 1, 0); m_pStereoTypeCB = new KComboBox(true, m_pGenGB ); genLayout -> addWidget(m_pStereoTypeCB, 1, 1); m_pAbstractCB = new QCheckBox( i18n("&Abstract operation"), m_pGenGB ); m_pAbstractCB -> setChecked( m_pOperation->getAbstract() ); genLayout -> addWidget( m_pAbstractCB, 2, 0 ); m_pStaticCB = new QCheckBox( i18n("Classifier &scope (\"static\")"), m_pGenGB ); m_pStaticCB -> setChecked( m_pOperation->getStatic() ); genLayout -> addWidget( m_pStaticCB, 2, 1 ); m_pQueryCB = new QCheckBox( i18n("&Query (\"const\")"), m_pGenGB ); m_pQueryCB -> setChecked( m_pOperation->getConst() ); genLayout -> addWidget( m_pQueryCB, 2, 2 ); topLayout -> addWidget( m_pGenGB ); m_pScopeBG = new QButtonGroup(i18n("Visibility"), plainPage() ); QHBoxLayout * scopeLayout = new QHBoxLayout(m_pScopeBG); scopeLayout -> setMargin(margin); m_pPublicRB = new QRadioButton(i18n("P&ublic"), m_pScopeBG); scopeLayout -> addWidget(m_pPublicRB); m_pPrivateRB = new QRadioButton(i18n("P&rivate"), m_pScopeBG); scopeLayout -> addWidget(m_pPrivateRB); m_pProtectedRB = new QRadioButton(i18n("Prot&ected"), m_pScopeBG); scopeLayout -> addWidget(m_pProtectedRB); m_pImplementationRB = new QRadioButton(i18n("I&mplementation"), m_pScopeBG); scopeLayout -> addWidget(m_pImplementationRB); topLayout -> addWidget(m_pScopeBG); m_pParmsGB = new QGroupBox(i18n("Parameters"), plainPage() ); QVBoxLayout* parmsLayout = new QVBoxLayout(m_pParmsGB); parmsLayout->setMargin(margin); parmsLayout->setSpacing(10); //horizontal box contains the list box and the move up/down buttons QHBoxLayout* parmsHBoxLayout = new QHBoxLayout(parmsLayout); m_pParmsLB = new QListBox(m_pParmsGB); parmsHBoxLayout->addWidget(m_pParmsLB); //the move up/down buttons (another vertical box) QVBoxLayout* buttonLayout = new QVBoxLayout( parmsHBoxLayout ); m_pUpButton = new KArrowButton( m_pParmsGB ); m_pUpButton->setEnabled( false ); buttonLayout->addWidget( m_pUpButton ); m_pDownButton = new KArrowButton( m_pParmsGB, Qt::DownArrow ); m_pDownButton->setEnabled( false ); buttonLayout->addWidget( m_pDownButton ); KButtonBox* buttonBox = new KButtonBox(m_pParmsGB); buttonBox->addButton( i18n("Ne&w Parameter..."), this, SLOT(slotNewParameter()) ); m_pDeleteButton = buttonBox->addButton( i18n("&Delete"), this, SLOT(slotDeleteParameter()) ); m_pPropertiesButton = buttonBox->addButton( i18n("&Properties"), this, SLOT(slotParameterProperties()) ); parmsLayout->addWidget(buttonBox); topLayout -> addWidget(m_pParmsGB); m_pDeleteButton->setEnabled(false); m_pPropertiesButton->setEnabled(false); m_pUpButton->setEnabled(false); m_pDownButton->setEnabled(false); // Add "void". We use this for denoting "no return type" independent // of the programming language. // For example, the Ada generator would interpret the return type // "void" as an instruction to generate a procedure instead of a // function. insertType( "void" ); m_pRtypeCB->setDuplicatesEnabled(false);//only allow one of each type in box m_pRtypeCB->setCompletionMode( KGlobalSettings::CompletionPopup ); // add template parameters UMLClassifier *classifier = dynamic_cast<UMLClassifier*>(m_pOperation->parent()); if (classifier) { UMLClassifierListItemList tmplParams( classifier->getFilteredList(Uml::ot_Template) ); for (UMLClassifierListItem *li = tmplParams.first(); li; li = tmplParams.next()) insertType( li->getName() ); } //now add the Classes and Interfaces (both are Concepts) UMLClassifierList namesList( m_doc->getConcepts() ); UMLClassifier* pConcept = 0; for(pConcept=namesList.first(); pConcept!=0 ;pConcept=namesList.next()) { insertType( pConcept->getFullyQualifiedName() ); } //work out which one to select int returnBoxCount = 0; bool foundReturnType = false; while (returnBoxCount < m_pRtypeCB->count() && foundReturnType == false) { QString returnBoxString = m_pRtypeCB->text(returnBoxCount); if ( returnBoxString == m_pOperation->getTypeName() ) { foundReturnType = true; m_pRtypeCB->setCurrentItem(returnBoxCount); break; } returnBoxCount++; } if (!foundReturnType) { insertType( m_pOperation->getTypeName(), 0 ); m_pRtypeCB->setCurrentItem(0); } //fill in parm list box UMLAttributeList list = m_pOperation->getParmList(); UMLAttribute * pAtt = 0; for (pAtt = list.first(); pAtt; pAtt = list.next()) m_pParmsLB->insertItem( pAtt->getName() ); //set scope Uml::Visibility scope = m_pOperation -> getVisibility(); if( scope == Uml::Visibility::Public ) m_pPublicRB -> setChecked( true ); else if( scope == Uml::Visibility::Private ) m_pPrivateRB -> setChecked( true ); else if( scope == Uml::Visibility::Protected ) m_pProtectedRB -> setChecked( true ); else if( scope == Uml::Visibility::Implementation ) m_pImplementationRB -> setChecked( true ); // manage stereotypes m_pStereoTypeCB -> setDuplicatesEnabled(false);//only allow one of each type in box m_pStereoTypeCB->setCompletionMode( KGlobalSettings::CompletionPopup ); insertStereotype (QString("")); // an empty stereotype is the default int defaultStereotype=0; bool foundDefaultStereotype = false; for (UMLStereotypeListIt it(m_doc->getStereotypes()); it.current(); ++it) { if (!foundDefaultStereotype) { if ( m_pOperation->getStereotype() == it.current()->getName()) { foundDefaultStereotype = true; } defaultStereotype++; } insertStereotype (it.current()->getName()); } // lookup for a default stereotype, if the operation doesn't have one if (foundDefaultStereotype) m_pStereoTypeCB->setCurrentItem(defaultStereotype); else m_pStereoTypeCB->setCurrentItem(-1); //setup parm list box signals connect( m_pUpButton, SIGNAL( clicked() ), this, SLOT( slotParameterUp() ) ); connect( m_pDownButton, SIGNAL( clicked() ), this, SLOT( slotParameterDown() ) ); connect(m_pParmsLB, SIGNAL(clicked(QListBoxItem*)), this, SLOT(slotParamsBoxClicked(QListBoxItem*))); connect(m_pParmsLB, SIGNAL(rightButtonPressed(QListBoxItem *, const QPoint &)), this, SLOT(slotParmRightButtonPressed(QListBoxItem *, const QPoint &))); connect(m_pParmsLB, SIGNAL(rightButtonClicked(QListBoxItem *, const QPoint &)), this, SLOT(slotParmRightButtonClicked(QListBoxItem *, const QPoint &))); connect(m_pParmsLB, SIGNAL(doubleClicked(QListBoxItem *)), this, SLOT(slotParmDoubleClick(QListBoxItem *))); m_pNameLE->setFocus(); connect( m_pNameLE, SIGNAL( textChanged ( const QString & ) ), SLOT( slotNameChanged( const QString & ) ) ); slotNameChanged(m_pNameLE->text() ); }
// we basically want to update the doc and start text of this method void RubyCodeOperation::updateMethodDeclaration() { CodeDocument * doc = getParentDocument(); RubyClassifierCodeDocument * rubydoc = dynamic_cast<RubyClassifierCodeDocument*>(doc); UMLClassifier *c = rubydoc->getParentClassifier(); UMLOperation * o = getParentOperation(); bool isInterface = rubydoc->getParentClassifier()->isInterface(); QString endLine = getNewLineEndingChars(); // now, the starting text. QString strVis = rubydoc->scopeToRubyDecl(o->getVisibility()); // no return type for constructors QString fixedReturn = RubyCodeGenerator::cppToRubyType(o->getTypeName()); QString returnType = o->isConstructorOperation() ? QString("") : (fixedReturn + QString(" ")); QString methodName = o->getName(); QString RubyClassName = rubydoc->getRubyClassName(c->getName()); // Skip destructors, and operator methods which // can't be defined in ruby if ( methodName.startsWith("~") || QRegExp("operator\\s*(=|--|\\+\\+|!=)$").exactMatch(methodName) ) { getComment()->setText(""); return; } if (RubyClassName == methodName) { methodName = "initialize"; } methodName.replace(QRegExp("operator\\s*"), ""); methodName = methodName.mid(0, 1).lower() + methodName.mid(1); QString paramStr = QString(""); QStringList commentedParams; // assemble parameters UMLAttributeList list = getParentOperation()->getParmList(); int nrofParam = list.count(); int paramNum = 0; for(UMLAttribute* parm = list.first(); parm; parm = list.next()) { QString paramName = RubyCodeGenerator::cppToRubyName(parm->getName()); paramStr += paramName; if (! parm->getInitialValue().isEmpty()) { paramStr += QString(" = ") + RubyCodeGenerator::cppToRubyType(parm->getInitialValue()); } paramNum++; if (paramNum != nrofParam ) paramStr += ", "; } QString startText; if (isInterface) { // Assume 'isInterface' means a module in Ruby, so // generate module methods startText = "def "+ RubyClassName + '.' + methodName + '(' + paramStr +')'; } else { startText = "def "+ methodName + '(' + paramStr +')'; } startText += ""; setEndMethodText("end"); setStartMethodText(startText); // Lastly, for text content generation, we fix the comment on the // operation, IF the codeop is autogenerated & currently empty QString comment = o->getDoc(); if (comment.isEmpty()) { if (getContentType() == CodeBlock::AutoGenerated) { UMLAttributeList parameters = o->getParmList(); for(UMLAttributeListIt iterator(parameters); iterator.current(); ++iterator) { comment += endLine + "* _" + iterator.current()->getName() + "_ "; comment += (' ' + iterator.current()->getDoc().replace( QRegExp("[\\n\\r]+[\\t ]*"), endLine + " " ) ); } // add a returns statement too if(!returnType.isEmpty() && !QRegExp("^void\\s*$").exactMatch(returnType)) comment += endLine + "* _returns_ " + returnType + ' '; getComment()->setText(comment); } } else { comment.replace(QRegExp("[\\n\\r]+ *"), endLine); comment.replace(QRegExp("[\\n\\r]+\\t*"), endLine); comment.replace(" m_", " "); comment.replace(QRegExp("\\s[npb](?=[A-Z])"), " "); QRegExp re_params("@param (\\w)(\\w*)"); int pos = re_params.search(comment); while (pos != -1) { comment.replace( re_params.cap(0), QString("@param _") + re_params.cap(1).lower() + re_params.cap(2) + '_' ); commentedParams.append(re_params.cap(1).lower() + re_params.cap(2)); pos += re_params.matchedLength() + 3; pos = re_params.search(comment, pos); } UMLAttributeList parameters = o->getParmList(); for (UMLAttributeListIt iterator(parameters); iterator.current(); ++iterator) { // Only write an individual @param entry if one hasn't been found already // in the main doc comment if (commentedParams.contains(RubyCodeGenerator::cppToRubyName(iterator.current()->getName())) == 0) { comment += (endLine + "@param _" + RubyCodeGenerator::cppToRubyName(iterator.current()->getName()) + '_'); if (iterator.current()->getDoc().isEmpty()) { comment += (' ' + RubyCodeGenerator::cppToRubyType(iterator.current()->getTypeName())); } else { comment += (' ' + iterator.current()->getDoc().replace(QRegExp("[\\n\\r]+[\\t ]*"), endLine + " ")); } } } comment.replace("@ref ", ""); comment.replace("@param", "*"); comment.replace("@return", "* _returns_"); // All lines after the first one starting with '*' in the doc comment // must be indented correctly. If they aren't a list // item starting with '*', then indent the text with // two spaces, ' ', to line up with the list item. pos = comment.find(endLine + '*'); if (pos != -1) { pos += endLine.length() + 1; pos = comment.find(endLine, pos); } while (pos > 0) { pos += endLine.length(); if (comment[pos] != '*') { comment.insert(pos, " "); pos += 2; } pos = comment.find(endLine, pos); } QString typeStr = RubyCodeGenerator::cppToRubyType(o->getTypeName()); if ( !typeStr.isEmpty() && !QRegExp("^void\\s*$").exactMatch(typeStr) && comment.contains("_returns_") == 0 ) { comment += endLine + "* _returns_ " + typeStr; } getComment()->setText(comment); } // In Java, for interfaces..we DONT write out non-public // method declarations. And for Ruby modules? if (isInterface) { UMLOperation * o = getParentOperation(); if(o->getVisibility() != Uml::Visibility::Public) setWriteOutText(false); } }
void RefactoringAssistant::addClassifier( UMLClassifier *classifier, QListViewItem *parent, bool addSuper, bool addSub, bool recurse) { QListViewItem *classifierItem, *item; if( parent ) { classifierItem = parent; } else { classifierItem= new KListViewItem( this, classifier->getName() ); m_umlObjectMap[classifierItem] = classifier; } connect( classifier, SIGNAL( modified() ), this, SLOT( umlObjectModified() ) ); UMLClassifier *klass = dynamic_cast<UMLClassifier*>(classifier); if( klass ) {// only Classes have attributes... connect( classifier, SIGNAL(attributeAdded(UMLClassifierListItem*)), this, SLOT(attributeAdded(UMLClassifierListItem*))); connect( classifier, SIGNAL(attributeRemoved(UMLClassifierListItem*)), this, SLOT(attributeRemoved(UMLClassifierListItem*))); QListViewItem *attsFolder = new KListViewItem( classifierItem, i18n("Attributes"), "attributes" ); attsFolder->setPixmap(0,SmallIcon("folder_green_open")); attsFolder->setExpandable( true ); UMLAttributeList atts = klass->getAttributeList(); for( UMLAttribute *att = atts.first(); att; att = atts.next() ) { attributeAdded( att ); } } // add operations connect( classifier, SIGNAL(operationAdded(UMLClassifierListItem*)), this, SLOT(operationAdded(UMLClassifierListItem*))); connect( classifier, SIGNAL(operationRemoved(UMLClassifierListItem*)), this, SLOT(operationRemoved(UMLClassifierListItem*))); QListViewItem *opsFolder = new KListViewItem( classifierItem, i18n("Operations"), "operations" ); opsFolder->setPixmap(0,SmallIcon("folder_blue_open")); opsFolder->setExpandable( true ); UMLOperationList ops(classifier->getOpList()); for( UMLOperation *op = ops.first(); op ; op = ops.next() ) { operationAdded( op ); } //if add parents if(addSuper) { QListViewItem *superFolder = new KListViewItem( classifierItem, i18n("Base Classifiers") ); superFolder->setExpandable( true ); UMLClassifierList super = classifier->findSuperClassConcepts(); for( UMLClassifier *cl = super.first(); cl ; cl = super.next() ) { item = new KListViewItem( superFolder, cl->getName() ); item->setPixmap(0,m_pixmaps.Generalization); item->setExpandable( true ); m_umlObjectMap[item] = cl; if( recurse ) { addClassifier( cl, item, true, false, true); } } } if(addSub) { //add derived classifiers QListViewItem *derivedFolder = new KListViewItem( classifierItem, i18n("Derived Classifiers") ); derivedFolder->setExpandable( true ); UMLClassifierList derived = classifier->findSubClassConcepts(); for( UMLClassifier *d = derived.first(); d ; d = derived.next() ) { item = new KListViewItem( derivedFolder, d->getName() ); item->setPixmap(0,m_pixmaps.Subclass); item->setExpandable( true ); m_umlObjectMap[item] = d; if( recurse ) { addClassifier( d, item, false, true, true); } } } }