summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/codegenerators/javacodeclassfielddeclarationblock.cpp
blob: 6f6eb5ec5337832e5ba8097ae55e056a66fb146f (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
/***************************************************************************
 *                                                                         *
 *   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-2006                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

/*  This code generated by:
 *      Author : thomas
 *      Date   : Fri Jul 25 2003
 */

#include "javacodeclassfielddeclarationblock.h"

#include "javacodeclassfield.h"
#include "javaclassifiercodedocument.h"
#include "javacodegenerationpolicy.h"
#include "../codegenerator.h"
#include "../classifier.h"
#include "../umlrole.h"
#include "../uml.h"

// Constructors/Destructors
//

JavaCodeClassFieldDeclarationBlock::JavaCodeClassFieldDeclarationBlock ( CodeClassField * tqparent )
        : CodeClassFieldDeclarationBlock ( tqparent )
{
    setOverallIndentationLevel(1);
    updateContent();
}

JavaCodeClassFieldDeclarationBlock::~JavaCodeClassFieldDeclarationBlock ( ) { }

//
// Methods
//



// Other methods
//

/**
 */
void JavaCodeClassFieldDeclarationBlock::updateContent( )
{

    CodeClassField * cf = getParentClassField();
    ClassifierCodeDocument * doc = cf->getParentDocument();
    JavaCodeClassField * jcf = dynamic_cast<JavaCodeClassField*>(cf);
    JavaClassifierCodeDocument* jdoc = dynamic_cast<JavaClassifierCodeDocument*>(doc);
    CodeGenerationPolicy * commonpolicy = UMLApp::app()->getCommonPolicy();

    CodeGenerationPolicy::ScopePolicy scopePolicy = commonpolicy->getAssociationFieldScope();

    // Set the comment
    TQString notes = getParentObject()->getDoc();
    getComment()->setText(notes);

    // Set the body
    TQString staticValue = getParentObject()->getStatic() ? "static " : "";
    TQString scopeStr = jdoc->scopeToJavaDecl(getParentObject()->getVisibility());

    // IF this is from an association, then scope taken as appropriate to policy
    if(!jcf->tqparentIsAttribute())
    {
        switch (scopePolicy) {
        case CodeGenerationPolicy::Public:
        case CodeGenerationPolicy::Private:
        case CodeGenerationPolicy::Protected:
              scopeStr = jdoc->scopeToJavaDecl((Uml::Visibility::Value) scopePolicy);
            break;
        default:
        case CodeGenerationPolicy::FromParent:
            // do nothing here... will leave as from tqparent object
            break;
        }
    }

    TQString typeName = jcf->getTypeName();
    TQString fieldName = jcf->getFieldName();
    TQString initialV = jcf->getInitialValue();

    if (!cf->tqparentIsAttribute() && !cf->fieldIsSingleValue())
        typeName = "List";

    TQString body = staticValue+scopeStr+' '+typeName+' '+fieldName;
    if (!initialV.isEmpty())
        body.append(" = " + initialV);
    else if (!cf->tqparentIsAttribute())
    {
        UMLRole * role = dynamic_cast<UMLRole*>(cf->getParentObject());
        if (role->getObject()->getBaseType() == Uml::ot_Interface)
        {
            // do nothing.. can't instanciate an interface
        } else {

            // FIX?: IF a constructor method exists in the classifiercodedoc
            // of the tqparent Object, then we can use that instead (if its empty).
            if(cf->fieldIsSingleValue())
            {
                if(!typeName.isEmpty())
                    body.append(" = new " + typeName + " ( )");
            } else
                body.append(" = new Vector ( )");
        }
    }

    setText(body+';');

}

#include "javacodeclassfielddeclarationblock.moc"