void CodeClassFieldDeclarationBlock::syncToParent () { // for role-based accessors, we DON'T write ourselves out when // the name of the role is not defined. if (!(getParentClassField()->parentIsAttribute())) { UMLRole * parent = getParentObject()->asUMLRole(); if (parent == 0) return; if (parent->name().isEmpty()) { getComment()->setWriteOutText(false); setWriteOutText(false); } else { getComment()->setWriteOutText(true); setWriteOutText(true); } } // only update IF we are NOT AutoGenerated if (contentType() != AutoGenerated) return; updateContent(); }
/** * Set the class attributes from a passed object. * @param obj text block from which the attributes are taken */ void TextBlock::setAttributesFromObject(TextBlock * obj) { // DON'T set tag here. setIndentationLevel(obj->getIndentationLevel()); setText(obj->getText()); setWriteOutText(obj->getWriteOutText()); m_canDelete = obj->canDelete(); }
/** * Set the class attributes of this object from * the passed element node. * @param root the xmi element from which to load */ void TextBlock::setAttributesFromNode(QDomElement & root) { QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars(); setIndentationLevel(root.attribute("indentLevel", "0").toInt()); setTag(root.attribute("tag", "")); setText(decodeText(root.attribute("text", ""), endLine)); setWriteOutText(root.attribute("writeOutText", "true") == "true" ? true : false); m_canDelete = root.attribute("canDelete", "true") == "true" ? true : false; }
/** * Set the class attributes of this object from * the passed element node. * @param root the xmi element from which to load */ void TextBlock::setAttributesFromNode(QDomElement & root) { QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars(); setIndentationLevel(root.attribute(QLatin1String("indentLevel"), QLatin1String("0")).toInt()); setTag(root.attribute(QLatin1String("tag"))); setText(decodeText(root.attribute(QLatin1String("text")), endLine)); const QString trueStr = QLatin1String("true"); setWriteOutText(root.attribute(QLatin1String("writeOutText"), trueStr) == trueStr); m_canDelete = root.attribute(QLatin1String("canDelete"), trueStr) == trueStr; }
// we basically want to update the start text of this method void CPPSourceCodeAccessorMethod::updateMethodDeclaration() { CodeClassField * parentField = getParentClassField(); ClassifierCodeDocument * doc = parentField->getParentDocument(); CodeGenPolicyExt *pe = UMLApp::app()->policyExt(); CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe); // Check for dynamic casting failure! if (policy == NULL) { uError() << "policy: invalid dynamic cast"; return; } CPPCodeClassField * cppfield = dynamic_cast<CPPCodeClassField*>(parentField); // Check for dynamic casting failure! if (cppfield == NULL) { uError() << "cppfield: invalid dynamic cast"; return; } UMLClassifier * c = doc->getParentClassifier(); bool isInlineMethod = policy->getAccessorsAreInline(); QString tag = policy->getDocToolTag(); QString vectorClassName = policy->getVectorClassName(); QString fieldName = cppfield->getFieldName(); QString fieldType = cppfield->getTypeName(); QString objectType = cppfield->getListObjectType(); if(objectType.isEmpty()) objectType = fieldName; QString methodReturnType(QLatin1String("void")); QString methodName; // QLatin1String("get") + cppdoc->capitalizeFirstLetter(fieldName); QString methodParams = QChar(QLatin1Char(' ')); // QLatin1String("get") + cppdoc->capitalizeFirstLetter(fieldName); QString headerText; QString className = CodeGenerator::cleanName(c->name()); QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars(); switch(getType()) { case CodeAccessorMethod::ADD: methodName = QLatin1String("add_") + fieldType; methodReturnType = QLatin1String("void"); methodParams = objectType + QLatin1String(" value "); headerText = QLatin1String("Add a ") + fieldName + QLatin1String(" object to the ") + fieldName + QLatin1String("List") + endLine + getParentObject()->doc() + endLine + tag + QLatin1String("return void"); break; case CodeAccessorMethod::REMOVE: methodName = QLatin1String("remove_") + fieldType; methodParams = objectType + QLatin1String(" value "); methodReturnType = QLatin1String("void"); headerText = QLatin1String("Remove a ") + fieldName + QLatin1String(" object from the ") + fieldName + QLatin1String("List") + endLine + getParentObject()->doc() + endLine + tag + QLatin1String("return void"); break; case CodeAccessorMethod::LIST: methodName = QLatin1String("get_") + fieldType + QLatin1String("_list"); methodReturnType = vectorClassName; headerText = QLatin1String("Get the ") + fieldName + QLatin1String("List") + endLine + getParentObject()->doc() + endLine + tag + QLatin1String("return ") + vectorClassName + QLatin1String("with list of objects"); break; case CodeAccessorMethod::SET: methodName = QLatin1String("set_") + fieldName; methodParams = fieldType + QLatin1String(" value "); methodReturnType = QLatin1String("void"); headerText = QLatin1String("Set the value of ") + fieldName + endLine + getParentObject()->doc() + endLine + tag + QLatin1String("param value the value of ") + fieldName; break; case CodeAccessorMethod::GET: default: methodName = QLatin1String("get_") + fieldName; methodReturnType = fieldType; headerText = QLatin1String("Get the value of ") + fieldName + endLine + getParentObject()->doc() + endLine + tag + QLatin1String("return the value of ") + fieldName; break; } // set header CPPCodeDocumentation * header = new CPPCodeDocumentation(doc); if(!getParentObject()->doc().isEmpty()) header->setText(headerText); setComment(header); // set start method text (EndText never changes) setStartMethodText(methodReturnType + QLatin1Char(' ') + className + QLatin1String("::") + methodName + QLatin1String(" (") + methodParams + QLatin1Char(')') + QLatin1String(" {")); setOverallIndentationLevel(0); // these ONLY appear if they arent inline if(isInlineMethod) setWriteOutText(false); }
// we basically want to update the start text of this method void CPPSourceCodeAccessorMethod::updateMethodDeclaration() { CodeClassField * parentField = getParentClassField(); ClassifierCodeDocument * doc = parentField->getParentDocument(); CodeGenPolicyExt *pe = UMLApp::app()->getPolicyExt(); CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe); CPPCodeClassField * cppfield = dynamic_cast<CPPCodeClassField*>(parentField); UMLClassifier * c = doc->getParentClassifier(); bool isInlineMethod = policy->getAccessorsAreInline( ); QString vectorClassName = policy->getVectorClassName(); QString fieldName = cppfield->getFieldName(); QString fieldType = cppfield->getTypeName(); QString objectType = cppfield->getListObjectType(); if(objectType.isEmpty()) objectType = fieldName; QString methodReturnType = "void"; QString methodName; QString methodParams; QString headerText; QString className = CodeGenerator::cleanName(c->getName()); QString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars(); switch(getType()) { case CodeAccessorMethod::ADD: methodName = "add_"+fieldType; methodReturnType = "void"; methodParams = objectType+" value "; headerText = "Add a "+fieldName+" object to the "+fieldName+"List"+endLine+getParentObject()->getDoc()+endLine+"@return void"; break; case CodeAccessorMethod::REMOVE: methodName = "remove_"+fieldType; methodParams = objectType+" value "; methodReturnType = "void"; headerText = "Remove a "+fieldName+" object from the "+fieldName+"List"+endLine+getParentObject()->getDoc()+endLine+"@return void"; break; case CodeAccessorMethod::LIST: methodName = "get_"+fieldType+"_list"; methodReturnType = vectorClassName; headerText = "Get the "+fieldName+"List"+endLine+getParentObject()->getDoc()+endLine+"@return "+vectorClassName+"with list of objects"; break; case CodeAccessorMethod::SET: methodName = "set_"+fieldName; methodParams = fieldType+" value "; methodReturnType = "void"; headerText = "Set the value of "+fieldName+endLine+getParentObject()->getDoc()+endLine+"@param value the value of "+fieldName; break; case CodeAccessorMethod::GET: default: methodName = "get_"+fieldName; methodReturnType = fieldType; headerText = "Get the value of "+fieldName+endLine+getParentObject()->getDoc()+endLine+"@return the value of "+fieldName; break; } // set header CPPCodeDocumentation * header = new CPPCodeDocumentation(doc); if(!getParentObject()->getDoc().isEmpty()) header->setText(headerText); setComment(header); // set start method text (EndText never changes) setStartMethodText(methodReturnType+' '+className+"::"+methodName+" ("+methodParams+')' + " {"); setOverallIndentationLevel(0); // these ONLY appear if they arent inline if(isInlineMethod) setWriteOutText(false); }
// 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); } }