• 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
javacodeaccessormethod.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 // own header
13 #include "javacodeaccessormethod.h"
14 
15 // local includes
16 #include "attribute.h"
17 #include "codegenerator.h"
18 #include "codegenerationpolicy.h"
19 #include "classifiercodedocument.h"
20 #include "debug_utils.h"
21 #include "umlobject.h"
22 #include "umlrole.h"
23 #include "uml.h"
24 #include "codegen_utils.h"
25 #include "javaclassifiercodedocument.h"
26 #include "javacodegenerationpolicy.h"
27 #include "javacodeclassfield.h"
28 #include "javacodedocumentation.h"
29 
30 JavaCodeAccessorMethod::JavaCodeAccessorMethod (CodeClassField * field, CodeAccessorMethod::AccessorType type)
31  : CodeAccessorMethod (field)
32 {
33  setType(type);
34 
35  // lets use full-blown comment
36  JavaClassifierCodeDocument* jccd = dynamic_cast<JavaClassifierCodeDocument*>(field->getParentDocument());
37  setComment(new JavaCodeDocumentation(jccd));
38 }
39 
40 JavaCodeAccessorMethod::~JavaCodeAccessorMethod ()
41 {
42 }
43 
44 void JavaCodeAccessorMethod::setAttributesOnNode (QDomDocument & doc, QDomElement & blockElement)
45 {
46  // set super-class attributes
47  CodeAccessorMethod::setAttributesOnNode(doc, blockElement);
48 
49  // set local attributes now
50 }
51 
52 void JavaCodeAccessorMethod::setAttributesFromNode(QDomElement & root)
53 {
54  // set attributes from superclass method the XMI
55  CodeAccessorMethod::setAttributesFromNode(root);
56 
57  // load local stuff
58 }
59 
60 void JavaCodeAccessorMethod::updateContent()
61 {
62  CodeClassField * parentField = getParentClassField();
63  JavaCodeClassField * javafield = dynamic_cast<JavaCodeClassField*>(parentField);
64  QString fieldName = javafield->getFieldName();
65 
66  QString text = "";
67  switch(getType()) {
68  case CodeAccessorMethod::ADD:
69  {
70  int maxOccurs = javafield->maximumListOccurances();
71  QString fieldType = javafield->getTypeName();
72  QString indent = getIndentation();
73  QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars();
74  if(maxOccurs > 0)
75  text += "if ("+fieldName+".size() < "+ QString::number(maxOccurs)+") {"+endLine+indent;
76  text += fieldName+".add(value);";
77  if(maxOccurs > 0)
78  {
79  text += endLine+"} else {"+endLine;
80  text += indent + "System.err.println(\"ERROR: Cant add"+fieldType+" to "+fieldName+", minimum number of items reached.\");"+endLine+'}'+endLine;
81  }
82  break;
83  }
84  case CodeAccessorMethod::GET:
85  text = "return "+fieldName+';';
86  break;
87  case CodeAccessorMethod::LIST:
88  text = "return (List) "+fieldName+';';
89  break;
90  case CodeAccessorMethod::REMOVE:
91  {
92  int minOccurs = javafield->minimumListOccurances();
93  QString fieldType = javafield->getTypeName();
94  QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars();
95  QString indent = getIndentation();
96 
97  if(minOccurs > 0)
98  text += "if ("+fieldName+".size() >= "+ QString::number(minOccurs)+") {"+endLine+indent;
99  text += fieldName+".remove(value);";
100  if(minOccurs > 0)
101  {
102  text += endLine+"} else {"+endLine;
103  text += indent + "System.err.println(\"ERROR: Cant remove"+fieldType+" from "+fieldName+", minimum number of items reached.\");"+endLine+'}'+endLine;
104  }
105  break;
106  }
107  case CodeAccessorMethod::SET:
108  text = fieldName+" = value;";
109  break;
110  default:
111  // do nothing
112  break;
113  }
114 
115  setText(text);
116 }
117 
118 void JavaCodeAccessorMethod::updateMethodDeclaration()
119 {
120  JavaCodeClassField * javafield = dynamic_cast<JavaCodeClassField*>(getParentClassField());
121  CodeGenerationPolicy *commonpolicy = UMLApp::app()->commonPolicy();
122 
123  // gather defs
124  Uml::Visibility::Enum scopePolicy = commonpolicy->getAttributeAccessorScope();
125  QString strVis = Uml::Visibility::toString(javafield->getVisibility());
126  QString fieldName = javafield->getFieldName();
127  QString fieldType = javafield->getTypeName();
128  QString objectType = javafield->getListObjectType();
129  if(objectType.isEmpty())
130  objectType = fieldName;
131  QString endLine = UMLApp::app()->commonPolicy()->getNewLineEndingChars();
132 
133  // set scope of this accessor appropriately..if its an attribute,
134  // we need to be more sophisticated
135  if(javafield->parentIsAttribute())
136  switch (scopePolicy) {
137  case Uml::Visibility::Public:
138  case Uml::Visibility::Private:
139  case Uml::Visibility::Protected:
140  strVis = Uml::Visibility::toString(scopePolicy);
141  break;
142  default:
143  case Uml::Visibility::FromParent:
144  // do nothing..already have taken parent value
145  break;
146  }
147 
148  // some variables we will need to populate
149  QString headerText = "";
150  QString methodReturnType = "";
151  QString methodName = "";
152  QString methodParams = "";
153 
154  switch(getType()) {
155  case CodeAccessorMethod::ADD:
156  methodName = "add" + Codegen_Utils::capitalizeFirstLetter(fieldType);
157  methodReturnType = "void";
158  methodParams = objectType+" value ";
159  headerText = "Add an object of type "+objectType+" to the List "+fieldName+endLine+getParentObject()->doc()+endLine+"@return void";
160  break;
161  case CodeAccessorMethod::GET:
162  methodName = "get" + Codegen_Utils::capitalizeFirstLetter(fieldName);
163  methodReturnType = fieldType;
164  headerText = "Get the value of "+fieldName+endLine+getParentObject()->doc()+endLine+"@return the value of "+fieldName;
165  break;
166  case CodeAccessorMethod::LIST:
167  methodName = "get" + Codegen_Utils::capitalizeFirstLetter(fieldType)+"List";
168  methodReturnType = "List";
169  headerText = "Get the list of "+fieldName+endLine+getParentObject()->doc()+endLine+"@return List of "+fieldName;
170  break;
171  case CodeAccessorMethod::REMOVE:
172  methodName = "remove" + Codegen_Utils::capitalizeFirstLetter(fieldType);
173  methodReturnType = "void";
174  methodParams = objectType+" value ";
175  headerText = "Remove an object of type "+objectType+" from the List "+fieldName+endLine+getParentObject()->doc();
176  break;
177  case CodeAccessorMethod::SET:
178  methodName = "set" + Codegen_Utils::capitalizeFirstLetter(fieldName);
179  methodReturnType = "void";
180  methodParams = fieldType + " value ";
181  headerText = "Set the value of "+fieldName+endLine+getParentObject()->doc()+endLine;
182  break;
183  default:
184  // do nothing..no idea what this is
185  uWarning()<<"Warning: cant generate JavaCodeAccessorMethod for type: "<<getType();
186  break;
187  }
188 
189  // set header once.
190  if(getComment()->getText().isEmpty())
191  getComment()->setText(headerText);
192 
193  // set start/end method text
194  setStartMethodText(strVis+' '+methodReturnType+' '+methodName+" ("+methodParams+") {");
195  setEndMethodText("}");
196 }
197 
198 void JavaCodeAccessorMethod::update()
199 {
200  updateMethodDeclaration();
201  updateContent();
202 }
203 
204 #include "javacodeaccessormethod.moc"
CodeAccessorMethod::setType
void setType(AccessorType type)
Set the type of accessor method this is.
Definition: codeaccessormethod.cpp:72
umlobject.h
CodeClassField
class CodeClassField a special type of parameter.
Definition: codeclassfield.h:29
OwnedCodeBlock::getParentObject
UMLObject * getParentObject()
Get the value of m_parentObject.
Definition: ownedcodeblock.cpp:64
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
JavaCodeAccessorMethod::updateContent
virtual void updateContent()
This is the method called from within syncToparent() to update the body of the method.
Definition: javacodeaccessormethod.cpp:60
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
CodeAccessorMethod::REMOVE
Definition: codeaccessormethod.h:32
Uml::Visibility::Enum
Enum
Definition: basictypes.h:56
TextBlock::setText
void setText(const QString &text)
Set the value of m_text The actual text of this code block.
Definition: textblock.cpp:80
umlrole.h
CodeGenerationPolicy::getNewLineEndingChars
QString getNewLineEndingChars() const
Utility function to get the actual characters.
Definition: codegenerationpolicy.cpp:248
CodeAccessorMethod::getType
AccessorType getType()
Utility method to get the value of the parent object of the parent classifield.
Definition: codeaccessormethod.cpp:64
JavaCodeAccessorMethod::~JavaCodeAccessorMethod
virtual ~JavaCodeAccessorMethod()
Empty Destructor.
Definition: javacodeaccessormethod.cpp:40
CodeAccessorMethod::getParentClassField
CodeClassField * getParentClassField()
Get the value of m_parentclassfield.
Definition: codeaccessormethod.cpp:40
CodeAccessorMethod::AccessorType
AccessorType
Definition: codeaccessormethod.h:32
UMLApp::app
static UMLApp * app()
Get the last created instance of this class.
Definition: uml.cpp:206
CodeGenerationPolicy
class CodeGenerationPolicy This class describes the code generation policy for this project...
Definition: codegenerationpolicy.h:29
uWarning
#define uWarning()
Definition: debug_utils.h:97
JavaCodeAccessorMethod::update
void update()
Must be called before this object is usable.
Definition: javacodeaccessormethod.cpp:198
debug_utils.h
CodeParameter::getParentDocument
ClassifierCodeDocument * getParentDocument()
Get the parent Code Document.
Definition: codeparameter.cpp:133
codegenerationpolicy.h
CodeClassField::minimumListOccurances
int minimumListOccurances()
Find the minimum number of things that can occur in an association If mistakenly called on attribute ...
Definition: codeclassfield.cpp:325
Uml::Visibility::Private
Definition: basictypes.h:58
javacodeclassfield.h
JavaCodeAccessorMethod::JavaCodeAccessorMethod
JavaCodeAccessorMethod(CodeClassField *field, CodeAccessorMethod::AccessorType type)
Constructor.
Definition: javacodeaccessormethod.cpp:30
codegenerator.h
javaclassifiercodedocument.h
JavaCodeAccessorMethod::setAttributesFromNode
virtual void setAttributesFromNode(QDomElement &element)
Set the class attributes of this object from the passed element node.
Definition: javacodeaccessormethod.cpp:52
Codegen_Utils::capitalizeFirstLetter
QString capitalizeFirstLetter(const QString &string)
Return the input string with the first letter capitalized.
Definition: codegen_utils.cpp:421
CodeAccessorMethod::SET
Definition: codeaccessormethod.h:32
attribute.h
javacodedocumentation.h
javacodegenerationpolicy.h
CodeClassField::parentIsAttribute
bool parentIsAttribute() const
Get the value of m_isAbstract.
Definition: codeclassfield.cpp:126
CodeAccessorMethod::LIST
Definition: codeaccessormethod.h:32
CodeAccessorMethod::setAttributesOnNode
virtual void setAttributesOnNode(QDomDocument &doc, QDomElement &blockElement)
Set attributes of the node that represents this class in the XMI document.
Definition: codeaccessormethod.cpp:123
javacodeaccessormethod.h
CodeClassField::maximumListOccurances
int maximumListOccurances()
Find the maximum number of things that can occur in an association If mistakenly called on attribute ...
Definition: codeclassfield.cpp:349
Uml::Visibility::toString
QString toString(Enum item, bool mnemonic)
Convert Visibility item into QString representation.
Definition: basictypes.cpp:99
CodeAccessorMethod
Definition: codeaccessormethod.h:20
CodeAccessorMethod::ADD
Definition: codeaccessormethod.h:32
UMLApp::commonPolicy
CodeGenerationPolicy * commonPolicy() const
Returns the default code generation policy.
Definition: uml.cpp:2132
JavaCodeDocumentation
class JavaCodeDocumentation A Java code comment.
Definition: javacodedocumentation.h:27
Uml::Visibility::Public
Definition: basictypes.h:57
CodeAccessorMethod::setAttributesFromNode
virtual void setAttributesFromNode(QDomElement &element)
Set the class attributes of this object from the passed element node.
Definition: codeaccessormethod.cpp:137
CodeGenerationPolicy::getAttributeAccessorScope
Uml::Visibility::Enum getAttributeAccessorScope()
Get the value of m_attributeAccessorScope.
Definition: codegenerationpolicy.cpp:384
Import_Rose::methodName
void methodName(const QString &m)
Definition: import_rose.cpp:43
CodeParameter::getVisibility
Uml::Visibility::Enum getVisibility() const
Utility method to get the value of parent object scope.
Definition: codeparameter.cpp:89
JavaCodeClassField
Definition: javacodeclassfield.h:21
CodeAccessorMethod::GET
Definition: codeaccessormethod.h:32
JavaCodeAccessorMethod::updateMethodDeclaration
virtual void updateMethodDeclaration()
This is the method called from within syncToparent().
Definition: javacodeaccessormethod.cpp:118
JavaCodeAccessorMethod::setAttributesOnNode
virtual void setAttributesOnNode(QDomDocument &doc, QDomElement &blockElement)
Set attributes of the node that represents this class in the XMI document.
Definition: javacodeaccessormethod.cpp:44
classifiercodedocument.h
Uml::Visibility::FromParent
Definition: basictypes.h:61
CodeClassField::getListObjectType
QString getListObjectType()
Definition: codeclassfield.cpp:112
CodeBlockWithComments::setComment
void setComment(CodeComment *object)
Set the Comment object.
Definition: codeblockwithcomments.cpp:38
codegen_utils.h
TextBlock::getText
QString getText() const
Get the value of m_text The actual text of this code block.
Definition: textblock.cpp:99
Uml::Visibility::Protected
Definition: basictypes.h:59
JavaCodeClassField::getFieldName
QString getFieldName()
Definition: javacodeclassfield.cpp:40
TextBlock::getIndentation
static QString getIndentation()
Get how much a single "level" of indentation will actually indent.
Definition: textblock.cpp:182
JavaCodeClassField::getTypeName
QString getTypeName()
Get the value of m_dialog.
Definition: javacodeclassfield.cpp:84
uml.h
UMLObject::doc
QString doc() const
Returns the documentation for the object.
Definition: umlobject.cpp:404
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