umbrello/umbrello
dcodegenerator.cpp
Go to the documentation of this file.00001 00002 /*************************************************************************** 00003 * * 00004 * This program is free software; you can redistribute it and/or modify * 00005 * it under the terms of the GNU General Public License as published by * 00006 * the Free Software Foundation; either version 2 of the License, or * 00007 * (at your option) any later version. * 00008 * * 00009 * copyright (C) 2007 Jari-Matti Mäkelä <jmjm@iki.fi> * 00010 * Umbrello UML Modeller Authors <uml-devel@uml.sf.net> * 00011 ***************************************************************************/ 00012 00013 // own header 00014 #include "dcodegenerator.h" 00015 00016 // qt/kde includes 00017 #include <qregexp.h> 00018 #include <kconfig.h> 00019 #include <kdebug.h> 00020 #include <klocale.h> 00021 #include <kmessagebox.h> 00022 00023 // local includes 00024 #include "dcodecomment.h" 00025 #include "codeviewerdialog.h" 00026 #include "../uml.h" 00027 00028 // Constructors/Destructors 00029 // 00030 00031 DCodeGenerator::DCodeGenerator (QDomElement & elem) 00032 : CodeGenerator(elem) 00033 { 00034 init(); 00035 } 00036 00037 DCodeGenerator::DCodeGenerator () 00038 { 00039 init(); 00040 } 00041 00042 DCodeGenerator::~DCodeGenerator ( ) { } 00043 00044 // 00045 // Methods 00046 // 00047 00048 // Accessor methods 00049 // 00050 00051 // return our language 00052 Uml::Programming_Language DCodeGenerator::getLanguage() { 00053 return Uml::pl_D; 00054 } 00055 00056 // In the D version, we make the ANT build file also available. 00057 CodeViewerDialog * DCodeGenerator::getCodeViewerDialog ( QWidget* parent, CodeDocument *doc, 00058 Settings::CodeViewerState state) 00059 { 00060 CodeViewerDialog *dialog = new CodeViewerDialog(parent, doc, state); 00061 return dialog; 00062 } 00063 00064 00065 DCodeGenerationPolicy * DCodeGenerator::getDPolicy() { 00066 return dynamic_cast<DCodeGenerationPolicy*>(UMLApp::app()->getPolicyExt()); 00067 } 00068 00069 bool DCodeGenerator::getAutoGenerateAttribAccessors ( ) 00070 { 00071 return getDPolicy()->getAutoGenerateAttribAccessors (); 00072 } 00073 00074 bool DCodeGenerator::getAutoGenerateAssocAccessors ( ) 00075 { 00076 return getDPolicy()->getAutoGenerateAssocAccessors (); 00077 } 00078 00079 QString DCodeGenerator::getListFieldClassName () { 00080 return QString("Vector"); 00081 } 00082 00083 // Other methods 00084 // 00085 00086 QString DCodeGenerator::capitalizeFirstLetter(const QString &string) 00087 { 00088 // we could lowercase everything tostart and then capitalize? Nah, it would 00089 // screw up formatting like getMyRadicalVariable() to getMyradicalvariable(). Bah. 00090 QChar firstChar = string.at(0); 00091 return firstChar.toUpper() + string.mid(1); 00092 } 00093 00094 // IF the type is "string" we need to declare it as 00095 // the D Object "String" (there is no string primative in D). 00096 // Same thing again for "bool" to "boolean" 00097 QString DCodeGenerator::fixTypeName(const QString &string) 00098 { 00099 if (string.isEmpty() || string.contains(QRegExp("^\\s+$"))) 00100 return "void"; 00101 if (string == "string") 00102 return "char[]"; 00103 return cleanName(string); 00104 } 00105 00110 CodeDocument * DCodeGenerator::newClassifierCodeDocument ( UMLClassifier * c) 00111 { 00112 DClassifierCodeDocument * doc = new DClassifierCodeDocument(c); 00113 doc->initCodeClassFields(); 00114 return doc; 00115 } 00116 00117 void DCodeGenerator::init() { 00118 // load Classifier documents from parent document 00119 //initFromParentDocument(); 00120 } 00121 00122 QStringList DCodeGenerator::defaultDatatypes() { 00123 QStringList l; 00124 l << "void" 00125 << "bool" 00126 << "byte" 00127 << "ubyte" 00128 << "short" 00129 << "ushort" 00130 << "int" 00131 << "uint" 00132 << "long" 00133 << "ulong" 00134 << "cent" 00135 << "ucent" 00136 << "float" 00137 << "double" 00138 << "real" 00139 << "ifloat" 00140 << "idouble" 00141 << "ireal" 00142 << "cfloat" 00143 << "cdouble" 00144 << "creal" 00145 << "char" 00146 << "wchar" 00147 << "dchar"; 00148 return l; 00149 } 00150 00151 const QStringList DCodeGenerator::reservedKeywords() const { 00152 00153 static QStringList keywords; 00154 00155 if (keywords.isEmpty()) { 00156 keywords << "abstract" 00157 << "alias" 00158 << "align" 00159 << "asm" 00160 << "assert" 00161 << "auto" 00162 << "body" 00163 << "bool" 00164 << "break" 00165 << "byte" 00166 << "case" 00167 << "cast" 00168 << "catch" 00169 << "cdouble" 00170 << "cent" 00171 << "cfloat" 00172 << "char" 00173 << "class" 00174 << "const" 00175 << "continue" 00176 << "creal" 00177 << "dchar" 00178 << "debug" 00179 << "default" 00180 << "delegate" 00181 << "delete" 00182 << "deprecated" 00183 << "do" 00184 << "double" 00185 << "else" 00186 << "enum" 00187 << "export" 00188 << "extern" 00189 << "false" 00190 << "final" 00191 << "finally" 00192 << "float" 00193 << "for" 00194 << "foreach" 00195 << "foreach_reverse" 00196 << "function" 00197 << "goto" 00198 << "idouble" 00199 << "if" 00200 << "ifloat" 00201 << "import" 00202 << "in" 00203 << "inout" 00204 << "int" 00205 << "interface" 00206 << "invariant" 00207 << "ireal" 00208 << "is" 00209 << "lazy" 00210 << "long" 00211 << "macro" 00212 << "mixin" 00213 << "module" 00214 << "msg" 00215 << "new" 00216 << "null" 00217 << "out" 00218 << "override" 00219 << "package" 00220 << "pragma" 00221 << "private" 00222 << "protected" 00223 << "public" 00224 << "real" 00225 << "ref" 00226 << "return" 00227 << "scope" 00228 << "short" 00229 << "static" 00230 << "struct" 00231 << "super" 00232 << "switch" 00233 << "synchronized" 00234 << "template" 00235 << "this" 00236 << "throw" 00237 << "true" 00238 << "try" 00239 << "typedef" 00240 << "typeid" 00241 << "typeof" 00242 << "ubyte" 00243 << "ucent" 00244 << "uint" 00245 << "ulong" 00246 << "union" 00247 << "unittest" 00248 << "ushort" 00249 << "version" 00250 << "void" 00251 << "volatile" 00252 << "wchar" 00253 << "while" 00254 << "with"; 00255 } 00256 00257 return keywords; 00258 } 00259 00260 #include "dcodegenerator.moc"
KDE 4.0 API Reference