cppheadercodeoperation.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "cppheadercodeoperation.h"
00018
00019 #include "cppcodegenerator.h"
00020 #include "cppcodegenerationpolicy.h"
00021 #include "cppheadercodedocument.h"
00022 #include "cppcodedocumentation.h"
00023 #include "../uml.h"
00024
00025
00026
00027
00028 CPPHeaderCodeOperation::CPPHeaderCodeOperation
00029 ( CPPHeaderCodeDocument * doc, UMLOperation *parent, const QString & body, const QString & comment )
00030 : CodeOperation (doc, parent, body, comment)
00031 {
00032
00033
00034 setComment(new CPPCodeDocumentation(doc));
00035
00036
00037 setOverallIndentationLevel(1);
00038
00039 setText("");
00040 setStartMethodText("");
00041 setEndMethodText("");
00042
00043 updateMethodDeclaration();
00044 updateContent();
00045
00046 }
00047
00048 CPPHeaderCodeOperation::~CPPHeaderCodeOperation ( ) { }
00049
00050
00051
00052
00053
00054
00055
00056
00057 void CPPHeaderCodeOperation::updateContent( )
00058 {
00059 CodeGenPolicyExt *pe = UMLApp::app()->getPolicyExt();
00060 CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
00061 bool isInlineMethod = policy->getOperationsAreInline( );
00062
00063 if(isInlineMethod)
00064 setText("");
00065 }
00066
00067
00068 void CPPHeaderCodeOperation::updateMethodDeclaration()
00069 {
00070 ClassifierCodeDocument *ccd = dynamic_cast<ClassifierCodeDocument*>(getParentDocument());
00071 bool isInterface = ccd->parentIsInterface();
00072 UMLOperation * o = getParentOperation();
00073
00074 CodeGenPolicyExt *pe = UMLApp::app()->getPolicyExt();
00075 CPPCodeGenerationPolicy * policy = dynamic_cast<CPPCodeGenerationPolicy*>(pe);
00076 bool isInlineMethod = policy->getOperationsAreInline( );
00077
00078 QString endLine = getNewLineEndingChars();
00079
00080
00081 QString comment = o->getDoc();
00082 if(comment.isEmpty() && getContentType() == CodeBlock::AutoGenerated)
00083 {
00084 UMLAttributeList parameters = o->getParmList();
00085 for(UMLAttributeListIt iterator(parameters); iterator.current(); ++iterator) {
00086 comment += endLine + "@param " + iterator.current()->getName() + ' ';
00087 comment += iterator.current()->getDoc();
00088 }
00089 getComment()->setText(comment);
00090 }
00091
00092
00093 QString methodReturnType = o->getTypeName();
00094 QString methodName = o->getName();
00095 QString paramStr = QString("");
00096
00097
00098 UMLAttributeList list = getParentOperation()->getParmList();
00099 int nrofParam = list.count();
00100 int paramNum = 0;
00101 for(UMLAttribute* parm = list.first(); parm; parm=list.next())
00102 {
00103 QString rType = parm->getTypeName();
00104 QString paramName = parm->getName();
00105 QString initialValue = parm->getInitialValue();
00106 paramStr += rType + ' ' + paramName;
00107 if(!initialValue.isEmpty())
00108 paramStr += '=' + initialValue;
00109
00110 paramNum++;
00111
00112 if (paramNum != nrofParam )
00113 paramStr += ", ";
00114 }
00115
00116
00117 if (o->isLifeOperation())
00118 methodReturnType = "";
00119 else if (methodReturnType.isEmpty())
00120 methodReturnType = QString("void");
00121
00122
00123 QString prototype = methodReturnType+' '+methodName+" ("+paramStr+')';
00124
00125 QString startText;
00126 QString endText;
00127
00128 applyStereotypes (prototype, o, isInlineMethod, isInterface, startText, endText);
00129
00130 setStartMethodText(prototype+startText);
00131 setEndMethodText(endText);
00132 }
00133
00134 int CPPHeaderCodeOperation::lastEditableLine() {
00135 ClassifierCodeDocument * doc = dynamic_cast<ClassifierCodeDocument*>(getParentDocument());
00136 UMLOperation * o = getParentOperation();
00137 if(doc->parentIsInterface() || o->getAbstract())
00138 return -1;
00139
00140 return 0;
00141 }
00142
00143 void CPPHeaderCodeOperation::applyStereotypes (QString& prototype, UMLOperation * pOp,
00144 bool inlinePolicy, bool interface,
00145 QString& start, QString& end)
00146 {
00147
00148
00149 start = (inlinePolicy ? " {" : ";");
00150 end = (inlinePolicy ? "}" : "");
00151 if (pOp->getConst())
00152 prototype += " const";
00153 if (interface || pOp->getAbstract()) {
00154
00155 if (!pOp->isLifeOperation()) {
00156 prototype = "virtual " + prototype + " = 0";
00157 if (inlinePolicy) {
00158 start = ";";
00159 end = "";
00160 }
00161 }
00162 }
00163 else if (pOp->getStatic() && !pOp->isLifeOperation()) {
00164 prototype = "static " + prototype;
00165 }
00166
00167 if (!pOp->getStereotype().isEmpty()) {
00168 if ((pOp->getStereotype() == "friend") || (pOp->getStereotype(false) == "virtual")) {
00169 if (!pOp->isLifeOperation() && !(interface || pOp->getAbstract()) && !pOp->getStatic())
00170 prototype = pOp->getStereotype() + ' ' + prototype;
00171 }
00172 }
00173 }
00174
00175 #include "cppheadercodeoperation.moc"
This file is part of the documentation for umbrello Version 3.1.0.