// we basically want to update the body of this method void CPPSourceCodeAccessorMethod::updateContent( ) { CodeClassField * parentField = getParentClassField(); CPPCodeClassField * cppfield = dynamic_cast<CPPCodeClassField*>(parentField); CodeGenPolicyExt *pe = UMLApp::app()->getPolicyExt(); CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe); bool isInlineMethod = policy->getAccessorsAreInline( ); QString variableName = cppfield->getFieldName(); QString itemClassName = cppfield->getTypeName(); QString text; if(isInlineMethod) { switch(getType()) { case CodeAccessorMethod::ADD: text = policy->getVectorMethodAppend(variableName, itemClassName); break; case CodeAccessorMethod::REMOVE: text = policy->getVectorMethodRemove(variableName, itemClassName); break; case CodeAccessorMethod::SET: text = variableName+" = value;"; break; case CodeAccessorMethod::LIST: case CodeAccessorMethod::GET: default: text = "return "+variableName+';'; break; } } setText(text); }
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(); }
void JavaCodeAccessorMethod::updateContent( ) { CodeClassField * parentField = getParentClassField(); JavaCodeClassField * javafield = dynamic_cast<JavaCodeClassField*>(parentField); QString fieldName = javafield->getFieldName(); QString text = ""; switch(getType()) { case CodeAccessorMethod::ADD: { int maxOccurs = javafield->maximumListOccurances(); QString fieldType = javafield->getTypeName(); QString indent = getIndentation(); QString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars(); if(maxOccurs > 0) text += "if ("+fieldName+".size() < "+ QString::number(maxOccurs)+") {"+endLine+indent; text += fieldName+".add(value);"; if(maxOccurs > 0) { text += endLine+"} else {"+endLine; text += indent + "System.err.println(\"ERROR: Cant add"+fieldType+" to "+fieldName+", minimum number of items reached.\");"+endLine+'}'+endLine; } break; } case CodeAccessorMethod::GET: text = "return "+fieldName+';'; break; case CodeAccessorMethod::LIST: text = "return (List) "+fieldName+';'; break; case CodeAccessorMethod::REMOVE: { int minOccurs = javafield->minimumListOccurances(); QString fieldType = javafield->getTypeName(); QString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars(); QString indent = getIndentation(); if(minOccurs > 0) text += "if ("+fieldName+".size() >= "+ QString::number(minOccurs)+") {"+endLine+indent; text += fieldName+".remove(value);"; if(minOccurs > 0) { text += endLine+"} else {"+endLine; text += indent + "System.err.println(\"ERROR: Cant remove"+fieldType+" from "+fieldName+", minimum number of items reached.\");"+endLine+'}'+endLine; } break; } case CodeAccessorMethod::SET: text = fieldName+" = value;"; break; default: // do nothing break; } setText(text); }
void RubyCodeAccessorMethod::updateContent( ) { CodeClassField * parentField = getParentClassField(); RubyCodeClassField * rubyfield = dynamic_cast<RubyCodeClassField*>(parentField); QString fieldName = rubyfield->getFieldName(); QString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars(); QString text = ""; switch(getType()) { case CodeAccessorMethod::ADD: { int maxOccurs = rubyfield->maximumListOccurances(); QString fieldType = rubyfield->getTypeName(); QString indent = getIndentation(); if(maxOccurs > 0) text += "if "+fieldName+".size() < "+ QString::number(maxOccurs)+' '+endLine+indent; text += fieldName+".push(value)"; if(maxOccurs > 0) { text += endLine+"else"+endLine; text += indent + "puts(\"ERROR: Can't add"+fieldType+" to "+fieldName+", minimum number of items reached.\")"+endLine+"end"+endLine; } break; } case CodeAccessorMethod::GET: // text = "return "+fieldName; break; case CodeAccessorMethod::LIST: text = "return "+fieldName; break; case CodeAccessorMethod::REMOVE: { int minOccurs = rubyfield->minimumListOccurances(); RubyClassifierCodeDocument * rubydoc = dynamic_cast<RubyClassifierCodeDocument*>(rubyfield->getParentDocument()); QString fieldType = rubyfield->getTypeName(); QString indent = getIndentation(); if(minOccurs > 0) text += "if "+fieldName+".size() >= "+ QString::number(minOccurs)+endLine+indent; text += fieldName+".delete(value)"; if(minOccurs > 0) { text += endLine+"else"+endLine; text += indent + "puts(\"ERROR: Cant remove"+fieldType+" from "+fieldName+", minimum number of items reached.\")"+endLine+"end"+endLine; } break; } case CodeAccessorMethod::SET: // text = fieldName+" = value"; break; default: // do nothing break; } setText(text); }
void DCodeAccessorMethod::updateContent() { CodeClassField * parentField = getParentClassField(); DCodeClassField * dfield = dynamic_cast<DCodeClassField*>(parentField); QString fieldName = dfield->getFieldName(); QString text; switch(getType()) { case CodeAccessorMethod::ADD: { int maxOccurs = dfield->maximumListOccurances(); QString fieldType = dfield->getTypeName(); QString indent = getIndentation(); QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars(); if(maxOccurs > 0) text += QLatin1String("if (") + fieldName + QLatin1String(".size() < ")+ QString::number(maxOccurs) + QLatin1String(") {") + endLine + indent; text += fieldName + QLatin1String(".add(value);"); if(maxOccurs > 0) { text += endLine + QLatin1String("} else {") + endLine; text += indent + QLatin1String("System.err.println(\"ERROR: Cant add") + fieldType + QLatin1String(" to ") + fieldName + QLatin1String(", minimum number of items reached.\");") + endLine + QLatin1Char('}') + endLine; } break; } case CodeAccessorMethod::GET: text = QLatin1String("return ") + fieldName + QLatin1Char(';'); break; case CodeAccessorMethod::LIST: text = QLatin1String("return (List) ") + fieldName + QLatin1Char(';'); break; case CodeAccessorMethod::REMOVE: { int minOccurs = dfield->minimumListOccurances(); QString fieldType = dfield->getTypeName(); QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars(); QString indent = getIndentation(); if(minOccurs > 0) text += QLatin1String("if (") + fieldName + QLatin1String(".size() >= ")+ QString::number(minOccurs) + QLatin1String(") {") + endLine + indent; text += fieldName + QLatin1String(".remove(value);"); if(minOccurs > 0) { text += endLine + QLatin1String("} else {") + endLine; text += indent + QLatin1String("System.err.println(\"ERROR: Cant remove") + fieldType + QLatin1String(" from ") + fieldName + QLatin1String(", minimum number of items reached.\");") + endLine + QLatin1Char('}') + endLine; } break; } case CodeAccessorMethod::SET: text = fieldName + QLatin1String(" = value;"); break; default: // do nothing break; } setText(text); }
// we basically want to update the body of this method void CPPSourceCodeAccessorMethod::updateContent() { CodeClassField * parentField = getParentClassField(); CPPCodeClassField * cppfield = dynamic_cast<CPPCodeClassField*>(parentField); // Check for dynamic casting failure! if(cppfield == NULL) { uError() << "cppfield: invalid dynamic cast"; return; } 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; } bool isInlineMethod = policy->getAccessorsAreInline(); QString variableName = cppfield->getFieldName(); QString itemClassName = cppfield->getTypeName(); QString text; if(isInlineMethod) { switch(getType()) { case CodeAccessorMethod::ADD: text = policy->getVectorMethodAppend(variableName, itemClassName); break; case CodeAccessorMethod::REMOVE: text = policy->getVectorMethodRemove(variableName, itemClassName); break; case CodeAccessorMethod::SET: text = variableName + QLatin1String(" = value;"); break; case CodeAccessorMethod::LIST: case CodeAccessorMethod::GET: default: text = QLatin1String("return ") + variableName + QLatin1Char(';'); break; } } setText(text); }
void CPPHeaderCodeClassFieldDeclarationBlock::updateContent() { UMLObject *umlparent = CodeClassFieldDeclarationBlock::getParentObject(); if (umlparent == NULL) { return; } CodeClassField * cf = getParentClassField(); CPPCodeClassField * hcppcf = dynamic_cast<CPPCodeClassField*>(cf); // Check for dynamic casting failure! if (hcppcf == NULL) { uError() << "hcppcf: invalid dynamic cast"; return; } // Set the comment QString notes = umlparent->doc(); getComment()->setText(notes); if (notes.isEmpty()) getComment()->setWriteOutText(false); else getComment()->setWriteOutText(true); // Set the body QString staticValue = umlparent->isStatic() ? QLatin1String("static ") : QString(); QString typeName = hcppcf->getTypeName(); QString fieldName = hcppcf->getFieldName(); // Ugh. Sloppy exception. if (!cf->parentIsAttribute() && !cf->fieldIsSingleValue()) typeName = hcppcf->getListFieldClassName(); QString body = staticValue + QLatin1Char(' ') + typeName + QLatin1Char(' ') + fieldName + QLatin1Char(';'); setText(body); }
// 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); }
void DCodeAccessorMethod::updateMethodDeclaration() { DCodeClassField * dfield = dynamic_cast<DCodeClassField*>(getParentClassField()); // Check for dynamic casting failure! if (dfield == 0) { uError() << "dfield: invalid dynamic cast"; return; } CodeGenerationPolicy *commonpolicy = UMLApp::app()->commonPolicy(); // gather defs Uml::Visibility::Enum scopePolicy = commonpolicy->getAttributeAccessorScope(); QString strVis = Uml::Visibility::toString(dfield->getVisibility()); QString fieldName = dfield->getFieldName(); QString fieldType = dfield->getTypeName(); QString objectType = dfield->getListObjectType(); if(objectType.isEmpty()) objectType = fieldName; QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars(); // set scope of this accessor appropriately..if its an attribute, // we need to be more sophisticated if (dfield->parentIsAttribute()) { switch (scopePolicy) { case Uml::Visibility::Public: case Uml::Visibility::Private: case Uml::Visibility::Protected: strVis = Uml::Visibility::toString(scopePolicy); break; default: case Uml::Visibility::FromParent: // do nothing..already have taken parent value break; } } // some variables we will need to populate QString headerText; QString methodReturnType; QString methodName; QString methodParams; switch(getType()) { case CodeAccessorMethod::ADD: methodName = QLatin1String("add") + Codegen_Utils::capitalizeFirstLetter(fieldType); methodReturnType = QLatin1String("void"); methodParams = objectType + QLatin1String(" value "); headerText = QLatin1String("Add an object of type ") + objectType + QLatin1String(" to the List ") + fieldName + endLine + getParentObject()->doc() + endLine + QLatin1String("@return void"); break; case CodeAccessorMethod::GET: methodName = QLatin1String("get") + Codegen_Utils::capitalizeFirstLetter(fieldName); methodReturnType = fieldType; headerText = QLatin1String("Get the value of ") + fieldName + endLine + getParentObject()->doc() + endLine + QLatin1String("@return the value of ") + fieldName; break; case CodeAccessorMethod::LIST: methodName = QLatin1String("get") + Codegen_Utils::capitalizeFirstLetter(fieldType) + QLatin1String("List"); methodReturnType = QLatin1String("List"); headerText = QLatin1String("Get the list of ") + fieldName + endLine + getParentObject()->doc() + endLine + QLatin1String("@return List of ") + fieldName; break; case CodeAccessorMethod::REMOVE: methodName = QLatin1String("remove") + Codegen_Utils::capitalizeFirstLetter(fieldType); methodReturnType = QLatin1String("void"); methodParams = objectType + QLatin1String(" value "); headerText = QLatin1String("Remove an object of type ") + objectType + QLatin1String(" from the List ") + fieldName + endLine + getParentObject()->doc(); break; case CodeAccessorMethod::SET: methodName = QLatin1String("set") + Codegen_Utils::capitalizeFirstLetter(fieldName); methodReturnType = QLatin1String("void"); methodParams = fieldType + QLatin1String(" value "); headerText = QLatin1String("Set the value of ") + fieldName + endLine + getParentObject()->doc() + endLine; break; default: // do nothing..no idea what this is uWarning()<<"Warning: cant generate DCodeAccessorMethod for type: "<<getType(); break; } // set header once. if(getComment()->getText().isEmpty()) getComment()->setText(headerText); // set start/end method text setStartMethodText(strVis + QLatin1Char(' ') + methodReturnType + QLatin1Char(' ') + methodName + QLatin1String(" (") + methodParams + QLatin1String(") {")); setEndMethodText(QLatin1String("}")); }
// 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 start text of this method void CPPHeaderCodeAccessorMethod::updateMethodDeclaration() { CodeClassField * parentField = getParentClassField(); ClassifierCodeDocument * doc = parentField->getParentDocument(); CodeGenPolicyExt *pe = UMLApp::app()->policyExt(); CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe); CPPCodeClassField * cppfield = dynamic_cast<CPPCodeClassField*>(parentField); 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 = "void"; QString methodName; // "get"+cppdoc->capitalizeFirstLetter(fieldName); QString methodParams = QChar(' '); // "get"+cppdoc->capitalizeFirstLetter(fieldName); QString headerText; QString endLine = UMLApp::app()->commonPolicy()->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()->doc()+endLine+tag+"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()->doc()+endLine+tag+"return void"; break; case CodeAccessorMethod::LIST: methodName = "get_"+fieldType+"_list"; methodReturnType = vectorClassName; headerText = "Get the "+fieldName+"List"+endLine+getParentObject()->doc()+endLine+tag+"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()->doc()+endLine+tag+"param value the value of "+fieldName; break; case CodeAccessorMethod::GET: default: methodName = "get_"+fieldName; methodReturnType = fieldType; headerText = "Get the value of "+fieldName+endLine+getParentObject()->doc()+endLine+tag+"return the value of "+fieldName; break; } // set header CPPCodeDocumentation * header = new CPPCodeDocumentation(doc); if(!getParentObject()->doc().isEmpty()) header->setText(headerText); setComment(header); // set start/end method text QString startText = methodReturnType + ' ' + methodName + " (" + methodParams +')'; if (isInlineMethod) startText += " {"; else startText += ';'; QString endText = (isInlineMethod ? "}" : ""); setStartMethodText(startText); setEndMethodText(endText); setOverallIndentationLevel(1); }
void RubyCodeClassFieldDeclarationBlock::updateContent( ) { CodeClassField * cf = getParentClassField(); ClassifierCodeDocument * doc = cf->getParentDocument(); RubyCodeClassField * rcf = dynamic_cast<RubyCodeClassField*>(cf); RubyClassifierCodeDocument* rdoc = dynamic_cast<RubyClassifierCodeDocument*>(doc); CodeGenerationPolicy * p = UMLApp::app()->getCommonPolicy(); CodeGenerationPolicy::ScopePolicy scopePolicy = p->getAssociationFieldScope(); // Set the comment QString notes = getParentObject()->getDoc(); getComment()->setText(notes); // Set the body QString staticValue = getParentObject()->getStatic() ? "static " : ""; QString scopeStr = rdoc->scopeToRubyDecl(getParentObject()->getVisibility()); // IF this is from an association, then scope taken as appropriate to policy if(!rcf->parentIsAttribute()) { switch (scopePolicy) { case CodeGenerationPolicy::Public: case CodeGenerationPolicy::Private: case CodeGenerationPolicy::Protected: scopeStr = rdoc->scopeToRubyDecl((Uml::Visibility::Value) scopePolicy); break; default: case CodeGenerationPolicy::FromParent: // do nothing here... will leave as from parent object break; } } QString typeName = rcf->getTypeName(); QString fieldName = rcf->getFieldName(); QString initialV = rcf->getInitialValue(); if (!cf->parentIsAttribute() && !cf->fieldIsSingleValue()) typeName = "Array"; QString body = staticValue+scopeStr+' '+typeName+' '+fieldName; if (!initialV.isEmpty()) body.append(" = " + initialV); else if (!cf->parentIsAttribute()) { UMLRole * role = dynamic_cast<UMLRole*>(cf->getParentObject()); if (role->getObject()->getBaseType() == Uml::ot_Interface) { // do nothing.. can't instanciate an interface } else { // FIX?: IF a constructor method exists in the classifiercodedoc // of the parent Object, then we can use that instead (if its empty). if(cf->fieldIsSingleValue()) { if(!typeName.isEmpty()) body.append(" = " + typeName + ".new()"); } else body.append(" = []"); } } setText(body); }
void JavaCodeAccessorMethod::updateMethodDeclaration() { JavaCodeClassField * javafield = dynamic_cast<JavaCodeClassField*>(getParentClassField()); JavaClassifierCodeDocument * javadoc = dynamic_cast<JavaClassifierCodeDocument*>(javafield->getParentDocument()); CodeGenerationPolicy *commonpolicy = UMLApp::app()->getCommonPolicy(); // gather defs CodeGenerationPolicy::ScopePolicy scopePolicy = commonpolicy->getAttributeAccessorScope(); QString strVis = javadoc->scopeToJavaDecl(javafield->getVisibility()); QString fieldName = javafield->getFieldName(); QString fieldType = javafield->getTypeName(); QString objectType = javafield->getListObjectType(); if(objectType.isEmpty()) objectType = fieldName; QString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars(); // set scope of this accessor appropriately..if its an attribute, // we need to be more sophisticated if(javafield->parentIsAttribute()) switch (scopePolicy) { case CodeGenerationPolicy::Public: case CodeGenerationPolicy::Private: case CodeGenerationPolicy::Protected: strVis = javadoc->scopeToJavaDecl((Uml::Visibility::Value) scopePolicy); break; default: case CodeGenerationPolicy::FromParent: // do nothing..already have taken parent value break; } // some variables we will need to populate QString headerText = ""; QString methodReturnType = ""; QString methodName = ""; QString methodParams = ""; switch(getType()) { case CodeAccessorMethod::ADD: methodName = "add" + Codegen_Utils::capitalizeFirstLetter(fieldType); methodReturnType = "void"; methodParams = objectType+" value "; headerText = "Add an object of type "+objectType+" to the List "+fieldName+endLine+getParentObject()->getDoc()+endLine+"@return void"; break; case CodeAccessorMethod::GET: methodName = "get" + Codegen_Utils::capitalizeFirstLetter(fieldName); methodReturnType = fieldType; headerText = "Get the value of "+fieldName+endLine+getParentObject()->getDoc()+endLine+"@return the value of "+fieldName; break; case CodeAccessorMethod::LIST: methodName = "get" + Codegen_Utils::capitalizeFirstLetter(fieldType)+"List"; methodReturnType = "List"; headerText = "Get the list of "+fieldName+endLine+getParentObject()->getDoc()+endLine+"@return List of "+fieldName; break; case CodeAccessorMethod::REMOVE: methodName = "remove" + Codegen_Utils::capitalizeFirstLetter(fieldType); methodReturnType = "void"; methodParams = objectType+" value "; headerText = "Remove an object of type "+objectType+" from the List "+fieldName+endLine+getParentObject()->getDoc(); break; case CodeAccessorMethod::SET: methodName = "set" + Codegen_Utils::capitalizeFirstLetter(fieldName); methodReturnType = "void"; methodParams = fieldType + " value "; headerText = "Set the value of "+fieldName+endLine+getParentObject()->getDoc()+endLine; break; default: // do nothing..no idea what this is kWarning()<<"Warning: cant generate JavaCodeAccessorMethod for type: "<<getType()<<endl; break; } // set header once. if(getComment()->getText().isEmpty()) getComment()->setText(headerText); // set start/end method text setStartMethodText(strVis+' '+methodReturnType+' '+methodName+" ( "+methodParams+" ) {"); setEndMethodText("}"); }
void RubyCodeAccessorMethod::updateMethodDeclaration() { RubyCodeClassField * rubyfield = dynamic_cast<RubyCodeClassField*>(getParentClassField()); RubyClassifierCodeDocument * rubydoc = dynamic_cast<RubyClassifierCodeDocument*>(rubyfield->getParentDocument()); // gather defs CodeGenerationPolicy *p = UMLApp::app()->getCommonPolicy(); CodeGenerationPolicy::ScopePolicy scopePolicy = p->getAttributeAccessorScope(); QString strVis = rubydoc->scopeToRubyDecl(rubyfield->getVisibility()); QString fieldName = RubyCodeGenerator::cppToRubyName(rubyfield->getFieldName()); QString fieldType = RubyCodeGenerator::cppToRubyType(rubyfield->getTypeName()); QString objectType = rubyfield->getListObjectType(); if(objectType.isEmpty()) objectType = fieldName; QString endLine = p->getNewLineEndingChars(); QString description = getParentObject()->getDoc(); description.replace(QRegExp("m_[npb](?=[A-Z])"), ""); description.replace("m_", ""); description.replace(QRegExp("[\\n\\r]+[\\t ]*"), endLine); // set scope of this accessor appropriately..if its an attribute, // we need to be more sophisticated if(rubyfield->parentIsAttribute()) switch (scopePolicy) { case CodeGenerationPolicy::Public: case CodeGenerationPolicy::Private: case CodeGenerationPolicy::Protected: strVis = rubydoc->scopeToRubyDecl((Uml::Visibility::Value) scopePolicy); break; default: case CodeGenerationPolicy::FromParent: // do nothing..already have taken parent value break; } // some variables we will need to populate QString headerText = ""; QString methodReturnType = ""; QString methodName = ""; QString methodParams = ""; switch(getType()) { case CodeAccessorMethod::ADD: methodName = "add" + Codegen_Utils::capitalizeFirstLetter(fieldType); methodReturnType = ""; methodParams = objectType+" value "; headerText = "Add an object of type "+objectType+" to the Array "+fieldName+endLine+description+endLine+"@return nil"; setStartMethodText("def "+ methodName + '(' + methodParams + ')'); setEndMethodText("end"); break; case CodeAccessorMethod::GET: headerText = "Get the value of " + fieldName + endLine + description; setStartMethodText(QString("attr_reader :") + fieldName); setEndMethodText(""); break; case CodeAccessorMethod::LIST: methodName = "get" + Codegen_Utils::capitalizeFirstLetter(fieldType)+"List"; methodReturnType = ""; headerText = "Get the list of "+fieldName+endLine+description+endLine+"_returns_ List of "+fieldName; setStartMethodText("def "+ methodName + '(' + methodParams + ')'); setEndMethodText("end"); break; case CodeAccessorMethod::REMOVE: methodName = "remove" + Codegen_Utils::capitalizeFirstLetter(fieldType); methodReturnType = ""; methodParams = objectType+" value "; headerText = "Remove an object of type "+objectType+" from the List "+fieldName+endLine+description; setStartMethodText("def "+ methodName + '(' + methodParams + ')'); setEndMethodText("end"); break; case CodeAccessorMethod::SET: headerText = "Set the value of " + fieldName + endLine + description; setStartMethodText(QString("attr_writer :") + fieldName); setEndMethodText(""); break; default: // do nothing..no idea what this is kWarning()<<"Warning: can't generate RubyCodeAccessorMethod for type: "<<getType()<<endl; break; } // set header once. if (getComment()->getText().isEmpty()) getComment()->setText(headerText); }
/** * This will be called by syncToParent whenever the parent object is "modified". */ void DCodeClassFieldDeclarationBlock::updateContent() { CodeClassField * cf = getParentClassField(); DCodeClassField * jcf = dynamic_cast<DCodeClassField*>(cf); if (!jcf) { uError() << "jcf: invalid dynamic cast"; return; } CodeGenerationPolicy * commonpolicy = UMLApp::app()->commonPolicy(); Uml::Visibility::Enum scopePolicy = commonpolicy->getAssociationFieldScope(); // Set the comment QString notes = getParentObject()->doc(); getComment()->setText(notes); // Set the body QString staticValue = getParentObject()->isStatic() ? QLatin1String("static ") : QString(); QString scopeStr = Uml::Visibility::toString(getParentObject()->visibility()); // IF this is from an association, then scope taken as appropriate to policy if (!jcf->parentIsAttribute()) { switch (scopePolicy) { case Uml::Visibility::Public: case Uml::Visibility::Private: case Uml::Visibility::Protected: scopeStr = Uml::Visibility::toString(scopePolicy); break; default: case Uml::Visibility::FromParent: // do nothing here... will leave as from parent object break; } } QString typeName = jcf->getTypeName(); QString fieldName = jcf->getFieldName(); QString initialV = jcf->getInitialValue(); if (!cf->parentIsAttribute() && !cf->fieldIsSingleValue()) typeName = QLatin1String("List"); QString body = staticValue + scopeStr + QLatin1Char(' ') + typeName + QLatin1Char(' ') + fieldName; if (!initialV.isEmpty()) body.append(QLatin1String(" = ") + initialV); else if (!cf->parentIsAttribute()) { UMLRole * role = dynamic_cast<UMLRole*>(cf->getParentObject()); // Check for dynamic casting failure! if (role == NULL) { uError() << "role: invalid dynamic cast"; return; } if (role->object()->baseType() == UMLObject::ot_Interface) { // do nothing.. can't instantiate an interface } else { // FIX?: IF a constructor method exists in the classifiercodedoc // of the parent Object, then we can use that instead (if its empty). if(cf->fieldIsSingleValue()) { if(!typeName.isEmpty()) body.append(QLatin1String(" = new ") + typeName + QLatin1String(" ()")); } else body.append(QLatin1String(" = new Vector ()")); } } setText(body + QLatin1Char(';')); }