summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/codegenerators/rubycodedocumentation.cpp
blob: 9afee3f18264d407f929dc68e8dbaaf73be1ce24 (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
/***************************************************************************
                          rubycodedocumentation.cpp
                          Derived from the Java code generator by thomas

    begin                : Thur Jul 21 2005
    author               : Richard Dale
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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) 2006-2007                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

// own header
#include "rubycodedocumentation.h"

// qt/kde includes
#include <tqregexp.h>
#include <kdebug.h>

// local includes
#include "rubyclassifiercodedocument.h"
#include "rubycodegenerationpolicy.h"
#include "../uml.h"

// Constructors/Destructors
//

RubyCodeDocumentation::RubyCodeDocumentation ( RubyClassifierCodeDocument * doc, const TQString & text )
        : CodeComment ((CodeDocument*) doc, text)
{

}

RubyCodeDocumentation::~RubyCodeDocumentation ( ) { }

//
// Methods
//


// Accessor methods
//

// Other methods
//

/**
 * Save the XMI representation of this object
 */
void RubyCodeDocumentation::saveToXMI ( TQDomDocument & doc, TQDomElement & root ) {
    TQDomElement blockElement = doc.createElement( "rubycodedocumentation" );
    setAttributesOnNode(doc, blockElement); // as we added no additional fields to this class we may
    // just use tqparent TextBlock method
    root.appendChild( blockElement );
}

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

    TQString output = "";

    // simple output method
    if(getWriteOutText())
    {
        bool  useHashOutput = true;

        // need to figure out output type from ruby policy
        CodeGenerationPolicy *p = UMLApp::app()->getCommonPolicy();
        if(p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
             useHashOutput = false;

        TQString indent = getIndentationString();
        TQString endLine = getNewLineEndingChars();
        TQString body = getText();
        if( useHashOutput)
        {
            if(!body.isEmpty())
                output.append(formatMultiLineText (body, indent +"# ", endLine));
        } else {
            output.append("=begin rdoc"+endLine);
            output.append(formatMultiLineText (body, indent +' ', endLine));
            output.append("=end"+endLine);
        }
    }

    return output;
}

TQString RubyCodeDocumentation::getNewEditorLine ( int amount )
{
    CodeGenerationPolicy *p = UMLApp::app()->getCommonPolicy();
    if(p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
        return getIndentationString(amount) + ' ';
    else
        return getIndentationString(amount) + "# ";
}

int RubyCodeDocumentation::firstEditableLine() {
    CodeGenerationPolicy *p = UMLApp::app()->getCommonPolicy();
    if(p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
        return 1;
    return 0;
}

int RubyCodeDocumentation::lastEditableLine() {
    CodeGenerationPolicy *p = UMLApp::app()->getCommonPolicy();
    if(p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
    {
        return -1; // very last line is NOT editable
    }
    return 0;
}

/** UnFormat a long text string. Typically, this means removing
 *  the indentaion (linePrefix) and/or newline chars from each line.
 */
TQString RubyCodeDocumentation::unformatText ( const TQString & text , const TQString & indent)
{

    TQString mytext = TextBlock::unformatText(text, indent);
    CodeGenerationPolicy *p = UMLApp::app()->getCommonPolicy();
    // remove leading or trailing comment stuff
    mytext.remove(TQRegExp('^'+indent));
    if(p->getCommentStyle() == CodeGenerationPolicy::MultiLine)
    {
        mytext.remove(TQRegExp("^=begin\\s*(rdoc)?\\s*\n?"));
        mytext.remove(TQRegExp("^=end\\s*\n?$"));
    } else
        mytext.remove(TQRegExp("^#\\s*"));

    return mytext;
}


#include "rubycodedocumentation.moc"