CodeGenerator Class Reference
CodeGenerator is the base class for all CodeGenerators. More...
#include <codegenerator.h>
Inheritance diagram for CodeGenerator:

Public Slots | |
| virtual void | checkAddUMLObject (UMLObject *obj) |
| These 2 functions check for adding or removing objects to the UMLDocument. | |
| virtual void | checkRemoveUMLObject (UMLObject *obj) |
| virtual void | syncCodeToDocument () |
| Force a synchronize of this code generator, and its present contents, to that of the parent UMLDocument. | |
Signals | |
| void | codeGenerated (UMLClassifier *concept, bool generated) |
| This signal is emitted when code for a UMLClassifier has been generated. | |
Public Member Functions | |
| CodeGenerator () | |
| Build a code generator. | |
| CodeGenerator (QDomElement &element) | |
| Build a code generator and then initialize it from an XMI element. | |
| virtual | ~CodeGenerator () |
| Empty Destructor. | |
| bool | addCodeDocument (CodeDocument *add_object) |
| Add a CodeDocument object to the m_codedocumentVector List. | |
| bool | removeCodeDocument (CodeDocument *remove_object) |
| Remove a CodeDocument object from m_codedocumentVector List. | |
| CodeDocumentList * | getCodeDocumentList () |
| Get the list of CodeDocument objects held by m_codedocumentVector. | |
| QString | getUniqueID (CodeDocument *codeDoc) |
| virtual void | saveToXMI (QDomDocument &doc, QDomElement &root) |
| Save the XMI representation of this object. | |
| CodeDocument * | findCodeDocumentByID (const QString &id) |
| Find a code document by the given id string. | |
| virtual void | writeCodeToFile () |
| Write out all code documents to file as appropriate. | |
| virtual void | writeCodeToFile (UMLClassifierList &list) |
| void | setModifyNamePolicy (CodeGenerationPolicy::ModifyNamePolicy p) |
| CodeGenerationPolicy::ModifyNamePolicy | modifyNamePolicy () const |
| void | setIncludeHeadings (bool i) |
| bool | includeHeadings () const |
| void | setHeadingFileDir (const QString &) |
| QString | headingFileDir () const |
| void | setForceDoc (bool f) |
| bool | forceDoc () const |
| void | setForceSections (bool f) |
| bool | forceSections () const |
| virtual QString | getHeadingFile (const QString &file) |
| Gets the heading file (as a string) to be inserted at the beginning of the generated file. | |
| virtual QString | findFileName (CodeDocument *doc) |
| 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). | |
| QString | formatDoc (const QString &text, const QString &linePrefix=" *", int lineWidth=80) |
| Format documentation for output in source files. | |
| virtual CodeDocument * | newClassifierCodeDocument (UMLClassifier *classifier)=0 |
| virtual void | loadFromXMI (QDomElement &element) |
| virtual CodeDocument * | newCodeDocument () |
| Create a new Code document belonging to this package. | |
| virtual Uml::Programming_Language | getLanguage ()=0 |
| Return the unique language enum that identifies this type of code generator. | |
| CodeDocument * | findCodeDocumentByClassifier (UMLClassifier *classifier) |
| Find a code document by the given classifier. | |
| virtual QStringList | defaultDatatypes () |
| Return the default datatypes for your language (bool, int etc) Default implementation returns empty list. | |
| virtual CodeViewerDialog * | getCodeViewerDialog (QWidget *parent, CodeDocument *doc, Settings::CodeViewerState state) |
| Get the editing dialog for this code document. | |
| virtual bool | isReservedKeyword (const QString &rPossiblyReservedKeyword) |
| Check whether the given string is a reserved word for the language of this code generator. | |
| virtual const QStringList | reservedKeywords () const |
| get list of reserved keywords | |
| virtual void | createDefaultStereotypes () |
| Create the default stereotypes for your language (constructor, int etc). | |
| virtual void | initFromParentDocument () |
| Initialize this code generator from its parent UMLDoc. | |
| void | connect_newcodegen_slots () |
| Connect additional slots. | |
Static Public Member Functions | |
| static QString | cleanName (const QString &name) |
| Replaces spaces with underscores and capitalises as defined in m_modname. | |
| static void | findObjectsRelated (UMLClassifier *c, UMLPackageList &cList) |
| Finds all classes in the current document to which objects of class c are in some way related. | |
Protected Member Functions | |
| QString | overwritableName (const QString &name, const QString &extension) |
| Returns a name that can be written to in the output directory, respecting the overwrite policy. | |
| bool | openFile (QFile &file, const QString &name) |
| Opens a file named "name" for writing in the outputDirectory. | |
| void | writeListedCodeDocsToFile (CodeDocumentList *docs) |
| the actual internal routine which writes code documents | |
Protected Attributes | |
| QDict< CodeDocument > | m_codeDocumentDictionary |
| bool | m_applyToAllRemaining |
| used by overwriteDialogue to know if the apply to all remaining files checkbox should be checked (is by default) | |
| UMLDoc * | m_document |
| The document object. | |
Static Protected Attributes | |
| static const char * | hierarchicalCodeBlockNodeName |
Detailed Description
CodeGenerator is the base class for all CodeGenerators.It provides the interface through which all Generators are invoked and the all the basic functionality. The only thing it doesn't do is to generate code =)
If you want to implement a CodeGenerator for some language follow these steps:
Create a class which inherits CodeGenerator. 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 "outputDirectory" and you should respect the OverwritePolicy specified. You should call findFileName(..) to get an appropriate file name, and then you can call openFile if you want, but if you want to do it yourself you
Finally put your generator in a library which can be dlopened together with a factory class (see below) and you are ready to go.
Definition at line 82 of file codegenerator.h.
Constructor & Destructor Documentation
|
|
Build a code generator.
Definition at line 57 of file codegenerator.cpp. |
|
|
Build a code generator and then initialize it from an XMI element.
Definition at line 65 of file codegenerator.cpp. References loadFromXMI(). |
|
|
Empty Destructor.
Definition at line 71 of file codegenerator.cpp. |
Member Function Documentation
|
|
Add a CodeDocument object to the m_codedocumentVector List.
Definition at line 125 of file codegenerator.cpp. References CodeDocument::getID(), and CodeDocument::setID(). Referenced by checkAddUMLObject(), and initFromParentDocument(). |
|
|
Remove a CodeDocument object from m_codedocumentVector List.
Definition at line 148 of file codegenerator.cpp. References CodeDocument::getID(). |
|
|
Get the list of CodeDocument objects held by m_codedocumentVector.
Definition at line 164 of file codegenerator.cpp. Referenced by saveToXMI(). |
|
||||||||||||
|
Save the XMI representation of this object.
Definition at line 217 of file codegenerator.cpp. References getCodeDocumentList(), getLanguage(), Model_Utils::progLangToString(), and CodeDocument::saveToXMI(). Referenced by UMLDoc::saveToXMI(). |
|
|
Find a code document by the given id string.
Definition at line 116 of file codegenerator.cpp. Referenced by findCodeDocumentByClassifier(), and loadFromXMI(). |
|
|
Write out all code documents to file as appropriate.
Reimplemented in SimpleCodeGenerator. Definition at line 313 of file codegenerator.cpp. References writeListedCodeDocsToFile(). Referenced by UMLApp::generateAllCode(). |
|
|
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%
Definition at line 380 of file codegenerator.cpp. References UMLApp::getCommonPolicy(), and CodeGenerationPolicy::getHeadingFile(). Referenced by XMLSchemaWriter::writeClass(), SQLWriter::writeClass(), RubyWriter::writeClass(), PythonWriter::writeClass(), PhpWriter::writeClass(), Php5Writer::writeClass(), PerlWriter::writeClass(), PascalWriter::writeClass(), JSWriter::writeClass(), JavaWriter::writeClass(), IDLWriter::writeClass(), DWriter::writeClass(), CSharpWriter::writeClass(), ASWriter::writeClass(), and AdaWriter::writeClass(). |
|
|
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).
Definition at line 492 of file codegenerator.cpp. References UMLApp::getCommonPolicy(), CodeGenerationPolicy::getOutputDirectory(), and overwritableName(). Referenced by XMLSchemaWriter::writeClass(), TclWriter::writeClass(), SQLWriter::writeClass(), RubyWriter::writeClass(), PythonWriter::writeClass(), PhpWriter::writeClass(), Php5Writer::writeClass(), PerlWriter::writeClass(), JSWriter::writeClass(), JavaWriter::writeClass(), IDLWriter::writeClass(), DWriter::writeClass(), CSharpWriter::writeClass(), CppWriter::writeClass(), ASWriter::writeClass(), and writeListedCodeDocsToFile(). |
|
|
Replaces spaces with underscores and capitalises as defined in m_modname.
Definition at line 486 of file codegenerator.cpp. Referenced by CodeDocument::cleanName(), CPPHeaderCodeDocument::updateContent(), TclWriter::writeClass(), SQLWriter::writeClass(), RubyWriter::writeClass(), PythonWriter::writeClass(), PhpWriter::writeClass(), Php5Writer::writeClass(), PerlWriter::writeClass(), PascalWriter::writeClass(), JSWriter::writeClass(), JavaWriter::writeClass(), IDLWriter::writeClass(), DWriter::writeClass(), CSharpWriter::writeClass(), CppWriter::writeClass(), ASWriter::writeClass(), and AdaWriter::writeClass(). |
|
||||||||||||||||
|
Format documentation for output in source files.
Definition at line 630 of file codegenerator.cpp. References UMLApp::getCommonPolicy(), and CodeGenerationPolicy::getNewLineEndingChars(). Referenced by SQLWriter::writeClass(), PythonWriter::writeClass(), PascalWriter::writeClass(), IDLWriter::writeClass(), and AdaWriter::writeClass(). |
|
||||||||||||
|
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
Definition at line 547 of file codegenerator.cpp. References UMLObject::getBaseType(), UMLOperation::getParmList(), and UMLClassifierListItem::getType(). Referenced by CPPHeaderCodeDocument::updateContent(), PythonWriter::writeClass(), PhpWriter::writeClass(), Php5Writer::writeClass(), PascalWriter::writeClass(), JSWriter::writeClass(), JavaWriter::writeClass(), IDLWriter::writeClass(), CSharpWriter::writeClass(), ASWriter::writeClass(), and AdaWriter::writeClass(). |
|
|
Definition at line 178 of file codegenerator.cpp. References findCodeDocumentByID(), getLanguage(), CodeDocument::loadFromXMI(), and Model_Utils::progLangToString(). Referenced by CodeGenerator(), and UMLDoc::loadExtensionsFromXMI(). |
|
|
Create a new Code document belonging to this package.
Definition at line 370 of file codegenerator.cpp. |
|
|
Return the unique language enum that identifies this type of code generator.
Implemented in AdaWriter, ASWriter, CppWriter, CSharpWriter, DWriter, IDLWriter, JavaWriter, JSWriter, PascalWriter, PerlWriter, Php5Writer, PhpWriter, PythonWriter, RubyWriter, SQLWriter, TclWriter, and XMLSchemaWriter. Referenced by loadFromXMI(), UMLApp::newDocument(), UMLApp::saveOptions(), saveToXMI(), UMLApp::setGenerator(), and UMLApp::slotImportClasses(). |
|
|
Find a code document by the given classifier.
Definition at line 305 of file codegenerator.cpp. References findCodeDocumentByID(). Referenced by initFromParentDocument(), and UMLApp::viewCodeDocument(). |
|
|
Return the default datatypes for your language (bool, int etc) Default implementation returns empty list.
Reimplemented in AdaWriter, CppWriter, CSharpWriter, DWriter, IDLWriter, JavaWriter, PascalWriter, PerlWriter, and SQLWriter. Definition at line 700 of file codegenerator.cpp. Referenced by UMLDoc::addDefaultDatatypes(), and Model_Utils::isCommonDataType(). |
|
||||||||||||||||
|
Get the editing dialog for this code document.
Definition at line 169 of file codegenerator.cpp. Referenced by UMLApp::viewCodeDocument(). |
|
|
Check whether the given string is a reserved word for the language of this code generator.
Reimplemented in AdaWriter, and PascalWriter. Definition at line 705 of file codegenerator.cpp. References reservedKeywords(). |
|
|
get list of reserved keywords
Reimplemented in AdaWriter, ASWriter, CppWriter, CSharpWriter, IDLWriter, JSWriter, PascalWriter, PerlWriter, Php5Writer, PhpWriter, PythonWriter, RubyWriter, SQLWriter, TclWriter, and XMLSchemaWriter. Definition at line 712 of file codegenerator.cpp. Referenced by isReservedKeyword(). |
|
|
Create the default stereotypes for your language (constructor, int etc).
Definition at line 718 of file codegenerator.cpp. Referenced by UMLDoc::addDefaultStereotypes(). |
|
|
Initialize this code generator from its parent UMLDoc. When this is called, it will (re-)generate the list of code documents for this project (generator) by checking for new objects/attributes which have been added or changed in the document. One or more CodeDocuments will be created/overwritten/amended as is appropriate for the given language. Reimplemented in SimpleCodeGenerator. Definition at line 244 of file codegenerator.cpp. References addCodeDocument(), findCodeDocumentByClassifier(), UMLDoc::getClassesAndInterfaces(), and UMLApp::getDocument(). Referenced by CodeGenFactory::createObject(). |
|
|
Connect additional slots. Only required for Advanced Code Generators. To be called after constructing the code generator (see CodeGenFactory) Definition at line 670 of file codegenerator.cpp. References checkAddUMLObject(), UMLApp::getCommonPolicy(), UMLApp::getDocument(), and syncCodeToDocument(). Referenced by CodeGenFactory::createObject(). |
|
||||||||||||
|
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().
Definition at line 389 of file codegenerator.cpp. References UMLApp::getCommonPolicy(), CodeGenerationPolicy::getOutputDirectory(), CodeGenerationPolicy::getOverwritePolicy(), m_applyToAllRemaining, and CodeGenerationPolicy::setOverwritePolicy(). Referenced by findFileName(), PascalWriter::writeClass(), and AdaWriter::writeClass(). |
|
||||||||||||
|
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
Definition at line 464 of file codegenerator.cpp. References UMLApp::getCommonPolicy(), and CodeGenerationPolicy::getOutputDirectory(). Referenced by XMLSchemaWriter::writeClass(), TclWriter::writeClass(), SQLWriter::writeClass(), RubyWriter::writeClass(), PythonWriter::writeClass(), PhpWriter::writeClass(), Php5Writer::writeClass(), PerlWriter::writeClass(), PascalWriter::writeClass(), JSWriter::writeClass(), JavaWriter::writeClass(), IDLWriter::writeClass(), DWriter::writeClass(), CSharpWriter::writeClass(), CppWriter::writeClass(), ASWriter::writeClass(), AdaWriter::writeClass(), and writeListedCodeDocsToFile(). |
|
|
the actual internal routine which writes code documents
Definition at line 333 of file codegenerator.cpp. References codeGenerated(), findFileName(), ClassifierCodeDocument::getParentClassifier(), openFile(), and CodeDocument::toString(). Referenced by writeCodeToFile(). |
|
|
These 2 functions check for adding or removing objects to the UMLDocument.
Definition at line 275 of file codegenerator.cpp. References addCodeDocument(). Referenced by connect_newcodegen_slots(). |
|
|
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. Reimplemented in SimpleCodeGenerator. Definition at line 268 of file codegenerator.cpp. References CodeDocument::synchronize(). Referenced by connect_newcodegen_slots(). |
|
||||||||||||
|
This signal is emitted when code for a UMLClassifier has been generated. Its only really used by the codegenerationwizard to update its progress.
Referenced by XMLSchemaWriter::writeClass(), TclWriter::writeClass(), SQLWriter::writeClass(), RubyWriter::writeClass(), PythonWriter::writeClass(), PhpWriter::writeClass(), Php5Writer::writeClass(), PerlWriter::writeClass(), PascalWriter::writeClass(), JSWriter::writeClass(), JavaWriter::writeClass(), IDLWriter::writeClass(), DWriter::writeClass(), CSharpWriter::writeClass(), CppWriter::writeClass(), ASWriter::writeClass(), AdaWriter::writeClass(), and writeListedCodeDocsToFile(). |
Member Data Documentation
|
|
used by overwriteDialogue to know if the apply to all remaining files checkbox should be checked (is by default)
Definition at line 368 of file codegenerator.h. Referenced by overwritableName(). |
|
|
The document object.
Definition at line 373 of file codegenerator.h. |
The documentation for this class was generated from the following files:
