javacodeoperation.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "javacodeoperation.h"
00018
00019 #include "javaclassifiercodedocument.h"
00020 #include "javacodedocumentation.h"
00021 #include "javacodegenerator.h"
00022 #include "../uml.h"
00023
00024
00025
00026
00027 JavaCodeOperation::JavaCodeOperation
00028 ( JavaClassifierCodeDocument * doc, UMLOperation *parent, const QString & body, const QString & comment )
00029 : CodeOperation (doc, parent, body, comment)
00030 {
00031
00032
00033 setComment(new JavaCodeDocumentation(doc));
00034
00035
00036 setOverallIndentationLevel(1);
00037
00038 updateMethodDeclaration();
00039 updateContent();
00040 }
00041
00042 JavaCodeOperation::~JavaCodeOperation ( ) { }
00043
00044
00045
00046
00047
00048 void JavaCodeOperation::updateMethodDeclaration()
00049 {
00050
00051 CodeDocument * doc = getParentDocument();
00052 JavaClassifierCodeDocument * javadoc = dynamic_cast<JavaClassifierCodeDocument*>(doc);
00053 UMLOperation * o = getParentOperation();
00054 bool isInterface = javadoc->getParentClassifier()->isInterface();
00055 QString endLine = getNewLineEndingChars();
00056
00057
00058 QString strVis = javadoc->scopeToJavaDecl(o->getVisibility());
00059
00060 QString fixedReturn = JavaCodeGenerator::fixTypeName(o->getTypeName());
00061 QString returnType = o->isConstructorOperation() ? QString("") : (fixedReturn + QString(" "));
00062 QString methodName = o->getName();
00063 QString paramStr = QString("");
00064
00065
00066 UMLAttributeList list = getParentOperation()->getParmList();
00067 int nrofParam = list.count();
00068 int paramNum = 0;
00069 for(UMLAttribute* parm = list.first(); parm; parm=list.next())
00070 {
00071 QString rType = parm->getTypeName();
00072 QString paramName = parm->getName();
00073 paramStr += rType + ' ' + paramName;
00074 paramNum++;
00075
00076 if (paramNum != nrofParam )
00077 paramStr += ", ";
00078 }
00079 QString maybeStatic;
00080 if (o->getStatic())
00081 maybeStatic = "static ";
00082 QString startText = strVis + ' ' + maybeStatic + returnType + methodName + " (" + paramStr + ')';
00083
00084
00085
00086 if(isInterface) {
00087 startText += ';';
00088 setEndMethodText("");
00089 } else {
00090 startText += " {";
00091 setEndMethodText("}");
00092 }
00093
00094 setStartMethodText(startText);
00095
00096
00097
00098 QString comment = o->getDoc();
00099 if(comment.isEmpty() && getContentType() == CodeBlock::AutoGenerated)
00100 {
00101 UMLAttributeList parameters = o->getParmList();
00102 for(UMLAttributeListIt iterator(parameters); iterator.current(); ++iterator) {
00103 comment += endLine + "@param " + iterator.current()->getName() + ' ';
00104 comment += iterator.current()->getDoc();
00105 }
00106
00107 if(!returnType.isEmpty())
00108 comment += endLine + "@return " + returnType + ' ';
00109 getComment()->setText(comment);
00110 }
00111
00112
00113
00114
00115 if(isInterface)
00116 {
00117 UMLOperation * o = getParentOperation();
00118 if(o->getVisibility() != Uml::Visibility::Public)
00119 setWriteOutText(false);
00120 }
00121
00122 }
00123
00124 int JavaCodeOperation::lastEditableLine() {
00125 ClassifierCodeDocument * doc = dynamic_cast<ClassifierCodeDocument*>(getParentDocument());
00126 if(doc->parentIsInterface())
00127 return -1;
00128
00129 return 0;
00130 }
00131
00132 #include "javacodeoperation.moc"
This file is part of the documentation for umbrello Version 3.1.0.