[Uml-devel] branches/KDE/3.5/kdesdk/umbrello/umbrello
Oliver Kellogg
okellogg at users.sourceforge.net
Sat Aug 6 10:59:42 UTC 2005
SVN commit 443597 by okellogg:
Umbrello::isCommonDataType(): New. SimpleCodeGenerator::writeCodeToFile()
uses this for avoiding generation of classes for common data types.
This is a fairly primitive approach and I'm sure someone will come up
with a better solution. At the least, the selected active programming
language should be considered. Candidate for JJ.
CCBUG:74429
M +2 -15 classifierlistitem.cpp
M +5 -2 codegenerators/simplecodegenerator.cpp
M +19 -0 model_utils.cpp
M +7 -0 model_utils.h
M +9 -20 umlobject.cpp
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/classifierlistitem.cpp #443596:443597
@@ -19,6 +19,7 @@
#include "classifier.h"
#include "uml.h"
#include "umldoc.h"
+#include "model_utils.h"
UMLClassifierListItem::UMLClassifierListItem(const UMLObject *parent, QString Name, Uml::IDType id)
: UMLObject(parent, Name, id) {
@@ -79,21 +80,7 @@
m_pSecondary = pDoc->findUMLObject(type);
if (m_pSecondary == NULL) {
// Make data type for easily identified cases
- const int n_types = 12;
- const char *types[] = {
- "void", "bool",
- "char", "unsigned char",
- "short", "unsigned short",
- "int", "unsigned int",
- "long", "unsigned long",
- "float", "double"
- };
- int i = 0;
- for (; i < n_types; i++) {
- if (type == types[i])
- break;
- }
- if (i < n_types || type.contains('*')) {
+ if (Umbrello::isCommonDataType(type) || type.contains('*')) {
m_pSecondary = pDoc->createUMLObject(Uml::ot_Datatype, type);
kdDebug() << "UMLClassifierListItem::setTypeName: "
<< "created datatype for " << type << endl;
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/codegenerators/simplecodegenerator.cpp #443596:443597
@@ -29,6 +29,7 @@
#include <kapplication.h>
// app includes
#include "../dialogs/overwritedialogue.h"
+#include "../model_utils.h"
#include "../attribute.h"
#include "../umloperationlist.h"
#include "../umlattributelist.h"
@@ -233,8 +234,10 @@
void SimpleCodeGenerator::writeCodeToFile ( ) {
m_fileMap->clear(); // yeah, need to do this, if not, just keep getting same damn directory to write to.
UMLClassifierList concepts = m_doc->getClassesAndInterfaces();
- for (UMLClassifier *c = concepts.first(); c; c = concepts.next())
- this->writeClass(c); // call the writer for each class.
+ for (UMLClassifier *c = concepts.first(); c; c = concepts.next()) {
+ if (! Umbrello::isCommonDataType(c->getName()))
+ this->writeClass(c); // call the writer for each class.
+ }
}
// write only selected concepts to file
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/model_utils.cpp #443596:443597
@@ -212,6 +212,25 @@
return retval;
}
+bool isCommonDataType(QString type) {
+ const int n_types = 12;
+ const char *types[] = { "void", "string",
+ "bool", "boolean",
+ "char", "unsigned char",
+ "short", "unsigned short",
+ "int", "unsigned int",
+ "long", "unsigned long",
+ "float", "double"
+ };
+ const QString lcType = type.lower();
+ int i = 0;
+ for (; i < n_types; i++) {
+ if (lcType == types[i])
+ return true;
+ }
+ return false;
+}
+
QString scopeToString(Uml::Scope scope, bool mnemonic) {
switch (scope) {
case Uml::Protected:
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/model_utils.h #443596:443597
@@ -80,6 +80,13 @@
bool isCommonXMIAttribute(const QString &tag);
/**
+ * Return true if the given type is common among the majority
+ * of programming languages, such as "bool" or "boolean".
+ * TODO: Make this depend on the active programming language.
+ */
+bool isCommonDataType(QString type);
+
+/**
* Convert Scope value into QString representation.
*
* @param scope The Scope enum value to convert.
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/umlobject.cpp #443596:443597
@@ -405,14 +405,18 @@
// Work around UMLDoc::createUMLObject()'s incapability
// of on-the-fly scope creation:
if (m_SecondaryId.contains("::")) {
- m_SecondaryId.replace("::", ".");
// TODO: Merge ClassImport::createUMLObject() into UMLDoc::createUMLObject()
m_pSecondary = ClassImport::createUMLObject(Uml::ot_UMLObject, m_SecondaryId, NULL);
if (m_pSecondary) {
+ if (ClassImport::newUMLObjectWasCreated()) {
+ maybeSignalObjectCreated();
+ kdDebug() << "UMLObject::resolveRef: ClassImport::createUMLObject() "
+ << "created a new type for " << m_SecondaryId << endl;
+ } else {
+ kdDebug() << "UMLObject::resolveRef: ClassImport::createUMLObject() "
+ << "returned an existing type for " << m_SecondaryId << endl;
+ }
m_SecondaryId = "";
- maybeSignalObjectCreated();
- kdDebug() << "UMLObject::resolveRef: Created a new type for " << m_SecondaryId
- << " using ClassImport::createUMLObject()" << endl;
return true;
}
kdError() << "UMLObject::resolveRef: ClassImport::createUMLObject() "
@@ -430,22 +434,7 @@
if (isReferenceType) {
ot = Uml::ot_Datatype;
} else {
- // Make data type for easily identified cases
- const int n_types = 12;
- const char *types[] = {
- "void", "bool",
- "char", "unsigned char",
- "short", "unsigned short",
- "int", "unsigned int",
- "long", "unsigned long",
- "float", "double"
- };
- int i = 0;
- for (; i < n_types; i++) {
- if (m_SecondaryId == types[i])
- break;
- }
- if (i < n_types)
+ if (Umbrello::isCommonDataType(m_SecondaryId))
ot = Uml::ot_Datatype;
}
m_pSecondary = pDoc->createUMLObject(ot, m_SecondaryId, NULL);
More information about the umbrello-devel
mailing list