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. *
7
* copyright (C) 2007 Jari-Matti Mäkelä <jmjm@iki.fi> *
8
* copyright (C) 2008-2013 *
9
* Umbrello UML Modeller Authors <uml-devel@uml.sf.net> *
10
***************************************************************************/
15
#include "simplecodegenerator.h"
16
#include "umloperationlist.h"
17
#include "umlattributelist.h"
18
#include "umlassociationlist.h"
23
* Class DWriter is a code generator for UMLClassifier objects.
24
* Create an instance of this class, and feed it a UMLClassifier when
25
* calling writeClass and it will generate a d source file for
28
* This is the "old" code generator that does not support code editing
29
* in the Modeller but uses significantly less file space because the
30
* source code is not replicated in the XMI file.
32
class DWriter : public SimpleCodeGenerator
39
virtual void writeClass(UMLClassifier *c);
41
virtual Uml::ProgrammingLanguage::Enum language() const;
43
QStringList defaultDatatypes();
48
* Writes the module declaration.
50
void writeModuleDecl(UMLClassifier *c, QTextStream &d);
53
* Writes the module imports.
55
void writeModuleImports(UMLClassifier *c, QTextStream &d);
58
* Writes class's documentation then the class header
59
* "public abstract class Foo extents {".
61
void writeClassDecl(UMLClassifier *c, QTextStream &d);
64
* Writes the comment and class constructor.
66
void writeConstructor(UMLClassifier *c, QTextStream &d);
69
* Return true if the two operations have the same name and the same parameters.
70
* @param op1 first operation to be compared
71
* @param op2 second operation to be compared
73
static bool compareDMethod(UMLOperation *op1, UMLOperation *op2);
76
* Return true if the operation is in the list.
77
* @param umlOp operation to be searched
78
* @param opl list of operations
80
static bool dMethodInList(UMLOperation *umlOp, UMLOperationList &opl);
83
* Get all operations which a given class inherit from all its super interfaces and get all operations
84
* which this given class inherit from all its super classes.
85
* @param c the class for which we are generating code
86
* @param yetImplementedOpList the list of yet implemented operations
87
* @param toBeImplementedOpList the list of to be implemented operations
88
* @param noClassInPath tells if there is a class between the base class and the current interface
90
void getSuperImplementedOperations(UMLClassifier *c, UMLOperationList &yetImplementedOpList,
91
UMLOperationList &toBeImplementedOpList, bool noClassInPath = true);
94
* Get all operations which a given class inherit from all its super interfaces and that should be implemented.
95
* @param c the class for which we are generating code
96
* @param opl the list of operations used to append the operations
98
void getInterfacesOperationsToBeImplemented(UMLClassifier *c, UMLOperationList &opl);
101
* Write all operations for a given class.
102
* @param c the class for which we are generating code
103
* @param j the stream associated with the output file
105
void writeOperations(UMLClassifier *c, QTextStream &j);
108
* Write a list of operations for a given class.
109
* @param list the list of operations you want to write
110
* @param j the stream associated with the output file
112
void writeOperations(UMLOperationList &list, QTextStream &j);
115
* Write all attributes for a given class.
116
* @param c the class for which we are generating code
117
* @param j the stream associated with the output file
119
void writeAttributes(UMLClassifier *c, QTextStream &j);
122
* Writes the protection modifier line.
123
* @param visibility protection modifier
124
* @param d text stream
126
void writeProtectionMod(Uml::Visibility::Enum visibility, QTextStream &d);
129
* Writes attribute declarations with a specific
130
* protection modifier.
131
* @param prot the protection modifier
132
* @param atlist attribute list
133
* @param d text stream
135
void writeAttributeDecl(Uml::Visibility::Enum visibility, UMLAttributeList &atlist, QTextStream &d);
138
* Writes the Attribute declarations.
139
* @param atpub List of public attributes
140
* @param atprot list of protected attributes
141
* @param atpriv list of private attributes
142
* @param d text stream
144
void writeAttributeDecls(UMLAttributeList &atpub, UMLAttributeList &atprot,
145
UMLAttributeList &atpriv, QTextStream &d );
148
* Searches a list of associations for appropriate ones to write out as attributes.
150
void writeAssociationDecls(UMLAssociationList associations, Uml::ID::Type id, QTextStream &d);
153
* Writes out an association as an attribute using Vector.
155
void writeAssociationRoleDecl(QString fieldClassName, QString roleName, QString multi,
156
QString doc, Uml::Visibility::Enum visib, QTextStream &d);
159
* Calls @ref writeSingleAttributeAccessorMethods() on each of the attributes in atpub.
161
void writeAttributeMethods(UMLAttributeList &atpub, Uml::Visibility::Enum visibility, QTextStream &d);
164
* Calls @ref writeAssociationRoleMethod() on each of the associations in the given list.
166
void writeAssociationMethods(UMLAssociationList associations, UMLClassifier *thisClass,
170
* Calls @ref writeSingleAttributeAccessorMethods() or @ref
171
* writeVectorAttributeAccessorMethods() on the assocaition
174
void writeAssociationRoleMethod(QString fieldClassName, QString roleName, QString multi,
175
QString description, Uml::Visibility::Enum visib, Uml::Changeability::Enum change,
179
* Writes getFoo() and setFoo() accessor methods for the attribute.
181
void writeSingleAttributeAccessorMethods(QString fieldClassName, QString fieldVarName,
182
QString fieldName, QString description,
183
Uml::Visibility::Enum visibility, Uml::Changeability::Enum change,
184
bool isFinal, QTextStream &d);
187
* Writes addFoo() and removeFoo() accessor methods for the Vector attribute.
189
void writeVectorAttributeAccessorMethods(QString fieldClassName, QString fieldVarName,
190
QString fieldName, QString description,
191
Uml::Visibility::Enum visibility, Uml::Changeability::Enum change,
195
* Writes a // style comment.
197
void writeComment(const QString &text, const QString &indent, QTextStream &d, bool dDocStyle=false);
200
* Writes a documentation comment.
202
void writeDocumentation(QString header, QString body, QString end, QString indent, QTextStream &d);
205
* Returns the name of the given object (if it exists).
207
QString getUMLObjectName(UMLObject *obj);
210
* Lowers the case of the first letter in the given string.
212
QString deCapitaliseFirstLetter(const QString& str);
215
* Returns the plural form of a subject.
217
QString pluralize(const QString& string);
220
* Returns the non-plural form of a subject.
222
QString unPluralize(const QString& str);
225
* Replaces `string' with `String' and `bool' with `boolean'.
227
QString fixTypeName(const QString& string);
230
* Check that initial values of strings have quotes around them.
232
QString fixInitialStringDeclValue(const QString& val, const QString& type);
235
* Write a blank line.
237
void writeBlankLine(QTextStream& d);
239
QString startline; ///< a \n, used at the end of each line
240
bool isInterface; ///< whether or not this concept is an interface