[Uml-devel] branches/KDE/3.5/kdesdk/umbrello/umbrello
Oliver Kellogg
okellogg at users.sourceforge.net
Thu Jan 12 10:36:03 UTC 2006
SVN commit 497423 by okellogg:
skipToClosing(): New. Handle template types.
M +47 -36 javaimport.cpp
M +11 -0 javaimport.h
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/javaimport.cpp #497422:497423
@@ -12,7 +12,6 @@
// own header
#include "javaimport.h"
-#include <stdio.h>
// qt/kde includes
#include <qfile.h>
#include <qtextstream.h>
@@ -42,32 +41,17 @@
}
/// Catenate possible template arguments/array dimensions to the end of the type name.
-/// Currently this function does not advance() to the next token. (TBC should it?)
QString JavaImport::joinTypename() {
QString typeName = m_source[m_srcIndex];
- const uint srcLength = m_source.count();
- QString next = m_source[m_srcIndex + 1];
- if (next == "<") {
- m_srcIndex++;
- typeName += '<';
- while (m_srcIndex < srcLength) {
- next = advance();
- typeName += next;
- if (next == ">")
- break;
+ if (m_source[m_srcIndex + 1] == "<" ||
+ m_source[m_srcIndex + 1] == "[") {
+ int start = ++m_srcIndex;
+ if (! skipToClosing(m_source[start][0]))
+ return typeName;
+ for (int i = start; i <= m_srcIndex; i++) {
+ typeName += m_source[i];
}
- next = m_source[m_srcIndex + 1];
}
- if (next == "[") {
- m_srcIndex++;
- typeName += '[';
- while (m_srcIndex < srcLength) {
- next = advance();
- typeName += next;
- if (next == "]")
- break;
- }
- }
return typeName;
}
@@ -101,6 +85,45 @@
m_source.append(lexeme);
}
+bool JavaImport::skipToClosing(QChar opener) {
+ QString closing;
+ switch (opener) {
+ case '{':
+ closing = "}";
+ break;
+ case '[':
+ closing = "]";
+ break;
+ case '(':
+ closing = ")";
+ break;
+ case '<':
+ closing = ">";
+ break;
+ default:
+ kdError() << "JavaImport::skipToClosing(" << opener
+ << "): " << "illegal input character" << endl;
+ return false;
+ }
+ const QString opening(opener);
+ skipStmt(opening);
+ const uint srcLength = m_source.count();
+ int nesting = 0;
+ while (m_srcIndex < srcLength) {
+ QString nextToken = advance();
+ if (nextToken == closing) {
+ if (nesting <= 0)
+ break;
+ nesting--;
+ } else if (nextToken == opening) {
+ nesting++;
+ }
+ }
+ if (m_srcIndex == srcLength)
+ return false;
+ return true;
+}
+
bool JavaImport::parseStmt() {
const uint srcLength = m_source.count();
const QString& keyword = m_source[m_srcIndex];
@@ -244,19 +267,7 @@
m_isStatic, m_isAbstract, false /*isFriend*/,
false /*isConstructor*/, m_comment);
m_isAbstract = m_isStatic = false;
- skipStmt("{");
- int braceNesting = 0;
- while (m_srcIndex < srcLength) {
- nextToken = advance();
- if (nextToken == "}") {
- if (braceNesting <= 0)
- break;
- braceNesting--;
- } else if (nextToken == "{") {
- braceNesting++;
- }
- }
- return true;
+ return skipToClosing('{');
}
// At this point we know it's some kind of attribute declaration.
while (1) {
--- branches/KDE/3.5/kdesdk/umbrello/umbrello/javaimport.h #497422:497423
@@ -40,6 +40,17 @@
*/
void fillSource(QString word);
+ /**
+ * Advance NativeImportBase::m_srcIndex to the index of the
+ * corresponding closing character of the given opening.
+ * Nested opening/closing pairs are respected.
+ * Valid openers are: '{' '[' '(' '<'
+ *
+ * @return True for success, false for misuse (invalid opener) or
+ * if no matching closing character is found in m_source.
+ */
+ bool skipToClosing(QChar opener);
+
QString joinTypename();
bool m_isStatic;
};
More information about the umbrello-devel
mailing list