umbrello 25.04.1
Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology
|
#include <codegenerator.h>
Public Types | |
enum | GenerationState { Generated , Failed , Skipped } |
Public Slots | |
virtual void | syncCodeToDocument () |
Signals | |
void | codeGenerated (UMLClassifier *classifier, bool generated) |
void | codeGenerated (UMLClassifier *classifier, CodeGenerator::GenerationState result) |
void | showGeneratedFile (const QString &filename) |
Static Public Member Functions | |
static QString | cleanName (const QString &name) |
static QString | formatDoc (const QString &text, const QString &linePrefix=QStringLiteral(" *"), int lineWidth=80) |
static QString | formatFullDocBlock (const QString &text, const QString &blockHeader=QStringLiteral("/* "), const QString &blockFooter=QStringLiteral(" */"), const QString &linePrefix=QStringLiteral(" *"), int lineWidth=80) |
static QString | formatSourceCode (const QString &code, const QString &indentation) |
static void | findObjectsRelated (UMLClassifier *c, UMLPackageList &cList) |
Protected Member Functions | |
QString | overwritableName (const QString &name, const QString &extension) |
bool | openFile (QFile &file, const QString &name) |
void | writeListedCodeDocsToFile (CodeDocumentList *docs) |
virtual void | finalizeRun () |
Protected Attributes | |
QHash< QString, CodeDocument * > | m_codeDocumentDictionary |
bool | m_applyToAllRemaining |
UMLDoc * | m_document |
Private Member Functions | |
void | loadCodeForOperation (const QString &id, const QDomElement &codeDocElement) |
Private Attributes | |
CodeDocumentList | m_codedocumentVector |
int | m_lastIDIndex |
This class collects together all of the code documents which form this project, and generates code for them in a given language.
CodeGenerator is the abstract base class for all types of code generators. It provides the interface through which all generators are invoked and provides most of the basic functionality.
If you want to implement a CodeGenerator for some language follow these steps:
Create a class which inherits SimpleCodeGenerator or AdvancedCodeGenerator. This class can have any name, I use names like CppCodeGenerator for the Cpp Generator, JavaCodeGenerator for the Java Generator and so on, but you can use what you want.
The code you generate should be output to getOutputDirectory() of the CodeGenerationPolicy instance and you should respect the OverwritePolicy specified. You should call findFileName(..) to get an appropriate file name, and then you can call openFile() and write the generated content to this file.
CodeGenerator::CodeGenerator | ( | ) |
Constructor for a code generator.
|
virtual |
Destructor.
bool CodeGenerator::addCodeDocument | ( | CodeDocument * | doc | ) |
Add a CodeDocument object to the m_codedocumentVector List.
|
static |
Replaces spaces with underscores and capitalises as defined in m_modname
name |
|
signal |
|
signal |
|
virtual |
Create the default stereotypes for your language (constructor, int etc).
Reimplemented in CPPCodeGenerator.
|
virtual |
Return the default datatypes for your language (bool, int etc). Default implementation returns empty list.
Reimplemented in AdaWriter, CPPCodeGenerator, CppWriter, CSharpWriter, DCodeGenerator, DWriter, IDLWriter, JavaCodeGenerator, JavaWriter, PascalWriter, PerlWriter, PythonWriter, MySQLWriter, PostgreSQLWriter, SQLWriter, and ValaWriter.
|
protectedvirtual |
A single call to writeCodeToFile() usually entails processing many items (e.g. as classifiers) for which code is generated. This method is called after all code of one call to writeCodeToFile() has been generated. It can be reimplemented by concrete code generators to perform additional cleanups or other actions that can only be performed once all code has been written.
Reimplemented in AdaWriter.
CodeDocument * CodeGenerator::findCodeDocumentByClassifier | ( | UMLClassifier * | classifier | ) |
Find a code document by the given classifier. NOTE: FIX, this should be 'protected' or we could have problems with CPP code generator
classifier |
CodeDocument * CodeGenerator::findCodeDocumentByID | ( | const QString & | tag | ) |
Find a code document by the given id string.
QString CodeGenerator::findFileName | ( | CodeDocument * | codeDocument | ) |
Finds an appropriate file name for the given CodeDocument, taking into account the Overwrite Policy and asking the user what to do if need be (if policy == Ask).
codeDocument | the CodeDocument for which an output file name is desired. |
|
static |
Finds all classes in the current document to which objects of class c are in some way related. Possible relations are Associations (generalization, composition, etc) as well as parameters to methods and return values this is useful in deciding which classes/files to import/include in code generation
c | the class for which relations are to be found |
cList | a reference to the list into which return the result |
bool CodeGenerator::forceDoc | ( | ) | const |
bool CodeGenerator::forceSections | ( | ) | const |
|
static |
Format documentation for output in source files
text | the documentation which has to be formatted |
linePrefix | the prefix which has to be added in the beginnig of each line |
lineWidth | the line width used for word-wrapping the documentation |
|
static |
Format full documentation block for output in source files
text | the documentation which has to be formatted |
blockHeader | the prefix which has to be added in the beginning of each line (instead of the first) |
blockFooter | the prefix which has to be added in the beginning of each line (instead of the first) |
linePrefix | the prefix which has to be added in the beginning of each line (instead of the first) |
lineWidth | the line width used for word-wrapping the documentation |
|
static |
Format source code for output in source files by adding the correct indentation to every line of code.
code | the source code block which has to be formatted |
indentation | the blanks to indent |
CodeDocumentList * CodeGenerator::getCodeDocumentList | ( | ) |
Get the list of CodeDocument objects held by m_codedocumentVector.
|
virtual |
Gets the heading file (as a string) to be inserted at the beginning of the generated file. you give the file type as parameter and get the string. if fileName starts with a period (.) then fileName is the extension (.cpp, .h, .java) if fileName starts with another character you are requesting a specific file (mylicensefile.txt). The files can have parameters which are denoted by parameter%.
current parameters are author% date% time% filepath%
file |
QString CodeGenerator::getUniqueID | ( | CodeDocument * | codeDoc | ) |
Get a unique id for this codedocument.
QString CodeGenerator::headingFileDir | ( | ) | const |
bool CodeGenerator::includeHeadings | ( | ) | const |
|
pure virtual |
Initialize this code generator from its parent UMLDoc.
Implemented in AdvancedCodeGenerator, CPPCodeGenerator, and SimpleCodeGenerator.
|
virtual |
Check whether the given string is a reserved word for the language of this code generator.
keyword | string to check |
Reimplemented in AdaWriter, and PascalWriter.
|
pure virtual |
Return the unique language enum that identifies this type of code generator.
Implemented in AdaWriter, ASWriter, CPPCodeGenerator, CppWriter, CSharpWriter, DCodeGenerator, DWriter, IDLWriter, JavaCodeGenerator, JavaWriter, JSWriter, PascalWriter, PerlWriter, Php5Writer, PhpWriter, PythonWriter, RubyCodeGenerator, RubyWriter, MySQLWriter, PostgreSQLWriter, SQLWriter, TclWriter, ValaWriter, and XMLSchemaWriter.
|
private |
Extract and load code for operations from xmi section. Probably we have code which was entered in classpropdlg for an operation.
|
virtual |
A series of accessor method constructors that we need to define for any particular language.
Load codegenerator data from xmi.
qElement | the element from which to load |
|
protected |
Opens a file named "name" for writing in the outputDirectory. If something goes wrong, it informs the user if this function returns true, you know you can write to the file.
file | file descriptor |
fileName | the name of the file |
|
protected |
Returns a name that can be written to in the output directory, respecting the overwrite policy. If a file of the given name and extension does not exist, then just returns the name. If a file of the given name and extension does exist, then opens an overwrite dialog. In this case the name returned may be a modification of the input name. This method is invoked by findFileName().
name | the proposed output file name |
extension | the extension to use |
bool CodeGenerator::removeCodeDocument | ( | CodeDocument * | remove_object | ) |
Remove a CodeDocument object from m_codedocumentVector List.
|
virtual |
Get list of reserved keywords.
Reimplemented in AdaWriter, ASWriter, CPPCodeGenerator, CppWriter, CSharpWriter, DCodeGenerator, IDLWriter, JavaCodeGenerator, JSWriter, PascalWriter, PerlWriter, Php5Writer, PhpWriter, PythonWriter, RubyCodeGenerator, RubyWriter, SQLWriter, TclWriter, ValaWriter, and XMLSchemaWriter.
|
virtual |
Save the XMI representation of this object
Reimplemented in CPPCodeGenerator.
void CodeGenerator::setForceDoc | ( | bool | f | ) |
void CodeGenerator::setHeadingFileDir | ( | const QString & | ) |
void CodeGenerator::setIncludeHeadings | ( | bool | i | ) |
void CodeGenerator::setSectionCommentPolicy | ( | CodeGenerationPolicy::WriteSectionCommentsPolicy | f | ) |
|
signal |
|
virtualslot |
Force a synchronize of this code generator, and its present contents, to that of the parent UMLDocument. "UserGenerated" code will be preserved, but Autogenerated contents will be updated/replaced or removed as is apppropriate.
|
virtual |
This method is here to provide class wizard the ability to write out only those classes which are selected by the user.
Reimplemented in CPPCodeGenerator, and SimpleCodeGenerator.
|
virtual |
This method is here to provide class wizard the ability to write out only those classes which are selected by the user.
Reimplemented in SimpleCodeGenerator, and CPPCodeGenerator.
|
protected |
The actual internal routine which writes code documents.
|
protected |
Used by OverwriteDialog to know if the apply to all remaining files checkbox should be checked (is by default).
|
protected |
|
private |
|
protected |
The document object.
|
private |