summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/codegenerator.cpp
blob: ea9bea43ed26afaf58b75bee7bece2ccd5377c6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   copyright (C) 2004-2007                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

/*  This code generated by:
 *      Author : thomas
 *      Date   : Thu Jun 19 2003
 */

// own header
#include "codegenerator.h"

// system includes
#include <cstdlib> //to get the user name

// qt includes
#include <tqdatetime.h>
#include <tqregexp.h>
#include <tqdir.h>
#include <tqtextstream.h>

// kde includes
#include <kdebug.h>
#include <tdelocale.h>
#include <tdemessagebox.h>
#include <kdialogbase.h>
#include <tdeapplication.h>

// app includes
#include "dialogs/overwritedialogue.h"
#include "dialogs/codeviewerdialog.h"
#include "codegenerators/simplecodegenerator.h"
#include "attribute.h"
#include "association.h"
#include "classifier.h"
#include "classifiercodedocument.h"
#include "codedocument.h"
#include "codegenerationpolicy.h"
#include "operation.h"
#include "uml.h"
#include "umldoc.h"
#include "umlobject.h"
#include "umlattributelist.h"
#include "umloperationlist.h"
#include "model_utils.h"

// Constructors/Destructors
//

CodeGenerator::CodeGenerator ()
        : TQObject (UMLApp::app()->getDocument())
{
    initFields();
}

// FIX
// hmm. this should be pure virtual so that implemented in sub-class
CodeGenerator::CodeGenerator (TQDomElement & element )
        : TQObject (UMLApp::app()->getDocument()) {
    initFields();
    loadFromXMI(element); // hmm. cant call this here.. its 'pure' virtual
}

CodeGenerator::~CodeGenerator ( ) {
    // destroy all owned codedocuments
    CodeDocument *doc;
    for (CodeDocumentListIt it(m_codedocumentVector);
                     (doc = it.current()) != NULL; ++it)
        delete doc;
    m_codedocumentVector.clear();
}

//
// Methods
//


// Accessor methods
//

TQString CodeGenerator::getUniqueID(CodeDocument * codeDoc)
{

    TQString id = codeDoc->getID();

    // does this document already exist? then just return its present id
    if (!id.isEmpty() && findCodeDocumentByID(id))
        return id;

    // approach now differs by whether or not its a classifier code document
    ClassifierCodeDocument * classDoc = dynamic_cast<ClassifierCodeDocument*>(codeDoc);
    if(classDoc) {
        UMLClassifier *c = classDoc->getParentClassifier();
        id = ID2STR(c->getID()); // this is supposed to be unique already..
    } else {

        TQString prefix = "doc";
        TQString id = prefix + "_0";
        int number = lastIDIndex;
        for ( ; findCodeDocumentByID(id); number++) {
            id = prefix + '_' + TQString::number(number);
        }
        lastIDIndex = number;
    }

    return id;
}

CodeDocument * CodeGenerator::findCodeDocumentByID( const TQString &tag ) {
    //if we already know to which file this class was written/should be written, just return it.
    CodeDocument * doc = (CodeDocument*)NULL;
    if((doc = m_codeDocumentDictionary.find(tag)))
        return doc;

    return doc;
}

bool CodeGenerator::addCodeDocument ( CodeDocument * doc )
{
    TQString tag = doc->getID();

    // assign a tag if one doesn't already exist
    if(tag.isEmpty())
    {
        tag = getUniqueID(doc);
        doc->setID(tag);
    }

    if(m_codeDocumentDictionary.find(tag))
        return false; // return false, we already have some object with this tag in the list
    else
        m_codeDocumentDictionary.insert(tag, doc);

    m_codedocumentVector.append(doc);
    return true;
}

/**
 * Remove a CodeDocument object from m_codedocumentVector List
 */
bool CodeGenerator::removeCodeDocument ( CodeDocument * remove_object ) {
    TQString tag = remove_object->getID();
    if(!(tag.isEmpty()))
        m_codeDocumentDictionary.remove(tag);
    else
        return false;

    m_codedocumentVector.remove(remove_object);
    return true;
}

/**
 * Get the list of CodeDocument objects held by m_codedocumentVector
 * @return TQPtrList<CodeDocument *> list of CodeDocument objects held by
 * m_codedocumentVector
 */
CodeDocumentList * CodeGenerator::getCodeDocumentList ( ) {
    return &m_codedocumentVector;
}

// the vanilla version
CodeViewerDialog * CodeGenerator::getCodeViewerDialog ( TQWidget* parent, CodeDocument *doc,
        Settings::CodeViewerState state)
{
    return new CodeViewerDialog(parent, doc, state);
}

// Other methods
//

void CodeGenerator::loadFromXMI (TQDomElement & qElement ) {

    // don't do anything for simple (compatability) code generators
    if(dynamic_cast<SimpleCodeGenerator*>(this))
        return;

    //now look for our particular child element
    TQDomNode node = qElement.firstChild();
    TQDomElement element = node.toElement();
    TQString langType = Model_Utils::progLangToString( getLanguage() );

    if (qElement.tagName() != "codegenerator"
            || qElement.attribute("language", "UNKNOWN") != langType)
        return;
    // got our code generator element, now load
    // codedocuments
    TQDomNode codeDocNode = qElement.firstChild();
    TQDomElement codeDocElement = codeDocNode.toElement();
    while( !codeDocElement.isNull() ) {

        TQString docTag = codeDocElement.tagName();
        if( docTag == "codedocument" ||
                docTag == "classifiercodedocument"
          ) {
            TQString id = codeDocElement.attribute( "id", "-1" );
            CodeDocument * codeDoc = findCodeDocumentByID(id);
            if(codeDoc)
                codeDoc->loadFromXMI(codeDocElement);
            else {
                kWarning()<<" loadFromXMI: missing code document w/ id:"<<id<<", plowing ahead with pre-generated one."<<endl;
            }
        } else
            kWarning()<<" loadFromXMI : got strange codegenerator child node:"<<docTag<<", ignoring."<<endl;

        codeDocNode = codeDocElement.nextSibling();
        codeDocElement = codeDocNode.toElement();
    }
}

void CodeGenerator::saveToXMI ( TQDomDocument & doc, TQDomElement & root ) {
    TQString langType = Model_Utils::progLangToString( getLanguage() );
    TQDomElement docElement = doc.createElement( "codegenerator" );
    docElement.setAttribute("language",langType);

    CodeDocumentList * docList = getCodeDocumentList();
    for (CodeDocument * codeDoc = docList->first(); codeDoc; codeDoc= docList->next())
        codeDoc->saveToXMI(doc, docElement);

    root.appendChild( docElement );
}

/**
 * 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 documnet. 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).
 */
void CodeGenerator::initFromParentDocument( ) {

    // Walk through the document converting classifiers into
    // classifier code documents as needed (e.g only if doesn't exist)
    UMLClassifierList concepts = UMLApp::app()->getDocument()->getClassesAndInterfaces();
    for (UMLClassifier *c = concepts.first(); c; c = concepts.next())
    {

        // Doesn't exist? Then build one.
        CodeDocument * codeDoc = findCodeDocumentByClassifier(c);
        if (!codeDoc)
        {
            codeDoc = newClassifierCodeDocument(c);
            addCodeDocument(codeDoc); // this will also add a unique tag to the code document
        }
    }

}

/**
 * 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.
 */
void CodeGenerator::syncCodeToDocument ( ) {
    for (CodeDocument * doc = m_codedocumentVector.first(); doc; doc=m_codedocumentVector.next())
        doc->synchronize();
}

// in this 'vanilla' version, we only worry about adding classifier
// documents
void CodeGenerator::checkAddUMLObject (UMLObject * obj) {
    if (!obj)
        return;

    UMLClassifier * c = dynamic_cast<UMLClassifier*>(obj);
    if(c) {
        CodeDocument * cDoc = newClassifierCodeDocument(c);
        addCodeDocument(cDoc);
    }
}

void CodeGenerator::checkRemoveUMLObject (UMLObject * obj)
{

    if (!obj)
        return;

    UMLClassifier * c = dynamic_cast<UMLClassifier*>(obj);
    if(c) {
        ClassifierCodeDocument * cDoc = (ClassifierCodeDocument*) findCodeDocumentByClassifier(c);
        if (cDoc)
            removeCodeDocument(cDoc);
    }

}

/**
 * @return      CodeDocument
 * @param       classifier
 */
CodeDocument * CodeGenerator::findCodeDocumentByClassifier ( UMLClassifier * classifier ) {
    return findCodeDocumentByID(ID2STR(classifier->getID()));
}


/**
 * Write out all code documents to file as appropriate.
 */
void CodeGenerator::writeCodeToFile ( )
{
    writeListedCodeDocsToFile(&m_codedocumentVector);
}

void CodeGenerator::writeCodeToFile ( UMLClassifierList & concepts) {
    CodeDocumentList docs;
    docs.setAutoDelete(false);

    for (UMLClassifier *concept= concepts.first(); concept; concept= concepts.next())
    {
        CodeDocument * doc = findCodeDocumentByClassifier(concept);
        if(doc)
            docs.append(doc);
    }

    writeListedCodeDocsToFile(&docs);
}

// Main method. Will write out passed code documents to file as appropriate.
void CodeGenerator::writeListedCodeDocsToFile ( CodeDocumentList * docs ) {

    // iterate thru all code documents
    for (CodeDocument *doc = docs->first(); doc; doc = docs->next())
    {

        // we need this so we know when to emit a 'codeGenerated' signal
        ClassifierCodeDocument * cdoc = dynamic_cast<ClassifierCodeDocument *>(doc);
        bool codeGenSuccess = false;

        // we only write the document, if so requested
        if(doc->getWriteOutCode())
        {
            TQString filename = findFileName(doc);
            // check that we may open that file for writing
            TQFile file;
            if ( openFile(file,filename) ) {
                TQTextStream stream(&file);
                stream<<doc->toString()<<endl;
                file.close();
                codeGenSuccess = true; // we wrote the code OK
            } else {
                kWarning() << "Cannot open file :"<<filename<<" for writing " << endl;
            }
        }

        if(cdoc)
            emit codeGenerated(cdoc->getParentClassifier(), codeGenSuccess);

    }

}

/**
 * Create a new Code document belonging to this package.
 * @return      CodeDocument
 */
CodeDocument * CodeGenerator::newCodeDocument ( ) {
    CodeDocument * newCodeDoc = new CodeDocument ();
    return newCodeDoc;
}

/**
 * @return      TQString
 * @param       file
 */

TQString CodeGenerator::getHeadingFile( const TQString &file ) {
    return UMLApp::app()->getCommonPolicy()->getHeadingFile(file);
}

/**
 * @return      TQString
 * @param       codeDoc
 * @param       name
 */
TQString CodeGenerator::overwritableName(const TQString& name, const TQString &extension ) {

    CodeGenerationPolicy *pol = UMLApp::app()->getCommonPolicy();
    TQDir outputDirectory = pol->getOutputDirectory();
    TQString filename = name + extension;

    if (!outputDirectory.exists(filename)) {
        return filename;
    }

    int suffix;
    OverwriteDialogue overwriteDialog( name, outputDirectory.absPath(),
                                         m_applyToAllRemaining, kapp -> mainWidget() );
    switch (pol->getOverwritePolicy()) {  //if it exists, check the OverwritePolicy we should use
    case CodeGenerationPolicy::Ok:              //ok to overwrite file
        filename = name + extension;
        break;
    case CodeGenerationPolicy::Ask:            //ask if we can overwrite
        switch(overwriteDialog.exec()) {
        case KDialogBase::Yes:  //overwrite file
            if ( overwriteDialog.applyToAllRemaining() ) {
                pol->setOverwritePolicy(CodeGenerationPolicy::Ok);
                filename = name + extension;
            } else {
                m_applyToAllRemaining = false;
            }
            break;
        case KDialogBase::No: //generate similar name
            suffix = 1;
            while (1) {
                filename = name + "__" + TQString::number(suffix) + extension;
                if (!outputDirectory.exists(filename))
                    break;
                suffix++;
            }
            if ( overwriteDialog.applyToAllRemaining() ) {
                pol->setOverwritePolicy(CodeGenerationPolicy::Never);
            } else {
                m_applyToAllRemaining = false;
            }
            break;
        case KDialogBase::Cancel: //don't output anything
            if ( overwriteDialog.applyToAllRemaining() ) {
                pol->setOverwritePolicy(CodeGenerationPolicy::Cancel);
            } else {
                m_applyToAllRemaining = false;
            }
            return TQString();
            break;
        }

        break;
    case CodeGenerationPolicy::Never: //generate similar name
        suffix = 1;
        while (1) {
            filename = name + "__" + TQString::number(suffix) + extension;
            if (!outputDirectory.exists(filename))
                break;
            suffix++;
        }
        break;
    case CodeGenerationPolicy::Cancel: //don't output anything
        return TQString();
        break;
    }

    return filename;
}


/**
 * @return      bool
 * @param       file
 * @param       name
 */
bool CodeGenerator::openFile (TQFile & file, const TQString &fileName ) {
    //open files for writing.
    if(fileName.isEmpty()) {
        kWarning() << "cannot find a file name" << endl;
        return false;
    } else {
        TQDir outputDirectory = UMLApp::app()->getCommonPolicy()->getOutputDirectory();
        file.setName(outputDirectory.absFilePath(fileName));
        if(!file.open(IO_WriteOnly)) {
            KMessageBox::sorry(0,i18n("Cannot open file %1 for writing. Please make sure the folder exists and you have permissions to write to it.").arg(file.name()),i18n("Cannot Open File"));
            return false;
        }
        return true;
    }

}


/**
 * @return      TQString
 * @param       name
 */
TQString CodeGenerator::cleanName ( const TQString &name ) {
    TQString retval = name;
    retval.replace(TQRegExp("\\W"), "_");
    return retval;
}

TQString CodeGenerator::findFileName ( CodeDocument * codeDocument ) {

    //else, determine the "natural" file name
    TQString name;

    // Get the path name
    TQString path = codeDocument->getPath();

    // if path is given add this as a directory to the file name
    if (!path.isEmpty()) {
        path.replace(TQRegExp("::"), "/"); // Simple hack!
        name = path + '/' + codeDocument->getFileName();
        path = '/' + path;
    } else {
        name = codeDocument->getFileName();
    }

    // Convert all "::" to "/" : Platform-specific path separator
    name.replace(TQRegExp("::"), "/"); // Simple hack!

    // if a path name exists check the existence of the path directory
    if (!path.isEmpty()) {
        TQDir outputDirectory = UMLApp::app()->getCommonPolicy()->getOutputDirectory();
        TQDir pathDir(outputDirectory.absPath() + path);

        // does our complete output directory exist yet? if not, try to create it
        if (!pathDir.exists())
        {
            // ugh. dir separator here is UNIX specific..
            TQStringList dirs = TQStringList::split("/",pathDir.absPath());
            TQString currentDir = "";

            TQStringList::iterator end(dirs.end());
            for (TQStringList::iterator dir(dirs.begin()); dir != end; ++dir)
            {
                currentDir += '/' + *dir;
                if (! (pathDir.exists(currentDir)
                        || pathDir.mkdir(currentDir) ) )
                {
                    KMessageBox::error(0, i18n("Cannot create the folder:\n") +
                                       pathDir.absPath() + i18n("\nPlease check the access rights"),
                                       i18n("Cannot Create Folder"));
                    return NULL;

                }
            }
        }
    }

    name.simplifyWhiteSpace();
    name.replace(TQRegExp(" "),"_");

    return overwritableName( name, codeDocument->getFileExtension() );
}

void CodeGenerator::findObjectsRelated(UMLClassifier *c, UMLPackageList &cList) {
    UMLPackage *temp;
    UMLAssociationList associations = c->getAssociations();

    for (UMLAssociation *a = associations.first(); a; a = associations.next()) {
        temp = 0;
        switch (a->getAssocType()) {
        case Uml::at_Generalization:
        case Uml::at_Realization:
            // only the "b" end is seen by the "a" end, not other way around
            {
                UMLObject *objB = a->getObject(Uml::B);
                if (objB != c)
                    temp = (UMLPackage*)objB;
            }
            break;
        case Uml::at_Dependency:
        case Uml::at_UniAssociation:
            {
                UMLObject *objA = a->getObject(Uml::A);
                UMLObject *objB = a->getObject(Uml::B);
                if (objA == c)
                    temp = static_cast<UMLPackage*>(objB);
            }
            break;
        case Uml::at_Aggregation:
        case Uml::at_Composition:
        case Uml::at_Association:
            {
                UMLObject *objA = a->getObject(Uml::A);
                UMLObject *objB = a->getObject(Uml::B);
                if (objA == c && objB->getBaseType() != Uml::ot_Datatype)
                    temp = static_cast<UMLPackage*>(objB);
            }
            break;
        default: /* all others.. like for state diagrams..we currently don't use */
            break;
        }

        // now add in list ONLY if its not already there
        if(temp  && !cList.containsRef(temp))
            cList.append(temp);
    }

    //operations
    UMLOperationList opl(c->getOpList());
    for(UMLOperation *op = opl.first(); op ; op = opl.next()) {
        temp =0;
        //check return value
        temp =(UMLClassifier*) op->getType();
        if (temp && temp->getBaseType() != Uml::ot_Datatype && !cList.containsRef(temp))
            cList.append(temp);
        //check parameters
        UMLAttributeList atl = op->getParmList();
        for (UMLAttribute *at = atl.first(); at; at = atl.next()) {
            temp = (UMLClassifier*)at->getType();
            if (temp && temp->getBaseType() != Uml::ot_Datatype && !cList.containsRef(temp))
                cList.append(temp);
        }

    }

    //attributes
    if (!c->isInterface()) {
        UMLAttributeList atl = c->getAttributeList();
        for (UMLAttribute *at = atl.first(); at; at = atl.next()) {
            temp=0;
            temp = (UMLClassifier*) at->getType();
            if (temp && temp->getBaseType() != Uml::ot_Datatype && !cList.containsRef(temp))
                cList.append(temp);
        }
    }


}

/**
 * Format an output document.
 * @return      TQString
 * @param       text
 * @param       lineprefix
 * @param       linewidth
 */
TQString CodeGenerator::formatDoc(const TQString &text, const TQString &linePrefix, int lineWidth) {
    TQString output;

    const TQString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars();
    TQStringList lines = TQStringList::split(endLine, text);
    for (TQStringList::ConstIterator lit = lines.begin(); lit != lines.end(); ++lit) {
        TQString input = *lit;
        input.remove( TQRegExp("\\s+$") );
        if (input.length() < (uint)lineWidth) {
            output += linePrefix + input + endLine;
            continue;
        }
        int index;
        while ((index = input.findRev(" ", lineWidth)) >= 0) {
            output += linePrefix + input.left(index) + endLine; // add line
            input.remove(0, index + 1); //and remove processed string, including
            // white space
        }
        if (!input.isEmpty())
            output += linePrefix + input + endLine;
    }
    return output;
}

void CodeGenerator::initFields() {

    m_document = UMLApp::app()->getDocument();
    m_codeDocumentDictionary.setAutoDelete(false);
    m_codedocumentVector.setAutoDelete(false);
    m_applyToAllRemaining = true;
    lastIDIndex = 0;

    // initial population of our project generator
    // CANT Be done here because we would call pure virtual method
    // of newClassifierDocument (bad!).
    // We should only call from the child
    // initFromParentDocument();

}

void CodeGenerator::connect_newcodegen_slots() {
    UMLDoc *doc = UMLApp::app()->getDocument();
    connect(doc, TQT_SIGNAL(sigObjectCreated(UMLObject*)),
            this, TQT_SLOT(checkAddUMLObject(UMLObject*)));
    connect(doc, TQT_SIGNAL(sigObjectRemoved(UMLObject*)),
            this, TQT_SLOT(checkRemoveUMLObject(UMLObject*)));
    CodeGenerationPolicy *commonPolicy = UMLApp::app()->getCommonPolicy();
    connect(commonPolicy, TQT_SIGNAL(modifiedCodeContent()),
            this, TQT_SLOT(syncCodeToDocument()));
}

// these are utility methods for accessing the default
// code gen policy object and should go away when we
// finally implement the CodeGenDialog class -b.t.
void CodeGenerator::setForceDoc(bool f) {
    UMLApp::app()->getCommonPolicy()->setCodeVerboseDocumentComments(f);
}

bool CodeGenerator::forceDoc() const {
    return UMLApp::app()->getCommonPolicy()->getCodeVerboseDocumentComments();
}

void CodeGenerator::setForceSections(bool f) {
    UMLApp::app()->getCommonPolicy()->setCodeVerboseSectionComments(f);
}

bool CodeGenerator::forceSections() const {
    return UMLApp::app()->getCommonPolicy()->getCodeVerboseSectionComments();
}

TQStringList CodeGenerator::defaultDatatypes()  {
    return TQStringList();
    //empty by default, override in your code generator
}

bool CodeGenerator::isReservedKeyword(const TQString & keyword) {

    const TQStringList keywords = reservedKeywords();

    return keywords.contains(keyword);
}

const TQStringList CodeGenerator::reservedKeywords() const {
    static TQStringList emptyList;

    return emptyList;
}

void CodeGenerator::createDefaultStereotypes()  {
    //empty by default, override in your code generator
    //e.g.  m_document->createDefaultStereotypes("constructor");
}

#include "codegenerator.moc"