• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

umbrello/umbrello

  • sources
  • kde-4.12
  • kdesdk
  • umbrello
  • umbrello
  • codegenerators
  • d
dcodeoperation.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * This program is free software; you can redistribute it and/or modify *
3  * it under the terms of the GNU General Public License as published by *
4  * the Free Software Foundation; either version 2 of the License, or *
5  * (at your option) any later version. *
6  * *
7  * copyright (C) 2007 Jari-Matti Mäkelä <jmjm@iki.fi> *
8  * copyright (C) 2008-2013 *
9  * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
10  ***************************************************************************/
11 
12 #include "dcodeoperation.h"
13 
14 #include "dcodegenerator.h"
15 #include "dcodegenerationpolicy.h"
16 #include "dclassifiercodedocument.h"
17 #include "dcodedocumentation.h"
18 #include "uml.h"
19 
20 // Constructors/Destructors
21 //
22 
23 DCodeOperation::DCodeOperation(DClassifierCodeDocument * doc, UMLOperation *parent,
24 const QString & body, const QString & comment) : CodeOperation (doc, parent, body, comment)
25 {
26  // lets not go with the default comment and instead use
27  // full-blown d documentation object instead
28  setComment(new DCodeDocumentation(doc));
29 
30  // these things never change..
31  setOverallIndentationLevel(1);
32 }
33 
34 DCodeOperation::~DCodeOperation()
35 {
36 }
37 
38 // we basically want to update the doc and start text of this method
39 void DCodeOperation::updateMethodDeclaration()
40 {
41  CodeDocument * doc = getParentDocument();
42  DClassifierCodeDocument * ddoc = dynamic_cast<DClassifierCodeDocument*>(doc);
43  UMLOperation * o = getParentOperation();
44  bool isInterface = ddoc->getParentClassifier()->isInterface();
45  QString endLine = getNewLineEndingChars();
46 
47  /*
48  * Member function declaration
49  *
50  * (visibility) (static | abstract | override) retType name (param1, ..., paramN) (; | {)
51  * a b c d e f g h
52  */
53 
54  QString startText;
55 
56  // (a) visibility modifier
57  //FIXME: startText += o->getVisibility().toString() + " ";
58 
59  // (b) static
60  if (o->isStatic()) startText += "static ";
61 
62  // (c) abstract
63  //TODO
64 
65  // (d) override
66  //TODO
67 
68  // (e) return type
69  if (!o->isConstructorOperation()) {
70  //FIXME: startText += DCodeGenerator::fixTypeName(o->getTypeName()) + " ";
71  }
72 
73  // (f) name
74  startText += o->name();
75 
76  // (g) params
77  startText += '(';
78 
79  // assemble parameters
80  QString paramStr = QString("");
81  UMLAttributeList list = getParentOperation()->getParmList();
82  int paramNum = list.count();
83 
84  foreach (UMLAttribute* parm, list) {
85  QString rType = parm->getTypeName();
86  QString paramName = parm->name();
87  paramStr += rType + ' ' + paramName;
88  paramNum--;
89 
90  if (paramNum > 0) paramStr += ", ";
91  }
92 
93  startText += paramStr;
94 
95  startText += ')';
96 
97  // (h) function body
98  if(isInterface) {
99  startText += ';';
100  setEndMethodText("");
101  } else {
102  startText += " {";
103  setEndMethodText("}");
104  }
105 
106  setStartMethodText(startText);
107 
108  // Lastly, for text content generation, we fix the comment on the
109  // operation, IF the codeop is autogenerated & currently empty
110  QString comment = o->doc();
111  if(comment.isEmpty() && contentType() == CodeBlock::AutoGenerated)
112  {
113  UMLAttributeList parameters = o->getParmList();
114  foreach (UMLAttribute* currentAtt, parameters) {
115  comment += endLine + "@param " + currentAtt->name() + ' ';
116  comment += currentAtt->doc();
117  }
118  // add a returns statement too
119  // TODO proper return type comments
120  //if(!returnType.isEmpty())
121  // comment += endLine + "@return " + returnType + ' ';
122 
123  getComment()->setText(comment);
124  }
125 }
126 
127 int DCodeOperation::lastEditableLine()
128 {
129  ClassifierCodeDocument * doc = dynamic_cast<ClassifierCodeDocument*>(getParentDocument());
130 
131  // very last line is NOT editable as its a one-line declaration
132  // w/ no body in an interface.
133  if (doc->parentIsInterface()) return -1;
134 
135  return 0;
136 }
137 
138 #include "dcodeoperation.moc"
CodeMethodBlock::setEndMethodText
void setEndMethodText(const QString &value)
Set the ending text that finishes this method after the body is printed.
Definition: codemethodblock.cpp:66
CodeMethodBlock::setStartMethodText
void setStartMethodText(const QString &value)
Set the starting text that begins this method before the body is printed.
Definition: codemethodblock.cpp:58
CodeBlockWithComments::getComment
CodeComment * getComment() const
Get the Comment object.
Definition: codeblockwithcomments.cpp:46
ClassifierCodeDocument
class ClassifierCodeDocument A CodeDocument which represents a UMLClassifier (e.g.
Definition: classifiercodedocument.h:33
TextBlock::setText
void setText(const QString &text)
Set the value of m_text The actual text of this code block.
Definition: textblock.cpp:80
CodeBlock::AutoGenerated
the content was generated by code generation itself
Definition: codeblock.h:28
DCodeOperation::DCodeOperation
DCodeOperation(DClassifierCodeDocument *doc, UMLOperation *op, const QString &body="", const QString &comment="")
Empty Constructor.
Definition: dcodeoperation.cpp:23
CodeBlockWithComments::setOverallIndentationLevel
void setOverallIndentationLevel(int level)
A utility method that causes the comment and body of the code block to have the same indentation leve...
Definition: codeblockwithcomments.cpp:163
UMLAttribute
This class is used to set up information for an attribute.
Definition: attribute.h:27
UMLAttributeList
This sub-class adds copyInto and clone to the QPtrList base class.
Definition: umlattributelist.h:26
CodeBlock::contentType
ContentType contentType() const
Get the value of m_contentType specifies whether the content (text) of this object was generated by t...
Definition: codeblock.cpp:54
ClassifierCodeDocument::getParentClassifier
UMLClassifier * getParentClassifier()
Get the value of m_parentclassifier.
Definition: classifiercodedocument.cpp:271
DCodeOperation::updateMethodDeclaration
virtual void updateMethodDeclaration()
This is the method called from within syncToparent().
Definition: dcodeoperation.cpp:39
TextBlock::getNewLineEndingChars
static QString getNewLineEndingChars()
Get the new line chars which ends the line.
Definition: textblock.cpp:172
dcodeoperation.h
UMLClassifier::isInterface
bool isInterface() const
Returns true if this classifier represents an interface.
Definition: classifier.cpp:112
DCodeDocumentation
A class representing a D documentation comment.
Definition: dcodedocumentation.h:27
CodeOperation
Definition: codeoperation.h:23
ClassifierCodeDocument::parentIsInterface
bool parentIsInterface()
Return if the parent classifier is an interface.
Definition: classifiercodedocument.cpp:413
DClassifierCodeDocument
A D UMLClassifier Code Document.
Definition: dclassifiercodedocument.h:36
CodeDocument
A document containing the code for one file.
Definition: codedocument.h:32
CodeMethodBlock::getParentDocument
CodeDocument * getParentDocument()
Get the parent code document.
Definition: codemethodblock.cpp:33
CodeOperation::getParentOperation
UMLOperation * getParentOperation()
Add a Parameter object to the m_parameterVector List.
Definition: codeoperation.cpp:64
UMLObject::isStatic
bool isStatic() const
Returns true if this UMLObject has classifier scope, otherwise false (the default).
Definition: umlobject.cpp:335
dclassifiercodedocument.h
DCodeOperation::lastEditableLine
virtual int lastEditableLine()
Definition: dcodeoperation.cpp:127
UMLOperation
This class represents an operation in the UML model.
Definition: operation.h:24
dcodedocumentation.h
dcodegenerator.h
DCodeOperation::~DCodeOperation
virtual ~DCodeOperation()
Empty Destructor.
Definition: dcodeoperation.cpp:34
UMLObject::name
QString name() const
Returns a copy of m_name.
Definition: umlobject.cpp:185
dcodegenerationpolicy.h
UMLOperation::isConstructorOperation
bool isConstructorOperation()
Returns whether this operation is a constructor.
Definition: operation.cpp:352
CodeBlockWithComments::setComment
void setComment(CodeComment *object)
Set the Comment object.
Definition: codeblockwithcomments.cpp:38
UMLClassifierListItem::getTypeName
virtual QString getTypeName() const
Returns the type name of the UMLClassifierListItem.
Definition: classifierlistitem.cpp:110
uml.h
UMLObject::doc
QString doc() const
Returns the documentation for the object.
Definition: umlobject.cpp:404
UMLOperation::getParmList
UMLAttributeList getParmList() const
Returns a list of parameters.
Definition: operation.cpp:171
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:05:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

umbrello/umbrello

Skip menu "umbrello/umbrello"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal