umbrello: umbrello/codegenerators/codegenerator.h Source File

umbrello 2.38.3 Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

codegenerator.h
Go to the documentation of this file.
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-2022 Umbrello UML Modeller Authors <umbrello-devel@kde.org>
6*/
7
8#ifndef CODEGENERATOR_H
9#define CODEGENERATOR_H
10
11#include "basictypes.h"
12#include "codegenpolicyext.h"
13#include "codegenerationpolicy.h"
14#include "umlpackagelist.h"
15#include "umlclassifierlist.h"
16#include "codedocumentlist.h"
17#include "codeviewerstate.h"
18
19#include <QDir>
20#include <QHash>
21#include <QList>
22
23class UMLDoc;
24class UMLObject;
25class ClassifierCodeDocument;
26class CodeDocument;
27class CodeViewerDialog;
28class QDomDocument;
29class QDomElement;
30class QXmlStreamWriter;
31
53 class CodeGenerator : public QObject
54{
55 Q_OBJECT
56public:
57 typedef enum {Generated, Failed, Skipped } GenerationState;
58 CodeGenerator();
59 virtual ~CodeGenerator();
60
61 bool addCodeDocument(CodeDocument * add_object);
62 bool removeCodeDocument(CodeDocument * remove_object);
63
64 CodeDocumentList * getCodeDocumentList();
65
66 QString getUniqueID(CodeDocument * codeDoc);
67
68 virtual void saveToXMI(QXmlStreamWriter& writer);
69
70 CodeDocument * findCodeDocumentByID(const QString &id);
71
72 virtual void writeCodeToFile();
73 virtual void writeCodeToFile(UMLClassifierList &list);
74
75 void setIncludeHeadings(bool i);
76 bool includeHeadings() const;
77
78 void setHeadingFileDir(const QString &);
79 QString headingFileDir() const;
80
81 void setForceDoc(bool f);
82 bool forceDoc() const;
83
84 void setSectionCommentPolicy(CodeGenerationPolicy::WriteSectionCommentsPolicy f);
85 bool forceSections() const; // TODO change to WriteSectionCommentsPolicy
86
87 virtual QString getHeadingFile(const QString &file);
88
89 QString findFileName(CodeDocument * codeDocument);
90
91 static QString cleanName(const QString &name);
92
93 static QString formatDoc(const QString& text, const QString& linePrefix = QStringLiteral(" *"), int lineWidth = 80);
94 static QString formatFullDocBlock(const QString &text,
95 const QString &blockHeader = QStringLiteral("/* "),
96 const QString &blockFooter = QStringLiteral(" */"),
97 const QString &linePrefix = QStringLiteral(" *"), int lineWidth = 80);
98
99 static QString formatSourceCode(const QString& code, const QString& indentation);
100
101 static void findObjectsRelated(UMLClassifier *c, UMLPackageList &cList);
102
107 virtual void loadFromXMI(QDomElement & element);
108
112 virtual Uml::ProgrammingLanguage::Enum language() const = 0;
113
114 CodeDocument * findCodeDocumentByClassifier(UMLClassifier * classifier);
115
116 virtual QStringList defaultDatatypes() const;
117
118 virtual bool isReservedKeyword(const QString & keyword);
119
120 virtual QStringList reservedKeywords() const;
121
122 virtual void createDefaultStereotypes();
123
127 virtual void initFromParentDocument() = 0;
128
129protected:
130 QString overwritableName(const QString& name, const QString &extension);
131
132 bool openFile(QFile& file, const QString &name);
133
134 void writeListedCodeDocsToFile(CodeDocumentList * docs);
135
136 virtual void finalizeRun();
137
138 // map of what code documents we currently have in this generator.
139 QHash<QString, CodeDocument*> m_codeDocumentDictionary;
140
145 bool m_applyToAllRemaining;
146
150 UMLDoc* m_document;
151
152private:
153 CodeDocumentList m_codedocumentVector;
154 int m_lastIDIndex;
155
156 void loadCodeForOperation(const QString& id, const QDomElement& codeDocElement);
157
158public slots:
159 virtual void syncCodeToDocument();
160
161signals:
162 void codeGenerated(UMLClassifier* concept, bool generated);
163 void codeGenerated(UMLClassifier* concept, CodeGenerator::GenerationState result);
164 void showGeneratedFile(const QString& filename);
165};
166
167#endif // CODEGENERATOR_H
basictypes.h
ClassifierCodeDocument
Definition classifiercodedocument.h:29
CodeDocument
Definition codedocument.h:30
CodeGenerationPolicy::WriteSectionCommentsPolicy
WriteSectionCommentsPolicy
Definition codegenerationpolicy.h:44
CodeGenerator
Definition codegenerator.h:54
CodeGenerator::defaultDatatypes
virtual QStringList defaultDatatypes() const
Definition codegenerator.cpp:838
CodeGenerator::findCodeDocumentByID
CodeDocument * findCodeDocumentByID(const QString &id)
Definition codegenerator.cpp:109
CodeGenerator::initFromParentDocument
virtual void initFromParentDocument()=0
CodeGenerator::codeGenerated
void codeGenerated(UMLClassifier *concept, CodeGenerator::GenerationState result)
CodeGenerator::codeGenerated
void codeGenerated(UMLClassifier *concept, bool generated)
CodeGenerator::GenerationState
GenerationState
Definition codegenerator.h:57
CodeGenerator::Failed
@ Failed
Definition codegenerator.h:57
CodeGenerator::Generated
@ Generated
Definition codegenerator.h:57
CodeGenerator::Skipped
@ Skipped
Definition codegenerator.h:57
CodeGenerator::syncCodeToDocument
virtual void syncCodeToDocument()
Definition codegenerator.cpp:284
CodeGenerator::includeHeadings
bool includeHeadings() const
CodeGenerator::cleanName
static QString cleanName(const QString &name)
Definition codegenerator.cpp:536
CodeGenerator::findCodeDocumentByClassifier
CodeDocument * findCodeDocumentByClassifier(UMLClassifier *classifier)
Definition codegenerator.cpp:299
CodeGenerator::loadFromXMI
virtual void loadFromXMI(QDomElement &element)
Definition codegenerator.cpp:177
CodeGenerator::finalizeRun
virtual void finalizeRun()
Definition codegenerator.cpp:384
CodeGenerator::removeCodeDocument
bool removeCodeDocument(CodeDocument *remove_object)
Definition codegenerator.cpp:149
CodeGenerator::findFileName
QString findFileName(CodeDocument *codeDocument)
Definition codegenerator.cpp:552
CodeGenerator::forceSections
bool forceSections() const
Definition codegenerator.cpp:829
CodeGenerator::loadCodeForOperation
void loadCodeForOperation(const QString &id, const QDomElement &codeDocElement)
Definition codegenerator.cpp:219
CodeGenerator::setSectionCommentPolicy
void setSectionCommentPolicy(CodeGenerationPolicy::WriteSectionCommentsPolicy f)
Definition codegenerator.cpp:824
CodeGenerator::m_applyToAllRemaining
bool m_applyToAllRemaining
Definition codegenerator.h:145
CodeGenerator::getHeadingFile
virtual QString getHeadingFile(const QString &file)
Definition codegenerator.cpp:406
CodeGenerator::writeCodeToFile
virtual void writeCodeToFile()
Definition codegenerator.cpp:309
CodeGenerator::findObjectsRelated
static void findObjectsRelated(UMLClassifier *c, UMLPackageList &cList)
Definition codegenerator.cpp:609
CodeGenerator::writeListedCodeDocsToFile
void writeListedCodeDocsToFile(CodeDocumentList *docs)
Definition codegenerator.cpp:340
CodeGenerator::setHeadingFileDir
void setHeadingFileDir(const QString &)
CodeGenerator::getCodeDocumentList
CodeDocumentList * getCodeDocumentList()
Definition codegenerator.cpp:168
CodeGenerator::m_lastIDIndex
int m_lastIDIndex
Definition codegenerator.h:154
CodeGenerator::headingFileDir
QString headingFileDir() const
CodeGenerator::formatFullDocBlock
static QString formatFullDocBlock(const QString &text, const QString &blockHeader=QStringLiteral("/* "), const QString &blockFooter=QStringLiteral(" */"), const QString &linePrefix=QStringLiteral(" *"), int lineWidth=80)
Definition codegenerator.cpp:734
CodeGenerator::openFile
bool openFile(QFile &file, const QString &name)
Definition codegenerator.cpp:510
CodeGenerator::CodeGenerator
CodeGenerator()
Definition codegenerator.cpp:51
CodeGenerator::language
virtual Uml::ProgrammingLanguage::Enum language() const =0
CodeGenerator::m_codeDocumentDictionary
QHash< QString, CodeDocument * > m_codeDocumentDictionary
Definition codegenerator.h:139
CodeGenerator::isReservedKeyword
virtual bool isReservedKeyword(const QString &keyword)
Definition codegenerator.cpp:851
CodeGenerator::m_codedocumentVector
CodeDocumentList m_codedocumentVector
Definition codegenerator.h:153
CodeGenerator::formatDoc
static QString formatDoc(const QString &text, const QString &linePrefix=QStringLiteral(" *"), int lineWidth=80)
Definition codegenerator.cpp:699
CodeGenerator::saveToXMI
virtual void saveToXMI(QXmlStreamWriter &writer)
Definition codegenerator.cpp:244
CodeGenerator::setIncludeHeadings
void setIncludeHeadings(bool i)
CodeGenerator::overwritableName
QString overwritableName(const QString &name, const QString &extension)
Definition codegenerator.cpp:426
CodeGenerator::forceDoc
bool forceDoc() const
Definition codegenerator.cpp:819
CodeGenerator::~CodeGenerator
virtual ~CodeGenerator()
Definition codegenerator.cpp:66
CodeGenerator::setForceDoc
void setForceDoc(bool f)
Definition codegenerator.cpp:814
CodeGenerator::m_document
UMLDoc * m_document
Definition codegenerator.h:150
CodeGenerator::formatSourceCode
static QString formatSourceCode(const QString &code, const QString &indentation)
Definition codegenerator.cpp:797
CodeGenerator::createDefaultStereotypes
virtual void createDefaultStereotypes()
Definition codegenerator.cpp:869
CodeGenerator::addCodeDocument
bool addCodeDocument(CodeDocument *add_object)
Definition codegenerator.cpp:124
CodeGenerator::showGeneratedFile
void showGeneratedFile(const QString &filename)
CodeGenerator::getUniqueID
QString getUniqueID(CodeDocument *codeDoc)
Definition codegenerator.cpp:77
CodeGenerator::reservedKeywords
virtual QStringList reservedKeywords() const
Definition codegenerator.cpp:860
CodeViewerDialog
Definition codeviewerdialog.h:23
UMLClassifier
Information for a non-graphical Concept/Class.
Definition classifier.h:35
UMLDoc
Definition umldoc.h:63
UMLObject
The base class for UML objects.
Definition umlobject.h:70
codedocumentlist.h
CodeDocumentList
QList< CodeDocument * > CodeDocumentList
Definition codedocumentlist.h:14
codegenerationpolicy.h
codegenpolicyext.h
codeviewerstate.h
Uml::ProgrammingLanguage::Enum
Enum
Definition basictypes.h:291
umlclassifierlist.h
UMLClassifierList
QList< UMLClassifier * > UMLClassifierList
Definition umlclassifierlist.h:14
umlpackagelist.h
UMLPackageList
QList< UMLPackage * > UMLPackageList
Definition umlpackagelist.h:13