umbrello API Documentation

CodeGenerator Class Reference

CodeGenerator is the base class for all CodeGenerators. More...

#include <codegenerator.h>

Inheritance diagram for CodeGenerator:

SimpleCodeGenerator AdaWriter ASWriter CppWriter CSharpWriter DWriter IDLWriter JavaWriter JSWriter PascalWriter PerlWriter Php5Writer PhpWriter PythonWriter RubyWriter SQLWriter TclWriter XMLSchemaWriter List of all members.

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.
CodeDocumentfindCodeDocumentByID (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 CodeDocumentnewClassifierCodeDocument (UMLClassifier *classifier)=0
virtual void loadFromXMI (QDomElement &element)
virtual CodeDocumentnewCodeDocument ()
 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.
CodeDocumentfindCodeDocumentByClassifier (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 CodeViewerDialoggetCodeViewerDialog (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< CodeDocumentm_codeDocumentDictionary
bool m_applyToAllRemaining
 used by overwriteDialogue to know if the apply to all remaining files checkbox should be checked (is by default)
UMLDocm_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

CodeGenerator::CodeGenerator  ) 
 

Build a code generator.

Returns:
CodeGenerator

Definition at line 57 of file codegenerator.cpp.

CodeGenerator::CodeGenerator QDomElement &  element  ) 
 

Build a code generator and then initialize it from an XMI element.

Returns:
CodeGenerator
Parameters:
element an element from an XMI document

Definition at line 65 of file codegenerator.cpp.

References loadFromXMI().

CodeGenerator::~CodeGenerator  )  [virtual]
 

Empty Destructor.

Definition at line 71 of file codegenerator.cpp.


Member Function Documentation

bool CodeGenerator::addCodeDocument CodeDocument add_object  ) 
 

Add a CodeDocument object to the m_codedocumentVector List.

Returns:
boolean - will return false if it couldnt add a document.

Definition at line 125 of file codegenerator.cpp.

References CodeDocument::getID(), and CodeDocument::setID().

Referenced by checkAddUMLObject(), and initFromParentDocument().

bool CodeGenerator::removeCodeDocument CodeDocument remove_object  ) 
 

Remove a CodeDocument object from m_codedocumentVector List.

Returns:
boolean - will return false if it couldnt remove a document.

Definition at line 148 of file codegenerator.cpp.

References CodeDocument::getID().

CodeDocumentList * CodeGenerator::getCodeDocumentList  ) 
 

Get the list of CodeDocument objects held by m_codedocumentVector.

Returns:
CodeDocumentList list of CodeDocument objects held by m_codedocumentVector

Definition at line 164 of file codegenerator.cpp.

Referenced by saveToXMI().

void CodeGenerator::saveToXMI QDomDocument &  doc,
QDomElement &  root
[virtual]
 

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().

CodeDocument * CodeGenerator::findCodeDocumentByID const QString &  id  ) 
 

Find a code document by the given id string.

Returns:
CodeDocument

Definition at line 116 of file codegenerator.cpp.

Referenced by findCodeDocumentByClassifier(), and loadFromXMI().

void CodeGenerator::writeCodeToFile  )  [virtual]
 

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().

QString CodeGenerator::getHeadingFile const QString &  file  )  [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%

Returns:
QString
Parameters:
file 

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().

QString CodeGenerator::findFileName CodeDocument doc  )  [virtual]
 

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).

Parameters:
doc the CodeDocument for which an output file name is desired.
Returns:
the file name that should be used. (with extension) or NULL if none to be used

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().

QString CodeGenerator::cleanName const QString &  name  )  [static]
 

Replaces spaces with underscores and capitalises as defined in m_modname.

Returns:
QString
Parameters:
name 

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().

QString CodeGenerator::formatDoc const QString &  text,
const QString &  linePrefix = " *",
int  lineWidth = 80
 

Format documentation for output in source files.

Parameters:
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
Returns:
the formatted documentation text

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().

void CodeGenerator::findObjectsRelated UMLClassifier c,
UMLPackageList &  cList
[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

Parameters:
c the class for which relations are to be found
cList a reference to the list into which return the result

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().

void CodeGenerator::loadFromXMI QDomElement &  element  )  [virtual]
 

Parameters:
element 

Definition at line 178 of file codegenerator.cpp.

References findCodeDocumentByID(), getLanguage(), CodeDocument::loadFromXMI(), and Model_Utils::progLangToString().

Referenced by CodeGenerator(), and UMLDoc::loadExtensionsFromXMI().

CodeDocument * CodeGenerator::newCodeDocument  )  [virtual]
 

Create a new Code document belonging to this package.

Returns:
CodeDocument pointer to new code document.

Definition at line 370 of file codegenerator.cpp.

virtual Uml::Programming_Language CodeGenerator::getLanguage  )  [pure virtual]
 

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().

CodeDocument * CodeGenerator::findCodeDocumentByClassifier UMLClassifier classifier  ) 
 

Find a code document by the given classifier.

Returns:
CodeDocument
Parameters:
classifier 

Definition at line 305 of file codegenerator.cpp.

References findCodeDocumentByID().

Referenced by initFromParentDocument(), and UMLApp::viewCodeDocument().

QStringList CodeGenerator::defaultDatatypes  )  [virtual]
 

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().

CodeViewerDialog * CodeGenerator::getCodeViewerDialog QWidget *  parent,
CodeDocument doc,
Settings::CodeViewerState  state
[virtual]
 

Get the editing dialog for this code document.

Definition at line 169 of file codegenerator.cpp.

Referenced by UMLApp::viewCodeDocument().

bool CodeGenerator::isReservedKeyword const QString &  rPossiblyReservedKeyword  )  [virtual]
 

Check whether the given string is a reserved word for the language of this code generator.

Parameters:
rPossiblyReservedKeyword is the string to check

Reimplemented in AdaWriter, and PascalWriter.

Definition at line 705 of file codegenerator.cpp.

References reservedKeywords().

const QStringList CodeGenerator::reservedKeywords  )  const [virtual]
 

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().

void CodeGenerator::createDefaultStereotypes  )  [virtual]
 

Create the default stereotypes for your language (constructor, int etc).

Definition at line 718 of file codegenerator.cpp.

Referenced by UMLDoc::addDefaultStereotypes().

void CodeGenerator::initFromParentDocument  )  [virtual]
 

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().

void CodeGenerator::connect_newcodegen_slots  ) 
 

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().

QString CodeGenerator::overwritableName const QString &  name,
const QString &  extension
[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().

Parameters:
name the proposed output file name
extension the extension to use
Returns:
the real file name that should be used (including extension) or QString::null if none to be used

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().

bool CodeGenerator::openFile QFile &  file,
const QString &  name
[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

Returns:
bool
Parameters:
file 
name 

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().

void CodeGenerator::writeListedCodeDocsToFile CodeDocumentList *  docs  )  [protected]
 

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().

void CodeGenerator::checkAddUMLObject UMLObject obj  )  [virtual, slot]
 

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().

void CodeGenerator::syncCodeToDocument  )  [virtual, slot]
 

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().

void CodeGenerator::codeGenerated UMLClassifier concept,
bool  generated
[signal]
 

This signal is emitted when code for a UMLClassifier has been generated.

Its only really used by the codegenerationwizard to update its progress.

Parameters:
concept The concept which was processed
generated Flag, set to true if generation was successful

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

bool CodeGenerator::m_applyToAllRemaining [protected]
 

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().

UMLDoc* CodeGenerator::m_document [protected]
 

The document object.

Definition at line 373 of file codegenerator.h.


The documentation for this class was generated from the following files:
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:08:04 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003