~ubuntu-branches/ubuntu/saucy/umbrello/saucy-proposed

« back to all changes in this revision

Viewing changes to umbrello/codegenerators/d/dwriter.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-06-21 02:29:56 UTC
  • Revision ID: package-import@ubuntu.com-20130621022956-vfvg2xih76w1ydxn
Tags: upstream-4.10.80
Import upstream version 4.10.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <uml-devel@uml.sf.net>                  *
 
10
 ***************************************************************************/
 
11
 
 
12
#ifndef DWRITER_H
 
13
#define DWRITER_H
 
14
 
 
15
#include "simplecodegenerator.h"
 
16
#include "umloperationlist.h"
 
17
#include "umlattributelist.h"
 
18
#include "umlassociationlist.h"
 
19
 
 
20
class UMLOperation;
 
21
 
 
22
/**
 
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
 
26
 * that concept.
 
27
 * Note:
 
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.
 
31
 */
 
32
class DWriter : public SimpleCodeGenerator
 
33
{
 
34
public:
 
35
 
 
36
    DWriter();
 
37
    virtual ~DWriter();
 
38
 
 
39
    virtual void writeClass(UMLClassifier *c);
 
40
 
 
41
    virtual Uml::ProgrammingLanguage::Enum language() const;
 
42
 
 
43
    QStringList defaultDatatypes();
 
44
 
 
45
private:
 
46
 
 
47
    /**
 
48
     * Writes the module declaration.
 
49
     */
 
50
    void writeModuleDecl(UMLClassifier *c, QTextStream &d);
 
51
 
 
52
    /**
 
53
     * Writes the module imports.
 
54
     */
 
55
    void writeModuleImports(UMLClassifier *c, QTextStream &d);
 
56
 
 
57
    /**
 
58
     * Writes class's documentation then the class header
 
59
     * "public abstract class Foo extents {".
 
60
     */
 
61
    void writeClassDecl(UMLClassifier *c, QTextStream &d);
 
62
 
 
63
    /**
 
64
     * Writes the comment and class constructor.
 
65
     */
 
66
    void writeConstructor(UMLClassifier *c, QTextStream &d);
 
67
 
 
68
    /**
 
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
 
72
     */
 
73
    static bool compareDMethod(UMLOperation *op1, UMLOperation *op2);
 
74
 
 
75
    /**
 
76
     * Return true if the operation is in the list.
 
77
     * @param umlOp   operation to be searched
 
78
     * @param opl     list of operations
 
79
     */
 
80
    static bool dMethodInList(UMLOperation *umlOp, UMLOperationList &opl);
 
81
 
 
82
    /**
 
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
 
89
     */
 
90
    void getSuperImplementedOperations(UMLClassifier *c, UMLOperationList &yetImplementedOpList,
 
91
                                       UMLOperationList &toBeImplementedOpList, bool noClassInPath = true);
 
92
 
 
93
    /**
 
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
 
97
     */
 
98
    void getInterfacesOperationsToBeImplemented(UMLClassifier *c, UMLOperationList &opl);
 
99
 
 
100
    /**
 
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
 
104
     */
 
105
    void writeOperations(UMLClassifier *c, QTextStream &j);
 
106
 
 
107
    /**
 
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
 
111
     */
 
112
    void writeOperations(UMLOperationList &list, QTextStream &j);
 
113
 
 
114
    /**
 
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
 
118
     */
 
119
    void writeAttributes(UMLClassifier *c, QTextStream &j);
 
120
 
 
121
    /**
 
122
     * Writes the protection modifier line.
 
123
     * @param visibility   protection modifier
 
124
     * @param d            text stream
 
125
     */
 
126
    void writeProtectionMod(Uml::Visibility::Enum visibility, QTextStream &d);
 
127
 
 
128
    /**
 
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
 
134
     */
 
135
    void writeAttributeDecl(Uml::Visibility::Enum visibility, UMLAttributeList &atlist, QTextStream &d);
 
136
 
 
137
    /**
 
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
 
143
     */
 
144
    void writeAttributeDecls(UMLAttributeList &atpub, UMLAttributeList &atprot,
 
145
                             UMLAttributeList &atpriv, QTextStream &d );
 
146
 
 
147
    /**
 
148
     * Searches a list of associations for appropriate ones to write out as attributes.
 
149
     */
 
150
    void writeAssociationDecls(UMLAssociationList associations, Uml::ID::Type id, QTextStream &d);
 
151
 
 
152
    /**
 
153
     * Writes out an association as an attribute using Vector.
 
154
     */
 
155
    void writeAssociationRoleDecl(QString fieldClassName, QString roleName, QString multi,
 
156
                                  QString doc, Uml::Visibility::Enum visib, QTextStream &d);
 
157
 
 
158
    /**
 
159
     * Calls @ref writeSingleAttributeAccessorMethods() on each of the attributes in atpub.
 
160
     */
 
161
    void writeAttributeMethods(UMLAttributeList &atpub, Uml::Visibility::Enum visibility, QTextStream &d);
 
162
 
 
163
    /**
 
164
     * Calls @ref writeAssociationRoleMethod() on each of the associations in the given list.
 
165
     */
 
166
    void writeAssociationMethods(UMLAssociationList associations, UMLClassifier *thisClass,
 
167
                                 QTextStream &d);
 
168
 
 
169
    /**
 
170
     * Calls @ref writeSingleAttributeAccessorMethods() or @ref
 
171
     * writeVectorAttributeAccessorMethods() on the assocaition
 
172
     * role.
 
173
     */
 
174
    void writeAssociationRoleMethod(QString fieldClassName, QString roleName, QString multi,
 
175
                                    QString description, Uml::Visibility::Enum visib, Uml::Changeability::Enum change,
 
176
                                    QTextStream &d);
 
177
 
 
178
    /**
 
179
     * Writes getFoo() and setFoo() accessor methods for the attribute.
 
180
     */
 
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);
 
185
 
 
186
    /**
 
187
     * Writes addFoo() and removeFoo() accessor methods for the Vector attribute.
 
188
     */
 
189
    void writeVectorAttributeAccessorMethods(QString fieldClassName, QString fieldVarName,
 
190
            QString fieldName, QString description,
 
191
            Uml::Visibility::Enum visibility, Uml::Changeability::Enum change,
 
192
            QTextStream &d);
 
193
 
 
194
    /**
 
195
     * Writes a // style comment.
 
196
     */
 
197
    void writeComment(const QString &text, const QString &indent, QTextStream &d, bool dDocStyle=false);
 
198
 
 
199
    /**
 
200
     * Writes a documentation comment.
 
201
     */
 
202
    void writeDocumentation(QString header, QString body, QString end, QString indent, QTextStream &d);
 
203
 
 
204
    /**
 
205
     * Returns the name of the given object (if it exists).
 
206
     */
 
207
    QString getUMLObjectName(UMLObject *obj);
 
208
 
 
209
    /**
 
210
     * Lowers the case of the first letter in the given string.
 
211
     */
 
212
    QString deCapitaliseFirstLetter(const QString& str);
 
213
 
 
214
    /**
 
215
     * Returns the plural form of a subject.
 
216
     */
 
217
    QString pluralize(const QString& string);
 
218
 
 
219
    /**
 
220
     * Returns the non-plural form of a subject.
 
221
     */
 
222
    QString unPluralize(const QString& str);
 
223
 
 
224
    /**
 
225
     * Replaces `string' with `String' and `bool' with `boolean'.
 
226
     */
 
227
    QString fixTypeName(const QString& string);
 
228
 
 
229
    /**
 
230
     * Check that initial values of strings have quotes around them.
 
231
     */
 
232
    QString fixInitialStringDeclValue(const QString& val, const QString& type);
 
233
 
 
234
    /**
 
235
     * Write a blank line.
 
236
     */
 
237
    void writeBlankLine(QTextStream& d);
 
238
 
 
239
    QString startline;  ///< a \n, used at the end of each line
 
240
    bool isInterface;  ///< whether or not this concept is an interface
 
241
 
 
242
};
 
243
 
 
244
#endif // DWRITER_H