umbrello API Documentation

rubycodegenerator.cpp

00001 /***************************************************************************
00002                           rubycodegenerator.cpp
00003                           Derived from the Java code generator by thomas
00004 
00005     begin                : Thur Jul 21 2005
00006     author               : Richard Dale
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  *   copyright (C) 2006-2007                                               *
00017  *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
00018  ***************************************************************************/
00019 
00020 // own header
00021 #include "rubycodegenerator.h"
00022 
00023 // qt/kde includes
00024 #include <qregexp.h>
00025 #include <kconfig.h>
00026 #include <kdebug.h>
00027 #include <klocale.h>
00028 #include <kmessagebox.h>
00029 
00030 // local includes
00031 #include "rubycodecomment.h"
00032 #include "codeviewerdialog.h"
00033 #include "../uml.h"
00034 
00035 // Constructors/Destructors
00036 //
00037 
00038 RubyCodeGenerator::RubyCodeGenerator (QDomElement & elem )
00039   : CodeGenerator(elem)
00040 {
00041 }
00042 
00043 RubyCodeGenerator::RubyCodeGenerator ()
00044 {
00045 }
00046 
00047 RubyCodeGenerator::~RubyCodeGenerator ( ) { }
00048 
00049 //
00050 // Methods
00051 //
00052 
00053 // Accessor methods
00054 //
00055 
00056 // return our language
00057 Uml::Programming_Language RubyCodeGenerator::getLanguage() {
00058     return Uml::pl_Ruby;
00059 }
00060 
00061 // In the Java version, we make the ANT build file also available.
00062 CodeViewerDialog * RubyCodeGenerator::getCodeViewerDialog ( QWidget* parent, CodeDocument *doc,
00063         Settings::CodeViewerState state)
00064 {
00065     CodeViewerDialog *dialog = new CodeViewerDialog(parent, doc, state);
00066     return dialog;
00067 }
00068 
00069 
00070 RubyCodeGenerationPolicy * RubyCodeGenerator::getRubyPolicy() {
00071     return dynamic_cast<RubyCodeGenerationPolicy*>(UMLApp::app()->getPolicyExt());
00072 }
00073 
00074 bool RubyCodeGenerator::getAutoGenerateAttribAccessors ( )
00075 {
00076     return getRubyPolicy()->getAutoGenerateAttribAccessors ();
00077 }
00078 
00079 bool RubyCodeGenerator::getAutoGenerateAssocAccessors ( )
00080 {
00081     return getRubyPolicy()->getAutoGenerateAssocAccessors ();
00082 }
00083 
00084 QString RubyCodeGenerator::getListFieldClassName () {
00085     return QString("Array");
00086 }
00087 
00088 // Other methods
00089 //
00090 
00091 QString RubyCodeGenerator::capitalizeFirstLetter(const QString &string)
00092 {
00093     // we could lowercase everything tostart and then capitalize? Nah, it would
00094     // screw up formatting like getMyRadicalVariable() to getMyradicalvariable(). Bah.
00095     QChar firstChar = string.at(0);
00096     return firstChar.upper() + string.mid(1);
00097 }
00098 
00099 QString RubyCodeGenerator::cppToRubyType(const QString &typeStr) {
00100     QString type = cleanName(typeStr);
00101     type.replace("const ", "");
00102     type.replace(QRegExp("[*&\\s]"), "");
00103     type.replace(QRegExp("[<>]"), "_");
00104     type.replace("QStringList", "Array");
00105     type.replace(QRegExp("^string$"),"String");
00106     type.replace("QString", "String");
00107     type.replace("bool", "true|false");
00108     type.replace(QRegExp("^(uint|int|ushort|short|ulong|long)$"), "Integer");
00109     type.replace(QRegExp("^(float|double)$"), "Float");
00110     type.replace(QRegExp("^Q(?=[A-Z])"), "Qt::");
00111     type.replace(QRegExp("^K(?!(DE|Parts|IO)"), "KDE::");
00112 
00113     return type;
00114 }
00115 
00116 QString RubyCodeGenerator::cppToRubyName(const QString &nameStr) {
00117     QString name = cleanName(nameStr);
00118     name.replace(QRegExp("^m_"), "");
00119     name.replace(QRegExp("^[pbn](?=[A-Z])"), "");
00120     name = name.mid(0, 1).lower() + name.mid(1);
00121     return name;
00122 }
00123 
00128 CodeDocument * RubyCodeGenerator::newClassifierCodeDocument ( UMLClassifier * c)
00129 {
00130     RubyClassifierCodeDocument * doc = new RubyClassifierCodeDocument(c);
00131     doc->initCodeClassFields();
00132     return doc;
00133 }
00134 
00135 /* These initializations are done in CodeGenFactory::createObject()
00136 void RubyCodeGenerator::initFields() {
00137     UMLApp::app()->setPolicyExt ( new RubyCodeGenerationPolicy(UMLApp::app()->getConfig()) );
00138     // load Classifier documents from parent document
00139     initFromParentDocument();
00140 }
00141  */
00142 
00143 const QStringList RubyCodeGenerator::reservedKeywords() const {
00144 
00145     static QStringList keywords;
00146 
00147     if (keywords.isEmpty()) {
00148         keywords << "__FILE__"
00149         << "__LINE__"
00150         << "BEGIN"
00151         << "END"
00152         << "alias"
00153         << "and"
00154         << "begin"
00155         << "break"
00156         << "case"
00157         << "class"
00158         << "def"
00159         << "defined?"
00160         << "do"
00161         << "else"
00162         << "elsif"
00163         << "end"
00164         << "ensure"
00165         << "false"
00166         << "for"
00167         << "if"
00168         << "in"
00169         << "module"
00170         << "next"
00171         << "nil"
00172         << "not"
00173         << "or"
00174         << "redo"
00175         << "rescue"
00176         << "retry"
00177         << "return"
00178         << "self"
00179         << "super"
00180         << "then"
00181         << "true"
00182         << "undef"
00183         << "unless"
00184         << "until"
00185         << "when"
00186         << "while"
00187         << "yield";
00188     }
00189 
00190     return keywords;
00191 }
00192 
00193 #include "rubycodegenerator.moc"
00194 
KDE Logo
This file is part of the documentation for umbrello Version 3.1.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Jun 26 08:08:00 2007 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003