cppsourcecodeoperation.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "cppsourcecodeoperation.h"
00018
00019 #include "cppcodegenerator.h"
00020 #include "cppcodegenerationpolicy.h"
00021 #include "cppsourcecodedocument.h"
00022 #include "cppcodedocumentation.h"
00023 #include "../uml.h"
00024
00025
00026
00027
00028 CPPSourceCodeOperation::CPPSourceCodeOperation ( CPPSourceCodeDocument * doc, UMLOperation *parent, const QString & body, const QString & comment )
00029 : CodeOperation (doc, parent, body, comment)
00030 {
00031
00032
00033 setComment(new CPPCodeDocumentation(doc));
00034
00035
00036 setOverallIndentationLevel(0);
00037 setEndMethodText("}");
00038
00039
00040 CodeGenPolicyExt * pe = UMLApp::app()->getPolicyExt();
00041 CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
00042 UMLClassifier * c = doc->getParentClassifier();
00043 UMLOperation * o = getParentOperation();
00044 bool isInterface = doc->parentIsInterface();
00045 bool isInlineMethod = policy->getOperationsAreInline( );
00046
00047
00048 QString cmnt = o->getDoc();
00049 getComment()->setText(cmnt);
00050
00051 QString returnType = o->getTypeName();
00052 QString methodName = o->getName();
00053 QString paramStr = QString("");
00054 QString className = CodeGenerator::cleanName(c->getName());
00055
00056
00057 UMLAttributeList list = getParentOperation()->getParmList();
00058 int nrofParam = list.count();
00059 int paramNum = 0;
00060 for(UMLAttribute* parm = list.first(); parm; parm=list.next())
00061 {
00062 QString rType = parm->getTypeName();
00063 QString paramName = parm->getName();
00064 paramStr += rType + ' ' + paramName;
00065 paramNum++;
00066
00067 if (paramNum != nrofParam )
00068 paramStr += ", ";
00069 }
00070
00071
00072 if (o->isLifeOperation())
00073 returnType = "";
00074
00075
00076 else if (returnType.isEmpty())
00077 returnType = QString("void");
00078
00079 QString startText = returnType + ' ';
00080
00081
00082
00083 if (o->getStereotype() != "friend")
00084 startText += className + "::";
00085 startText += methodName + " (" + paramStr + ')';
00086 if (o->getConst())
00087 startText += " const";
00088 startText += " {";
00089
00090 setStartMethodText(startText);
00091
00092 // Only write this out if its a child of an interface OR is abstract.
00093 // and its not inline
00094 if(isInterface || o->getAbstract() || isInlineMethod)
00095 {
00096 setWriteOutText(false);
00097 } else {
00098 setWriteOutText(true);
00099 }
00100
00101
00102 updateContent();
00103 }
00104
00105 CPPSourceCodeOperation::~CPPSourceCodeOperation ( ) { }
00106
00107 // Other methods
00108 //
00109
00110 // we basically just want to know whether or not to print out
00111 // the body of the operation.
00112 // In C++ if the operations are inline, then we DONT print out
00113 // the body text.
00114 void CPPSourceCodeOperation::updateContent( )
00115 {
00116 CodeGenPolicyExt *pe = UMLApp::app()->getPolicyExt();
00117 CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
00118 bool isInlineMethod = policy->getOperationsAreInline();
00119
00120 if(!isInlineMethod)
00121 setText(""); // change whatever it is to "";
00122
00123 }
00124
00125 // we basically want to update the doc and start text of this method
00126 void CPPSourceCodeOperation::updateMethodDeclaration()
00127 {
00128
00129 CPPSourceCodeDocument * doc = dynamic_cast<CPPSourceCodeDocument*>(getParentDocument());
00130 CodeGenPolicyExt *pe = UMLApp::app()->getPolicyExt();
00131 CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
00132 UMLClassifier * c = doc->getParentClassifier();
00133 UMLOperation * o = getParentOperation();
00134 bool isInterface = doc->parentIsInterface();
00135 bool isInlineMethod = policy->getOperationsAreInline( );
00136
00137 // first, the comment on the operation
00138 QString comment = o->getDoc();
00139 getComment()->setText(comment);
00140
00141 QString returnType = o->getTypeName();
00142 QString methodName = o->getName();
00143 QString paramStr = QString("");
00144 QString className = CodeGenerator::cleanName(c->getName());
00145
00146 // assemble parameters
00147 UMLAttributeList list = getParentOperation()->getParmList();
00148 int nrofParam = list.count();
00149 int paramNum = 0;
00150 for(UMLAttribute* parm = list.first(); parm; parm=list.next())
00151 {
00152 QString rType = parm->getTypeName();
00153 QString paramName = parm->getName();
00154 paramStr += rType + ' ' + paramName;
00155 paramNum++;
00156
00157 if (paramNum != nrofParam )
00158 paramStr += ", ";
00159 }
00160
00161 // no return type for constructors/destructors
00162 if (o->isLifeOperation())
00163 returnType = "";
00164 // if an operation isn't a constructor/destructor and it has no return type
00165 // this operation should be void
00166 else if (returnType.isEmpty())
00167 returnType = QString("void");
00168
00169 QString startText = returnType + ' ';
00170
00171 // if a property has a friend stereotype, the operation should
00172 // not be a class name
00173 if (o->getStereotype() != "friend")
00174 startText += className + "::";
00175 startText += methodName + " (" + paramStr + ')';
00176 if (o->getConst())
00177 startText += " const";
00178 startText += " {";
00179
00180 setStartMethodText(startText);
00181
00182 // Only write this out if its a child of an interface OR is abstract.
00183 // and its not inline
00184 if(isInterface || o->getAbstract() || isInlineMethod)
00185 {
00186 setWriteOutText(false);
00187 } else {
00188 setWriteOutText(true);
00189 }
00190
00191 }
00192
00193 #include "cppsourcecodeoperation.moc"
This file is part of the documentation for umbrello Version 3.1.0.