[Uml-devel] KDE/kdesdk/umbrello/umbrello/codeimport
Oliver Kellogg
okellogg at users.sourceforge.net
Sat Feb 9 13:56:12 UTC 2008
SVN commit 772711 by okellogg:
http://sf.net/mailarchive/forum.php?thread_name=704630.203.qm%40web58014.mail.re3.yahoo.com&forum_name=uml-devel
Walter Christie <wheeltracks1932 at yahoo.com> wrote:
> I'm using Umbrello 2.0 with python. When using
> autogenerate, umbrello creates function definitions
> that are empty, removing any code that is in there
> already.
Right. Umbrello does not yet support round-tripping but here's my little stab
at it, for Python only. I'm not a Python expert and it's not yet perfect.
Perhaps you find ways of improving it.
CCBUG:53382
M +32 -2 pythonimport.cpp
M +8 -2 pythonimport.h
--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/pythonimport.cpp #772710:772711
@@ -113,9 +113,23 @@
}
}
-void PythonImport::skipBody() {
+QString PythonImport::indentation(int level) {
+ QString spaces;
+ for (int i = 0; i < level; i++)
+ spaces += " ";
+ return spaces;
+}
+
+QString PythonImport::skipBody() {
+ /* During input preprocessing, changes in indentation were replaced by
+ braces, and a semicolon was appended to each line ending.
+ In order to return the body, we try to reconstruct the original Python
+ syntax by reverting those changes.
+ */
+ QString body = ":\n";
if (m_source[m_srcIndex] != "{")
skipStmt("{");
+ bool firstTokenAfterNewline = true;
int braceNesting = 0;
QString token;
while (!(token = advance()).isNull()) {
@@ -123,10 +137,26 @@
if (braceNesting <= 0)
break;
braceNesting--;
+ body += "\n";
+ firstTokenAfterNewline = true;
} else if (token == "{") {
braceNesting++;
+ body += ":\n";
+ firstTokenAfterNewline = true;
+ } else if (token == ";") {
+ body += "\n";
+ firstTokenAfterNewline = true;
+ } else {
+ if (firstTokenAfterNewline) {
+ body += indentation(braceNesting);
+ firstTokenAfterNewline = false;
+ } else if (body.contains(QRegExp("\\w$")) && token.contains(QRegExp("^\\w"))) {
+ body += ' ';
+ }
+ body += token;
}
}
+ return body;
}
bool PythonImport::parseStmt() {
@@ -174,7 +204,7 @@
Import_Utils::insertMethod(m_klass, op, Uml::Visibility::Public, "string",
false /*isStatic*/, false /*isAbstract*/, false /*isFriend*/,
false /*isConstructor*/, m_comment);
- skipBody();
+ op->setSourceCode(skipBody());
return true;
}
if (keyword == "}") {
--- trunk/KDE/kdesdk/umbrello/umbrello/codeimport/pythonimport.h #772710:772711
@@ -51,11 +51,17 @@
bool preprocess(QString& line);
/**
- * Skip ahead to outermost closing brace
+ * Return an amount of spaces that corresponds to @param level
*/
- void skipBody();
+ QString indentation(int level);
/**
+ * Skip ahead to outermost closing brace.
+ * @return body contents skipped
+ */
+ QString skipBody();
+
+ /**
* Buffer for number of indentation characters (whitespace,
* i.e. tabs or spaces) at beginning of input line.
*/
More information about the umbrello-devel
mailing list