• Skip to content
  • Skip to link menu
KDE 4.4 API Reference
  • KDE API Reference
  • kdesdk
  • Sitemap
  • Contact Us
 

umbrello/umbrello

CodeGenerator Class Reference

This class collects together all of the code documents which form this project, and generates code for them in a given language. More...

#include <codegenerator.h>

Inheritance diagram for CodeGenerator:
Inheritance graph
[legend]

List of all members.

Public Slots

virtual void checkAddUMLObject (UMLObject *obj)
virtual void checkRemoveUMLObject (UMLObject *obj)
virtual void syncCodeToDocument ()

Signals

void codeGenerated (UMLClassifier *concept, bool generated)

Public Member Functions

 CodeGenerator (QDomElement &element)
 CodeGenerator ()
virtual ~CodeGenerator ()
bool addCodeDocument (CodeDocument *add_object)
void connect_newcodegen_slots ()
virtual void createDefaultStereotypes ()
virtual QStringList defaultDatatypes ()
CodeDocument * findCodeDocumentByClassifier (UMLClassifier *classifier)
CodeDocument * findCodeDocumentByID (const QString &id)
QString findFileName (CodeDocument *codeDocument)
bool forceDoc () const
bool forceSections () const
CodeDocumentList * getCodeDocumentList ()
virtual CodeViewerDialog * getCodeViewerDialog (QWidget *parent, CodeDocument *doc, Settings::CodeViewerState state)
virtual QString getHeadingFile (const QString &file)
virtual Uml::Programming_Language getLanguage ()=0
QString getUniqueID (CodeDocument *codeDoc)
QString headingFileDir () const
bool includeHeadings () const
virtual void initFromParentDocument ()
virtual bool isReservedKeyword (const QString &keyword)
virtual void loadFromXMI (QDomElement &element)
CodeGenerationPolicy::ModifyNamePolicy modifyNamePolicy () const
virtual CodeDocument * newClassifierCodeDocument (UMLClassifier *classifier)=0
virtual CodeDocument * newCodeDocument ()
bool removeCodeDocument (CodeDocument *remove_object)
virtual const QStringList reservedKeywords () const
virtual void saveToXMI (QDomDocument &doc, QDomElement &root)
void setForceDoc (bool f)
void setForceSections (bool f)
void setHeadingFileDir (const QString &)
void setIncludeHeadings (bool i)
void setModifyNamePolicy (CodeGenerationPolicy::ModifyNamePolicy p)
virtual void writeCodeToFile (UMLClassifierList &list)
virtual void writeCodeToFile ()

Static Public Member Functions

static QString cleanName (const QString &name)
static void findObjectsRelated (UMLClassifier *c, UMLPackageList &cList)
static QString formatDoc (const QString &text, const QString &linePrefix=" *", int lineWidth=80)
static QString formatSourceCode (const QString &code, const QString &indentation)

Protected Member Functions

bool openFile (QFile &file, const QString &name)
QString overwritableName (const QString &name, const QString &extension)
void writeListedCodeDocsToFile (CodeDocumentList *docs)

Protected Attributes

bool m_applyToAllRemaining
QHash< QString, CodeDocument * > m_codeDocumentDictionary
UMLDoc * m_document

Static Protected Attributes

static const char * hierarchicalCodeBlockNodeName

Detailed Description

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

Note for "simple" code generators: Code can be entered into a QTextEdit widget in the ClassPropDlg. This code is then stored in the respective UMLOperation, written to the xmi file, and also used when generating the source files. The code fragments are stored into the xmi file in the section "codegeneration" with the tag "sourcecode".

Definition at line 68 of file codegenerator.h.


Constructor & Destructor Documentation

CodeGenerator::CodeGenerator (  ) 

Constructor for a code generator.

Definition at line 54 of file codegenerator.cpp.

CodeGenerator::CodeGenerator ( QDomElement &  element  ) 

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

FIX: hmm. this should be pure virtual so that implemented in sub-class.

Parameters:
element an element from an XMI document

Definition at line 65 of file codegenerator.cpp.

CodeGenerator::~CodeGenerator (  )  [virtual]

Destructor.

Definition at line 75 of file codegenerator.cpp.


Member Function Documentation

bool CodeGenerator::addCodeDocument ( CodeDocument *  doc  ) 

Add a CodeDocument object to the m_codedocumentVector List.

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

Definition at line 130 of file codegenerator.cpp.

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

These 2 functions check for adding or removing objects to the UMLDocument.

Reimplemented in CPPCodeGenerator.

Definition at line 348 of file codegenerator.cpp.

void CodeGenerator::checkRemoveUMLObject ( UMLObject *  obj  )  [virtual, slot]

Reimplemented in CPPCodeGenerator.

Definition at line 360 of file codegenerator.cpp.

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 590 of file codegenerator.cpp.

void CodeGenerator::codeGenerated ( UMLClassifier *  concept,
bool  generated 
) [signal]
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 810 of file codegenerator.cpp.

void CodeGenerator::createDefaultStereotypes (  )  [virtual]

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

Reimplemented in CPPCodeGenerator.

Definition at line 877 of file codegenerator.cpp.

QStringList CodeGenerator::defaultDatatypes (  )  [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.

Definition at line 849 of file codegenerator.cpp.

CodeDocument * CodeGenerator::findCodeDocumentByClassifier ( UMLClassifier *  classifier  ) 

Find a code document by the given classifier.

Returns:
CodeDocument
Parameters:
classifier 

Definition at line 373 of file codegenerator.cpp.

CodeDocument * CodeGenerator::findCodeDocumentByID ( const QString &  tag  ) 

Find a code document by the given id string.

Returns:
CodeDocument

Definition at line 117 of file codegenerator.cpp.

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

Parameters:
codeDocument 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 606 of file codegenerator.cpp.

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 666 of file codegenerator.cpp.

bool CodeGenerator::forceDoc (  )  const

Definition at line 830 of file codegenerator.cpp.

bool CodeGenerator::forceSections (  )  const

Definition at line 840 of file codegenerator.cpp.

QString CodeGenerator::formatDoc ( const QString &  text,
const QString &  linePrefix = " *",
int  lineWidth = 80 
) [static]

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 749 of file codegenerator.cpp.

QString CodeGenerator::formatSourceCode ( const QString &  code,
const QString &  indentation 
) [static]

Format source code for output in source files by adding the correct indentation to every line of code.

Parameters:
code the source code block which has to be formatted
indentation the blanks to indent

Definition at line 779 of file codegenerator.cpp.

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 171 of file codegenerator.cpp.

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

Get the editing dialog for this code document.

Reimplemented in CPPCodeGenerator, DCodeGenerator, JavaCodeGenerator, and RubyCodeGenerator.

Definition at line 181 of file codegenerator.cpp.

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 471 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, CPPCodeGenerator, CppWriter, CSharpWriter, DCodeGenerator, DWriter, IDLWriter, JavaCodeGenerator, JavaWriter, JSWriter, PascalWriter, PerlWriter, Php5Writer, PhpWriter, PythonWriter, RubyCodeGenerator, RubyWriter, MySQLWriter, PostgreSQLWriter, SQLWriter, TclWriter, ValaWriter, and XMLSchemaWriter.

QString CodeGenerator::getUniqueID ( CodeDocument *  codeDoc  ) 

Get a unique id for this codedocument.

Returns:
id for the codedocument

Definition at line 86 of file codegenerator.cpp.

QString CodeGenerator::headingFileDir (  )  const
bool CodeGenerator::includeHeadings (  )  const
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.

In this 'generic' version a ClassifierCodeDocument will exist for each and every classifier that exists in our UMLDoc. IF when this is called, a code document doesn't exist for the given classifier, then we will created and add a new code document to our generator.

IF you want to add non-classifier related code documents at this step, you will need to overload this method in the appropriate code generatator (see JavaCodeGenerator for an example of this).

Reimplemented in CPPCodeGenerator, and SimpleCodeGenerator.

Definition at line 314 of file codegenerator.cpp.

bool CodeGenerator::isReservedKeyword ( const QString &  keyword  )  [virtual]

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

Parameters:
keyword string to check

Reimplemented in AdaWriter, and PascalWriter.

Definition at line 862 of file codegenerator.cpp.

void CodeGenerator::loadFromXMI ( QDomElement &  qElement  )  [virtual]

Load codegenerator data from xmi.

Parameters:
qElement the element from which to load

Definition at line 191 of file codegenerator.cpp.

CodeGenerationPolicy::ModifyNamePolicy CodeGenerator::modifyNamePolicy (  )  const
virtual CodeDocument* CodeGenerator::newClassifierCodeDocument ( UMLClassifier *  classifier  )  [pure virtual]

A series of accessor method constructors that we need to define for any particular language.

Implemented in CPPCodeGenerator, DCodeGenerator, JavaCodeGenerator, RubyCodeGenerator, and SimpleCodeGenerator.

CodeDocument * CodeGenerator::newCodeDocument (  )  [virtual]

Create a new Code document belonging to this package.

Returns:
CodeDocument pointer to new code document.

Definition at line 447 of file codegenerator.cpp.

bool CodeGenerator::openFile ( QFile &  file,
const QString &  fileName 
) [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.

Parameters:
file file descriptor
fileName the name of the file
Returns:
success state

Definition at line 568 of file codegenerator.cpp.

QString CodeGenerator::overwritableName ( const QString &  name,
const QString &  extension 
) [protected]

Remove (and possibly delete) all AutoGenerated content type CodeDocuments but leave the UserGenerated (and any other type) documents in this generator alone.

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() if none to be used

Definition at line 491 of file codegenerator.cpp.

bool CodeGenerator::removeCodeDocument ( CodeDocument *  remove_object  ) 

Replace (or possibly add a new) CodeDocument object to the m_codedocumentVector List.

Remove a CodeDocument object from m_codedocumentVector List.

As names must be unique and each code document must have a name.

Returns:
boolean value which will be true if the passed document was able to replace some other document OR was added(no prior document existed..only when addIfPriorDocumentNotPresent is true). The document which was replaced will be deleted IF deleteReplacedDocument is true.
boolean - will return false if it couldnt remove a document

Definition at line 154 of file codegenerator.cpp.

const QStringList CodeGenerator::reservedKeywords (  )  const [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.

Definition at line 868 of file codegenerator.cpp.

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

Save the XMI representation of this object.

Reimplemented in CPPCodeGenerator.

Definition at line 261 of file codegenerator.cpp.

void CodeGenerator::setForceDoc ( bool  f  ) 

Definition at line 825 of file codegenerator.cpp.

void CodeGenerator::setForceSections ( bool  f  ) 

Definition at line 835 of file codegenerator.cpp.

void CodeGenerator::setHeadingFileDir ( const QString &   ) 
void CodeGenerator::setIncludeHeadings ( bool  i  ) 
void CodeGenerator::setModifyNamePolicy ( CodeGenerationPolicy::ModifyNamePolicy  p  ) 
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 CPPCodeGenerator, and SimpleCodeGenerator.

Definition at line 336 of file codegenerator.cpp.

void CodeGenerator::writeCodeToFile ( UMLClassifierList &  list  )  [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.

Definition at line 393 of file codegenerator.cpp.

void CodeGenerator::writeCodeToFile (  )  [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.

Definition at line 383 of file codegenerator.cpp.

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

The actual internal routine which writes code documents.

Definition at line 411 of file codegenerator.cpp.


Member Data Documentation

const char* CodeGenerator::hierarchicalCodeBlockNodeName [static, protected]

Definition at line 191 of file codegenerator.h.

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 200 of file codegenerator.h.

QHash<QString, CodeDocument*> CodeGenerator::m_codeDocumentDictionary [protected]

Definition at line 194 of file codegenerator.h.

UMLDoc* CodeGenerator::m_document [protected]

The document object.

Definition at line 205 of file codegenerator.h.


The documentation for this class was generated from the following files:
  • codegenerator.h
  • codegenerator.cpp

umbrello/umbrello

Skip menu "umbrello/umbrello"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdesdk

Skip menu "kdesdk"
  • kapptemplate
  • kate
  •     kate
  • kbugbuster
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello
Generated for kdesdk by doxygen 1.5.9-20090814
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal