• 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
  • java
javacodeoperation.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) 2003 Brian Thomas <thomas@mail630.gsfc.nasa.gov> *
8  * copyright (C) 2004-2013 *
9  * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
10  ***************************************************************************/
11 
12 #include "javacodeoperation.h"
13 
14 #include "javaclassifiercodedocument.h"
15 #include "javacodedocumentation.h"
16 #include "javacodegenerator.h"
17 #include "uml.h"
18 
19 JavaCodeOperation::JavaCodeOperation
20  (JavaClassifierCodeDocument * doc, UMLOperation *parent, const QString & body, const QString & comment)
21  : CodeOperation (doc, parent, body, comment)
22 {
23  // lets not go with the default comment and instead use
24  // full-blown java documentation object instead
25  setComment(new JavaCodeDocumentation(doc));
26 
27  // these things never change..
28  setOverallIndentationLevel(1);
29 }
30 
31 JavaCodeOperation::~JavaCodeOperation()
32 {
33 }
34 
35 // we basically want to update the doc and start text of this method
36 void JavaCodeOperation::updateMethodDeclaration()
37 {
38  CodeDocument * doc = getParentDocument();
39  JavaClassifierCodeDocument * javadoc = dynamic_cast<JavaClassifierCodeDocument*>(doc);
40  UMLOperation * o = getParentOperation();
41  bool isInterface = javadoc->getParentClassifier()->isInterface();
42  QString endLine = getNewLineEndingChars();
43 
44  // now, the starting text.
45  QString strVis = Uml::Visibility::toString(o->visibility());
46  // no return type for constructors
47  QString fixedReturn = JavaCodeGenerator::fixTypeName(o->getTypeName());
48  QString returnType = o->isConstructorOperation() ? QString("") : (fixedReturn + QString(" "));
49  QString methodName = o->name();
50  QString paramStr = QString("");
51 
52  // assemble parameters
53  UMLAttributeList list = getParentOperation()->getParmList();
54  int nrofParam = list.count();
55  int paramNum = 0;
56  foreach (UMLAttribute* parm, list) {
57  QString rType = parm->getTypeName();
58  QString paramName = parm->name();
59  paramStr += rType + ' ' + paramName;
60  paramNum++;
61 
62  if (paramNum != nrofParam)
63  paramStr += ", ";
64  }
65  QString maybeStatic;
66  if (o->isStatic())
67  maybeStatic = "static ";
68  QString startText = strVis + ' ' + maybeStatic + returnType + methodName + " (" + paramStr + ')';
69 
70  // IF the parent is an interface, our operations look different
71  // e.g. they have no body
72  if(isInterface) {
73  startText += ';';
74  setEndMethodText("");
75  } else {
76  startText += " {";
77  setEndMethodText("}");
78  }
79 
80  setStartMethodText(startText);
81 
82  // Lastly, for text content generation, we fix the comment on the
83  // operation, IF the codeop is autogenerated & currently empty
84  QString comment = o->doc();
85  if(comment.isEmpty() && contentType() == CodeBlock::AutoGenerated)
86  {
87  UMLAttributeList parameters = o->getParmList();
88  foreach (UMLAttribute* currentAtt, parameters) {
89  comment += endLine + "@param " + currentAtt->name() + ' ';
90  comment += currentAtt->doc();
91  }
92  // add a returns statement too
93  if(!returnType.isEmpty())
94  comment += endLine + "@return " + returnType + ' ';
95  getComment()->setText(comment);
96  }
97 
98  // In Java, for interfaces..we DON'T write out non-public
99  // method declarations.
100  if(isInterface)
101  {
102  UMLOperation * o = getParentOperation();
103  if(o->visibility() != Uml::Visibility::Public)
104  setWriteOutText(false);
105  }
106 }
107 
108 int JavaCodeOperation::lastEditableLine()
109 {
110  ClassifierCodeDocument * doc = dynamic_cast<ClassifierCodeDocument*>(getParentDocument());
111  if(doc->parentIsInterface())
112  return -1; // very last line is NOT editable as its a one-line declaration w/ no body in
113  // an interface.
114  return 0;
115 }
116 
117 #include "javacodeoperation.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
JavaClassifierCodeDocument
class JavaClassifierCodeDocument A Java UMLClassifier Code Document.
Definition: javaclassifiercodedocument.h:32
ClassifierCodeDocument
class ClassifierCodeDocument A CodeDocument which represents a UMLClassifier (e.g.
Definition: classifiercodedocument.h:33
UMLObject::visibility
Uml::Visibility::Enum visibility() const
Returns the visibility of the object.
Definition: umlobject.cpp:435
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
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
JavaCodeOperation::updateMethodDeclaration
void updateMethodDeclaration()
This is the method called from within syncToparent().
Definition: javacodeoperation.cpp:36
ClassifierCodeDocument::getParentClassifier
UMLClassifier * getParentClassifier()
Get the value of m_parentclassifier.
Definition: classifiercodedocument.cpp:271
TextBlock::getNewLineEndingChars
static QString getNewLineEndingChars()
Get the new line chars which ends the line.
Definition: textblock.cpp:172
JavaCodeOperation::lastEditableLine
virtual int lastEditableLine()
Definition: javacodeoperation.cpp:108
javaclassifiercodedocument.h
UMLClassifier::isInterface
bool isInterface() const
Returns true if this classifier represents an interface.
Definition: classifier.cpp:112
javacodedocumentation.h
CodeOperation
Definition: codeoperation.h:23
ClassifierCodeDocument::parentIsInterface
bool parentIsInterface()
Return if the parent classifier is an interface.
Definition: classifiercodedocument.cpp:413
TextBlock::setWriteOutText
void setWriteOutText(bool write)
Set the value of m_writeOutText Whether or not to include the text of this TextBlock into a file...
Definition: textblock.cpp:131
CodeDocument
A document containing the code for one file.
Definition: codedocument.h:32
Uml::Visibility::toString
QString toString(Enum item, bool mnemonic)
Convert Visibility item into QString representation.
Definition: basictypes.cpp:99
CodeMethodBlock::getParentDocument
CodeDocument * getParentDocument()
Get the parent code document.
Definition: codemethodblock.cpp:33
JavaCodeDocumentation
class JavaCodeDocumentation A Java code comment.
Definition: javacodedocumentation.h:27
JavaCodeOperation::~JavaCodeOperation
virtual ~JavaCodeOperation()
Empty Destructor.
Definition: javacodeoperation.cpp:31
Uml::Visibility::Public
Definition: basictypes.h:57
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
javacodegenerator.h
UMLOperation
This class represents an operation in the UML model.
Definition: operation.h:24
Import_Rose::methodName
void methodName(const QString &m)
Definition: import_rose.cpp:43
JavaCodeOperation::JavaCodeOperation
JavaCodeOperation(JavaClassifierCodeDocument *doc, UMLOperation *op, const QString &body="", const QString &comment="")
Empty Constructor.
Definition: javacodeoperation.cpp:20
javacodeoperation.h
UMLObject::name
QString name() const
Returns a copy of m_name.
Definition: umlobject.cpp:185
UMLOperation::isConstructorOperation
bool isConstructorOperation()
Returns whether this operation is a constructor.
Definition: operation.cpp:352
UMLClassifierListItem::getTypeName
virtual QString getTypeName() const
Returns the type name of the UMLClassifierListItem.
Definition: classifierlistitem.cpp:110
JavaCodeGenerator::fixTypeName
static QString fixTypeName(const QString &string)
IF the type is "string" we need to declare it as the Java Object "String" (there is no string primati...
Definition: javacodegenerator.cpp:291
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:06:00 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