umbrello API Documentation

javacodeoperation.cpp

00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  *   copyright (C) 2004-2006                                               *
00009  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00010  ***************************************************************************/
00011 
00012 /*  This code generated by:
00013  *      Author : thomas
00014  *      Date   : Mon Jun 30 2003
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 // Constructors/Destructors
00025 //
00026 
00027 JavaCodeOperation::JavaCodeOperation
00028  ( JavaClassifierCodeDocument * doc, UMLOperation *parent, const QString & body, const QString & comment )
00029         : CodeOperation (doc, parent, body, comment)
00030 {
00031     // lets not go with the default comment and instead use
00032     // full-blown java documentation object instead
00033     setComment(new JavaCodeDocumentation(doc));
00034 
00035     // these things never change..
00036     setOverallIndentationLevel(1);
00037 
00038     updateMethodDeclaration();
00039     updateContent();
00040 }
00041 
00042 JavaCodeOperation::~JavaCodeOperation ( ) { }
00043 
00044 // Other methods
00045 //
00046 
00047 // we basically want to update the doc and start text of this method
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     // now, the starting text.
00058     QString strVis = javadoc->scopeToJavaDecl(o->getVisibility());
00059     // no return type for constructors
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     // assemble parameters
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     // IF the parent is an interface, our operations look different
00085     // e.g. they have no body
00086     if(isInterface) {
00087         startText += ';';
00088         setEndMethodText("");
00089     } else {
00090         startText += " {";
00091         setEndMethodText("}");
00092     }
00093 
00094     setStartMethodText(startText);
00095 
00096     // Lastly, for text content generation, we fix the comment on the
00097     // operation, IF the codeop is autogenerated & currently empty
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         // add a returns statement too
00107         if(!returnType.isEmpty())
00108             comment += endLine + "@return " + returnType + ' ';
00109         getComment()->setText(comment);
00110     }
00111 
00112 
00113     // In Java, for interfaces..we DON'T write out non-public
00114     // method declarations.
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; // very last line is NOT editable as its a one-line declaration w/ no body in
00128     // an interface.
00129     return 0;
00130 }
00131 
00132 #include "javacodeoperation.moc"
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:07:57 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003