1 /*
2     SPDX-License-Identifier: GPL-2.0-or-later
3 
4     SPDX-FileCopyrightText: 2003 Brian Thomas <thomas@mail630.gsfc.nasa.gov>
5     SPDX-FileCopyrightText: 2004-2020 Umbrello UML Modeller Authors <umbrello-devel@kde.org>
6 */
7 
8 #ifndef SIMPLECODEGENERATOR_H
9 #define SIMPLECODEGENERATOR_H
10 
11 #include "basictypes.h"
12 #include "codegenerator.h"
13 
14 #include <QMap>
15 #include <QString>
16 #include <QStringList>
17 
18 
19 /**
20  * A simple code generator interface designed to work with
21  * the existing codewriters.
22  *
23  * Code can be entered into a QTextEdit widget in the ClassPropertiesDialog. This
24  * code is then stored in the respective UMLOperation, written to the
25  * xmi file, and also used when generating the source files.
26  * The code fragments are stored into the xmi file in the section "codegeneration"
27  * with the tag "sourcecode".
28  */
29 class SimpleCodeGenerator : public CodeGenerator
30 {
31     Q_OBJECT
32 public:
33 
34     explicit SimpleCodeGenerator(bool createDirHierarchyForPackages = true);
35     virtual ~SimpleCodeGenerator();
36 
37     void writeCodeToFile(UMLClassifierList & concepts);
38     void writeCodeToFile();
39 
40     /**
41      * Call this method to generate code for a UMLClassifier
42      * @param c the class you want to generate code for.
43      */
44     virtual void writeClass(UMLClassifier *c) = 0;
45 
46 protected:
47     QString className_;
48     QString fileName_;
49 
50     QString findFileName(UMLPackage* concept, const QString &ext);
51     QString overwritableName(UMLPackage* concept, const QString &name, const QString &ext);
52     bool hasDefaultValueAttr(UMLClassifier *c);
53     bool hasAbstractOps(UMLClassifier *c);
54 
55     QString indent();
56 
57     /**
58      * Maps UMLObjects to filenames. Used for finding out which file
59      * each class was written to.
60      */
61     QMap<UMLPackage*, QString> m_fileMap;
62 
63     /**
64      * For some code generators, it does not make much sense to create a
65      * directory for each package because that would lead to a rather
66      * sparsely populated directory tree (maximum of just one source file
67      * per directory.)
68      */
69     bool m_createDirHierarchyForPackages;
70 
71     // old attributes writers will look for
72     QString m_indentation;
73     int m_indentLevel;
74     QString m_endl;
75 
76     virtual void initFromParentDocument();
77 
78 public slots:
79     virtual void syncCodeToDocument();
80 
81 };
82 
83 #endif // SIMPLECODEGENERATOR_H
84