summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/codegenerators/rubycodegenerator.cpp
blob: 4acfd65a4c450070f648d631e38885439e4937d9 (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
/***************************************************************************
                          rubycodegenerator.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 <[email protected]>                  *
 ***************************************************************************/

// own header
#include "rubycodegenerator.h"

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

// local includes
#include "rubycodecomment.h"
#include "codeviewerdialog.h"
#include "../uml.h"

// Constructors/Destructors
//

RubyCodeGenerator::RubyCodeGenerator (TQDomElement & elem )
  : CodeGenerator(elem)
{
}

RubyCodeGenerator::RubyCodeGenerator ()
{
}

RubyCodeGenerator::~RubyCodeGenerator ( ) { }

//
// Methods
//

// Accessor methods
//

// return our language
Uml::Programming_Language RubyCodeGenerator::getLanguage() {
    return Uml::pl_Ruby;
}

// In the Java version, we make the ANT build file also available.
CodeViewerDialog * RubyCodeGenerator::getCodeViewerDialog ( TQWidget* parent, CodeDocument *doc,
        Settings::CodeViewerState state)
{
    CodeViewerDialog *dialog = new CodeViewerDialog(parent, doc, state);
    return dialog;
}


RubyCodeGenerationPolicy * RubyCodeGenerator::getRubyPolicy() {
    return dynamic_cast<RubyCodeGenerationPolicy*>(UMLApp::app()->getPolicyExt());
}

bool RubyCodeGenerator::getAutoGenerateAttribAccessors ( )
{
    return getRubyPolicy()->getAutoGenerateAttribAccessors ();
}

bool RubyCodeGenerator::getAutoGenerateAssocAccessors ( )
{
    return getRubyPolicy()->getAutoGenerateAssocAccessors ();
}

TQString RubyCodeGenerator::getListFieldClassName () {
    return TQString("Array");
}

// Other methods
//

TQString RubyCodeGenerator::cppToRubyType(const TQString &typeStr) {
    TQString type = cleanName(typeStr);
    type.replace("const ", "");
    type.replace(TQRegExp("[*&\\s]"), "");
    type.replace(TQRegExp("[<>]"), "_");
    type.replace("TQStringList", "Array");
    type.replace(TQRegExp("^string$"),"String");
    type.replace("TQString", "String");
    type.replace("bool", "true|false");
    type.replace(TQRegExp("^(uint|int|ushort|short|ulong|long)$"), "Integer");
    type.replace(TQRegExp("^(float|double)$"), "Float");
    type.replace(TQRegExp("^Q(?=[A-Z])"), "Qt::");
    type.replace(TQRegExp("^K(?!(DE|Parts|IO)"), "KDE::");

    return type;
}

TQString RubyCodeGenerator::cppToRubyName(const TQString &nameStr) {
    TQString name = cleanName(nameStr);
    name.replace(TQRegExp("^m_"), "");
    name.replace(TQRegExp("^[pbn](?=[A-Z])"), "");
    name = name.mid(0, 1).lower() + name.mid(1);
    return name;
}

/**
 * @return      ClassifierCodeDocument
 * @param       classifier
 */
CodeDocument * RubyCodeGenerator::newClassifierCodeDocument ( UMLClassifier * c)
{
    RubyClassifierCodeDocument * doc = new RubyClassifierCodeDocument(c);
    doc->initCodeClassFields();
    return doc;
}

/* These initializations are done in CodeGenFactory::createObject()
void RubyCodeGenerator::initFields() {
    UMLApp::app()->setPolicyExt ( new RubyCodeGenerationPolicy(UMLApp::app()->getConfig()) );
    // load Classifier documents from parent document
    initFromParentDocument();
}
 */

const TQStringList RubyCodeGenerator::reservedKeywords() const {

    static TQStringList keywords;

    if (keywords.isEmpty()) {
        keywords << "__FILE__"
        << "__LINE__"
        << "BEGIN"
        << "END"
        << "alias"
        << "and"
        << "begin"
        << "break"
        << "case"
        << "class"
        << "def"
        << "defined?"
        << "do"
        << "else"
        << "elsif"
        << "end"
        << "ensure"
        << "false"
        << "for"
        << "if"
        << "in"
        << "module"
        << "next"
        << "nil"
        << "not"
        << "or"
        << "redo"
        << "rescue"
        << "retry"
        << "return"
        << "self"
        << "super"
        << "then"
        << "true"
        << "undef"
        << "unless"
        << "until"
        << "when"
        << "while"
        << "yield";
    }

    return keywords;
}

#include "rubycodegenerator.moc"