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

codegenerator.h
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-2020 *
9 * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
10 ***************************************************************************/
11
12 #ifndef CODEGENERATOR_H
13 #define CODEGENERATOR_H
14
15 #include "basictypes.h"
16 #include "codegenpolicyext.h"
17 #include "codegenerationpolicy.h"
18 #include "umlpackagelist.h"
19 #include "umlclassifierlist.h"
20 #include "codedocumentlist.h"
21 #include "codeviewerstate.h"
22
23 #include <QDir>
24 #include <QHash>
25 #include <QList>
26
27 class UMLDoc;
28 class UMLObject;
29 class ClassifierCodeDocument;
30 class CodeDocument;
31 class CodeViewerDialog;
32 class QDomDocument;
33 class QDomElement;
34
56 class CodeGenerator : public QObject
57 {
58 Q_OBJECT
59 public:
60 CodeGenerator();
61 virtual ~CodeGenerator();
62
63 bool addCodeDocument(CodeDocument * add_object);
64 bool removeCodeDocument(CodeDocument * remove_object);
65
66 CodeDocumentList * getCodeDocumentList();
67
68 QString getUniqueID(CodeDocument * codeDoc);
69
70 virtual void saveToXMI1(QDomDocument & doc, QDomElement & root);
71
72 CodeDocument * findCodeDocumentByID(const QString &id);
73
74 virtual void writeCodeToFile();
75 virtual void writeCodeToFile(UMLClassifierList &list);
76
77 void setIncludeHeadings(bool i);
78 bool includeHeadings() const;
79
80 void setHeadingFileDir(const QString &);
81 QString headingFileDir() const;
82
83 void setForceDoc(bool f);
84 bool forceDoc() const;
85
86 void setForceSections(bool f);
87 bool forceSections() const;
88
89 virtual QString getHeadingFile(const QString &file);
90
91 QString findFileName(CodeDocument * codeDocument);
92
93 static QString cleanName(const QString &name);
94
95 static QString formatDoc(const QString& text, const QString& linePrefix = QLatin1String(" *"), int lineWidth = 80);
96
97 static QString formatSourceCode(const QString& code, const QString& indentation);
98
99 static void findObjectsRelated(UMLClassifier *c, UMLPackageList &cList);
100
105 virtual void loadFromXMI1(QDomElement & element);
106
110 virtual Uml::ProgrammingLanguage::Enum language() const = 0;
111
112 CodeDocument * findCodeDocumentByClassifier(UMLClassifier * classifier);
113
114 virtual QStringList defaultDatatypes();
115
116 virtual bool isReservedKeyword(const QString & keyword);
117
118 virtual QStringList reservedKeywords() const;
119
120 virtual void createDefaultStereotypes();
121
125 virtual void initFromParentDocument() = 0;
126
127 protected:
128 QString overwritableName(const QString& name, const QString &extension);
129
130 bool openFile(QFile& file, const QString &name);
131
132 void writeListedCodeDocsToFile(CodeDocumentList * docs);
133
134 virtual void finalizeRun();
135
136 // map of what code documents we currently have in this generator.
137 QHash<QString, CodeDocument*> m_codeDocumentDictionary;
138
143 bool m_applyToAllRemaining;
144
148 UMLDoc* m_document;
149
150 private:
151 CodeDocumentList m_codedocumentVector;
152 int m_lastIDIndex;
153
154 void loadCodeForOperation(const QString& id, const QDomElement& codeDocElement);
155
156 public slots:
157 virtual void syncCodeToDocument();
158
159 signals:
160 void codeGenerated(UMLClassifier* concept, bool generated);
161 void showGeneratedFile(const QString& filename);
162 };
163
164 #endif // CODEGENERATOR_H
CodeGenerationPolicy::Ok
@ Ok
Definition: codegenerationpolicy.h:46
UMLObject::id
virtual Uml::ID::Type id() const
Definition: umlobject.cpp:425
umlattributelist.h
umlpackagelist.h
UMLClassifier::getOpList
UMLOperationList getOpList(bool includeInherited=false, UMLClassifierSet *alreadyTraversed=0)
Definition: classifier.cpp:939
CodeGenerator::finalizeRun
virtual void finalizeRun()
Definition: codegenerator.cpp:385
UMLObject::ObjectType
ObjectType
Definition: umlobject.h:80
CodeGenerator::m_codedocumentVector
CodeDocumentList m_codedocumentVector
Definition: codegenerator.h:151
Uml::ProgrammingLanguage::Enum
Enum
Definition: basictypes.h:271
UMLClassifier::isInterface
bool isInterface() const
Definition: classifier.cpp:118
CodeGenerator::loadCodeForOperation
void loadCodeForOperation(const QString &id, const QDomElement &codeDocElement)
Definition: codegenerator.cpp:220
UMLObject::asUMLOperation
UMLOperation * asUMLOperation()
Definition: umlobject.cpp:1324
CodeGenerationPolicy::Ask
@ Ask
Definition: codegenerationpolicy.h:46
UMLAttributeList
Definition: umlattributelist.h:27
umloperationlist.h
CodeGenerator::setForceDoc
void setForceDoc(bool f)
Definition: codegenerator.cpp:760
CodeGenerator::getHeadingFile
virtual QString getHeadingFile(const QString &file)
Definition: codegenerator.cpp:407
UMLCanvasObject::getAssociations
UMLAssociationList getAssociations()
Definition: umlcanvasobject.cpp:329
UMLOperation::getParmList
UMLAttributeList getParmList() const
Definition: operation.cpp:178
codedocumentlist.h
CodeGenerator::cleanName
static QString cleanName(const QString &name)
Definition: codegenerator.cpp:549
CodeGenerationPolicy::setCodeVerboseDocumentComments
void setCodeVerboseDocumentComments(bool new_var)
Definition: codegenerationpolicy.cpp:139
operation.h
UMLClassifierListItem::getType
UMLClassifier * getType() const
Definition: classifierlistitem.cpp:102
CodeGenerator::syncCodeToDocument
virtual void syncCodeToDocument()
Definition: codegenerator.cpp:285
CodeGenerationPolicy::setCodeVerboseSectionComments
void setCodeVerboseSectionComments(bool new_var)
Definition: codegenerationpolicy.cpp:115
codeviewerdialog.h
CodeGenerator::isReservedKeyword
virtual bool isReservedKeyword(const QString &keyword)
Definition: codegenerator.cpp:797
Uml::RoleType::A
@ A
Definition: basictypes.h:239
CodeGenerator::findObjectsRelated
static void findObjectsRelated(UMLClassifier *c, UMLPackageList &cList)
Definition: codegenerator.cpp:622
UMLApp::commonPolicy
CodeGenerationPolicy * commonPolicy() const
Definition: uml.cpp:2283
Uml::ID::toString
QString toString(const ID::Type &id)
Definition: basictypes.cpp:1263
association.h
CodeGenerationPolicy::Never
@ Never
Definition: codegenerationpolicy.h:46
UMLClassifierList
QList< UMLClassifier * > UMLClassifierList
Definition: umlclassifierlist.h:17
CodeGenerator::findCodeDocumentByID
CodeDocument * findCodeDocumentByID(const QString &id)
Definition: codegenerator.cpp:110
Uml::ID::Type
std::string Type
Definition: basictypes.h:351
CodeGenerator::findCodeDocumentByClassifier
CodeDocument * findCodeDocumentByClassifier(UMLClassifier *classifier)
Definition: codegenerator.cpp:300
CodeGenerator::findFileName
QString findFileName(CodeDocument *codeDocument)
Definition: codegenerator.cpp:565
CodeDocument::getFileExtension
QString getFileExtension() const
Definition: codedocument.cpp:82
CodeGenerator::setHeadingFileDir
void setHeadingFileDir(const QString &)
CodeDocument
Definition: codedocument.h:33
Uml::AssociationType::UniAssociation
@ UniAssociation
Definition: basictypes.h:119
CodeGenerationPolicy::setOverwritePolicy
void setOverwritePolicy(OverwritePolicy new_var)
Definition: codegenerationpolicy.cpp:74
UMLObject
The base class for UML objects.
Definition: umlobject.h:74
UMLObject::baseType
ObjectType baseType() const
Definition: umlobject.cpp:397
CodeGenerationPolicy::Cancel
@ Cancel
Definition: codegenerationpolicy.h:46
CodeGenerator::forceDoc
bool forceDoc() const
Definition: codegenerator.cpp:765
ClassifierCodeDocument
Definition: classifiercodedocument.h:33
CodeGenerator::m_codeDocumentDictionary
QHash< QString, CodeDocument * > m_codeDocumentDictionary
Definition: codegenerator.h:137
CodeGenerator::loadFromXMI1
virtual void loadFromXMI1(QDomElement &element)
Definition: codegenerator.cpp:178
CodeGenerator::writeCodeToFile
virtual void writeCodeToFile()
Definition: codegenerator.cpp:310
CodeGenerator::formatSourceCode
static QString formatSourceCode(const QString &code, const QString &indentation)
Definition: codegenerator.cpp:743
CodeDocument::getPath
virtual QString getPath()
Definition: codedocument.cpp:100
Uml::AssociationType::Aggregation
@ Aggregation
Definition: basictypes.h:108
CodeGenerator::reservedKeywords
virtual QStringList reservedKeywords() const
Definition: codegenerator.cpp:806
Uml::ProgrammingLanguage::toString
QString toString(Enum item)
Definition: basictypes.cpp:873
Uml::ID::fromString
ID::Type fromString(const QString &id)
Definition: basictypes.cpp:1268
CodeGenerator::setForceSections
void setForceSections(bool f)
Definition: codegenerator.cpp:770
UMLOperation::setSourceCode
void setSourceCode(const QString &code)
Definition: operation.cpp:499
CodeDocument::loadFromXMI1
virtual void loadFromXMI1(QDomElement &root)
Definition: codedocument.cpp:348
CodeGenerationPolicy::getHeadingFile
QString getHeadingFile(const QString &str)
Definition: codegenerationpolicy.cpp:546
CodeGenerator::showGeneratedFile
void showGeneratedFile(const QString &filename)
Definition: moc_codegenerator.cpp:161
UMLApp
Definition: uml.h:100
UMLDoc::findObjectById
UMLObject * findObjectById(Uml::ID::Type id)
Definition: umldoc.cpp:1038
attribute.h
CodeGenerator::initFromParentDocument
virtual void initFromParentDocument()=0
a
QString a
Definition: petalnode.cpp:18
uWarning
#define uWarning()
Definition: debug_utils.h:124
CodeGenerator::~CodeGenerator
virtual ~CodeGenerator()
Definition: codegenerator.cpp:67
i18n
#define i18n
Definition: main.cpp:39
classifiercodedocument.h
Uml::AssociationType::Association
@ Association
Definition: basictypes.h:110
umlclassifierlist.h
CodeGenerator::formatDoc
static QString formatDoc(const QString &text, const QString &linePrefix=QLatin1String(" *"), int lineWidth=80)
Definition: codegenerator.cpp:712
basictypes.h
codegenerationpolicy.h
CodeGenerationPolicy
Definition: codegenerationpolicy.h:30
uDebug
#define uDebug()
Definition: debug_utils.h:122
SimpleCodeGenerator
Definition: simplecodegenerator.h:34
CodeGenerationPolicy::getCodeVerboseDocumentComments
bool getCodeVerboseDocumentComments() const
Definition: codegenerationpolicy.cpp:152
CodeGenerator::removeCodeDocument
bool removeCodeDocument(CodeDocument *remove_object)
Definition: codegenerator.cpp:150
Uml::RoleType::B
@ B
Definition: basictypes.h:240
CodeGenerator::headingFileDir
QString headingFileDir() const
UMLObject::toString
static QString toString(ObjectType ot)
Definition: umlobject.cpp:1125
CodeGenerator::includeHeadings
bool includeHeadings() const
Uml::AssociationType::Generalization
@ Generalization
Definition: basictypes.h:107
CodeGenerator::getCodeDocumentList
CodeDocumentList * getCodeDocumentList()
Definition: codegenerator.cpp:169
CodeGenerationPolicy::getOverwritePolicy
OverwritePolicy getOverwritePolicy() const
Definition: codegenerationpolicy.cpp:85
UMLApp::app
static UMLApp * app()
Definition: uml.cpp:278
overwritedialog.h
UMLDoc
Definition: umldoc.h:75
UMLAttribute
Sets up attribute information.
Definition: attribute.h:28
UMLClassifier::getAttributeList
UMLAttributeList getAttributeList() const
Definition: classifier.cpp:436
UMLDoc::classesAndInterfaces
UMLClassifierList classesAndInterfaces(bool includeNested=true)
Definition: umldoc.cpp:3014
CodeViewerDialog
Definition: codeviewerdialog.h:28
CodeGenerator::saveToXMI1
virtual void saveToXMI1(QDomDocument &doc, QDomElement &root)
Definition: codegenerator.cpp:245
CodeGenerator::getUniqueID
QString getUniqueID(CodeDocument *codeDoc)
Definition: codegenerator.cpp:78
UMLPackageList
QList< UMLPackage * > UMLPackageList
Definition: umlpackagelist.h:17
codedocument.h
CodeGenerator::m_applyToAllRemaining
bool m_applyToAllRemaining
Definition: codegenerator.h:143
CodeGenerator::codeGenerated
void codeGenerated(UMLClassifier *concept, bool generated)
Definition: moc_codegenerator.cpp:154
CodeGenerator::CodeGenerator
CodeGenerator()
Definition: codegenerator.cpp:52
ClassifierCodeDocument::getParentClassifier
UMLClassifier * getParentClassifier()
Definition: classifiercodedocument.cpp:275
classifier.h
uError
#define uError()
Definition: debug_utils.h:123
UMLOperation
Definition: operation.h:25
CodeDocument::getFileName
QString getFileName() const
Definition: codedocument.cpp:63
uml.h
CodeGenerator::defaultDatatypes
virtual QStringList defaultDatatypes()
Definition: codegenerator.cpp:784
CodeGenerationPolicy::getNewLineEndingChars
QString getNewLineEndingChars() const
Definition: codegenerationpolicy.cpp:253
UMLClassifier
Information for a non-graphical Concept/Class.
Definition: classifier.h:40
debug_utils.h
UMLAssociation
Sets up association information.
Definition: association.h:33
codeviewerstate.h
CodeGenerationPolicy::getOutputDirectory
QDir getOutputDirectory()
Definition: codegenerationpolicy.cpp:211
UMLObject::isUMLDatatype
bool isUMLDatatype()
Definition: umlobject.h:206
CodeGenerator::overwritableName
QString overwritableName(const QString &name, const QString &extension)
Definition: codegenerator.cpp:427
codegenpolicyext.h
umlobject.h
Uml::AssociationType::Composition
@ Composition
Definition: basictypes.h:117
CodeDocument::ID
QString ID() const
Definition: codedocument.cpp:143
CodeGenerator::language
virtual Uml::ProgrammingLanguage::Enum language() const =0
codegenerator.h
UMLObject::asUMLPackage
UMLPackage * asUMLPackage()
Definition: umlobject.cpp:1325
simplecodegenerator.h
uIgnoreZeroPointer
#define uIgnoreZeroPointer(a)
Definition: debug_utils.h:134
UMLObject::ot_Operation
@ ot_Operation
Definition: umlobject.h:93
CodeGenerator
Definition: codegenerator.h:57
OverwriteDialog
Definition: overwritedialog.h:30
CodeGenerator::m_lastIDIndex
int m_lastIDIndex
Definition: codegenerator.h:152
Uml::AssociationType::Dependency
@ Dependency
Definition: basictypes.h:109
CodeGenerator::forceSections
bool forceSections() const
Definition: codegenerator.cpp:775
UMLOperationList
QList< UMLOperation * > UMLOperationList
Definition: umloperationlist.h:18
CodeDocumentList
QList< CodeDocument * > CodeDocumentList
Definition: codedocumentlist.h:17
CodeGenerator::addCodeDocument
bool addCodeDocument(CodeDocument *add_object)
Definition: codegenerator.cpp:125
CodeGenerator::m_document
UMLDoc * m_document
Definition: codegenerator.h:148
CodeGenerator::createDefaultStereotypes
virtual void createDefaultStereotypes()
Definition: codegenerator.cpp:815
CodeGenerator::writeListedCodeDocsToFile
void writeListedCodeDocsToFile(CodeDocumentList *docs)
Definition: codegenerator.cpp:341
CodeDocument::setID
void setID(const QString &new_id)
Definition: codedocument.cpp:134
CodeGenerationPolicy::getCodeVerboseSectionComments
bool getCodeVerboseSectionComments() const
Definition: codegenerationpolicy.cpp:127
UMLAssociationList
QList< UMLAssociation * > UMLAssociationList
Definition: umlassociationlist.h:18
Uml::AssociationType::Realization
@ Realization
Definition: basictypes.h:118
umldoc.h
CodeGenerator::openFile
bool openFile(QFile &file, const QString &name)
Definition: codegenerator.cpp:523
UMLOperation::getSourceCode
QString getSourceCode() const
Definition: operation.cpp:507
UMLPackage
Non-graphical information for a Package.
Definition: package.h:33
CodeGenerator::setIncludeHeadings
void setIncludeHeadings(bool i)