summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/codemethodblock.cpp
blob: 5a6bbc974699ecea6ed141033a4e92cf85e91019 (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
/***************************************************************************
 *                                                                         *
 *   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 Jun 20 2003
 */
#include "codemethodblock.h"
#include "codeclassfield.h"
#include "classifiercodedocument.h"
#include "codegenerationpolicy.h"
#include "uml.h"

// Constructors/Destructors
//

CodeMethodBlock::CodeMethodBlock ( ClassifierCodeDocument * doc, UMLObject * parentObj, const TQString & body, const TQString & comment)
        : CodeBlockWithComments ((CodeDocument*)doc, body, comment), OwnedCodeBlock (parentObj)
{
    initFields();
}

CodeMethodBlock::~CodeMethodBlock ( ) { }

//
// Methods
//


// Accessor methods
//

// we can just call the superclass
CodeDocument * CodeMethodBlock::getParentDocument() {
    return TextBlock::getParentDocument();
}

/**
 * Get the starting text that begins this method before the body is printed.
 */
TQString CodeMethodBlock::getStartMethodText() const {
    return m_startMethod;
}

/**
 * Get the ending text that finishes this method after the body is printed.
 */
TQString CodeMethodBlock::getEndMethodText() const {
    return m_endMethod;
}

/**
 * Set the starting text that begins this method before the body is printed.
 */
void CodeMethodBlock::setStartMethodText (const TQString &value) {
    m_startMethod = value;
}

/**
 * Set the ending text that finishes this method after the body is printed.
 */
void CodeMethodBlock::setEndMethodText (const TQString &value) {
    m_endMethod = value;
}

// Other methods
//

void CodeMethodBlock::release () {
    // just call super-class versions
    OwnedCodeBlock::release();
    TextBlock::release();
}

/** set attributes of the node that represents this class
 * in the XMI document.
 */
void CodeMethodBlock::setAttributesOnNode ( TQDomDocument & doc, TQDomElement & elem) {

    // set super-class attributes
    CodeBlockWithComments::setAttributesOnNode(doc, elem);
    OwnedCodeBlock::setAttributesOnNode(doc, elem);

    // set local class attributes
    if(getContentType() != AutoGenerated)
    {
        TQString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars();
        elem.setAttribute("startMethodText",encodeText(getStartMethodText(),endLine));
        elem.setAttribute("endMethodText",encodeText(getEndMethodText(),endLine));
    }

}

/** set the class attributes of this object from
 * the passed element node.
 */
void CodeMethodBlock::setAttributesFromNode ( TQDomElement & elem) {

    // set attributes from the XMI
    CodeBlockWithComments::setAttributesFromNode(elem); // superclass load
    OwnedCodeBlock::setAttributesFromNode(elem); // superclass load

    // now load local attributes
    if(getContentType() != AutoGenerated)
    {
        TQString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars();
        setStartMethodText(decodeText(elem.attribute("startMethodText",""),endLine));
        setEndMethodText(decodeText(elem.attribute("endMethodText",""),endLine));
    }

}

void CodeMethodBlock::setAttributesFromObject(TextBlock * obj)
{

    CodeBlockWithComments::setAttributesFromObject(obj);

    CodeMethodBlock * mb = dynamic_cast<CodeMethodBlock*>(obj);
    if(mb)
    {
        setStartMethodText(mb->getStartMethodText());
        setEndMethodText(mb->getEndMethodText());
    }

}

/**
 * @return      TQString
 */
TQString CodeMethodBlock::toString ( ) {

    TQString string = TQString("");

    if(getWriteOutText()) {

        TQString indent = getIndentationString();
        TQString bodyIndent = getIndentationString(getIndentationLevel()+1);
        TQString endLine = UMLApp::app()->getCommonPolicy()->getNewLineEndingChars();

        TQString startMethod = formatMultiLineText ( getStartMethodText(), indent, endLine);
        TQString body = formatMultiLineText (getText(), bodyIndent, endLine);
        TQString endMethod = formatMultiLineText( getEndMethodText(), indent, endLine);

        TQString comment = getComment()->toString();
        if(!comment.isEmpty() && getComment()->getWriteOutText())
            string.append(comment);

        if(!startMethod.isEmpty())
            string.append(startMethod);

        if(!body.isEmpty())
            string.append(body);

        if(!endMethod.isEmpty())
            string.append(endMethod);

    }

    return string;

}

void CodeMethodBlock::initFields ( ) {

    m_startMethod = TQString("");
    m_endMethod = TQString("");
}

void CodeMethodBlock::syncToParent ( )
{

    getComment()->setText(getParentObject()->getDoc());

    updateMethodDeclaration();

    // only update IF we are NOT AutoGenerated
    if(getContentType() != AutoGenerated)
        return;

    updateContent();
}

#include "codemethodblock.moc"