diff options
author | Christian Kamm <christian.d.kamm@nokia.com> | 2011-10-07 14:04:06 +0200 |
---|---|---|
committer | Christian Kamm <christian.d.kamm@nokia.com> | 2011-10-10 09:36:12 +0200 |
commit | a7f78991c9317471ddc85f6556be971d019f3f59 (patch) | |
tree | 51e53891d62970c14efc59e986a2459cad6267ed /src/libs/qmljs/qmljsrewriter.cpp | |
parent | 737aaf02b4d221d8088513fef810e0f453a737be (diff) | |
download | qt-creator-a7f78991c9317471ddc85f6556be971d019f3f59.tar.gz |
QmlJS: Move commonly used functions to qmlutils.h.
Change-Id: I22376d96fe575bc00a55094c06af80e32a5587e6
Reviewed-on: http://codereview.qt-project.org/6238
Sanity-Review: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@nokia.com>
Diffstat (limited to 'src/libs/qmljs/qmljsrewriter.cpp')
-rw-r--r-- | src/libs/qmljs/qmljsrewriter.cpp | 55 |
1 files changed, 21 insertions, 34 deletions
diff --git a/src/libs/qmljs/qmljsrewriter.cpp b/src/libs/qmljs/qmljsrewriter.cpp index c95a7e82a9..6dbf08e675 100644 --- a/src/libs/qmljs/qmljsrewriter.cpp +++ b/src/libs/qmljs/qmljsrewriter.cpp @@ -34,6 +34,7 @@ #include <qmljs/parser/qmljsast_p.h> #include <qmljs/parser/qmljsengine_p.h> +#include <qmljs/qmljsutils.h> #include <utils/changeset.h> // ### FIXME: remove these includes: @@ -160,11 +161,11 @@ UiObjectMemberList *Rewriter::searchMemberToInsertAfter(UiObjectMemberList *memb if (cast<UiObjectDefinition*>(member)) lastObjectDef = iter; else if (UiArrayBinding *arrayBinding = cast<UiArrayBinding*>(member)) - idx = propertyOrder.indexOf(flatten(arrayBinding->qualifiedId)); + idx = propertyOrder.indexOf(toString(arrayBinding->qualifiedId)); else if (UiObjectBinding *objectBinding = cast<UiObjectBinding*>(member)) - idx = propertyOrder.indexOf(flatten(objectBinding->qualifiedId)); + idx = propertyOrder.indexOf(toString(objectBinding->qualifiedId)); else if (UiScriptBinding *scriptBinding = cast<UiScriptBinding*>(member)) - idx = propertyOrder.indexOf(flatten(scriptBinding->qualifiedId)); + idx = propertyOrder.indexOf(toString(scriptBinding->qualifiedId)); else if (cast<UiPublicMember*>(member)) idx = propertyOrder.indexOf(QLatin1String("property")); @@ -193,11 +194,11 @@ UiArrayMemberList *Rewriter::searchMemberToInsertAfter(UiArrayMemberList *member if (cast<UiObjectDefinition*>(member)) lastObjectDef = iter; else if (UiArrayBinding *arrayBinding = cast<UiArrayBinding*>(member)) - idx = propertyOrder.indexOf(flatten(arrayBinding->qualifiedId)); + idx = propertyOrder.indexOf(toString(arrayBinding->qualifiedId)); else if (UiObjectBinding *objectBinding = cast<UiObjectBinding*>(member)) - idx = propertyOrder.indexOf(flatten(objectBinding->qualifiedId)); + idx = propertyOrder.indexOf(toString(objectBinding->qualifiedId)); else if (UiScriptBinding *scriptBinding = cast<UiScriptBinding*>(member)) - idx = propertyOrder.indexOf(flatten(scriptBinding->qualifiedId)); + idx = propertyOrder.indexOf(toString(scriptBinding->qualifiedId)); else if (cast<UiPublicMember*>(member)) idx = propertyOrder.indexOf(QLatin1String("property")); @@ -224,13 +225,13 @@ UiObjectMemberList *Rewriter::searchMemberToInsertAfter(UiObjectMemberList *memb UiObjectMember *member = iter->member; if (UiArrayBinding *arrayBinding = cast<UiArrayBinding*>(member)) - orderedMembers[flatten(arrayBinding->qualifiedId)] = iter; + orderedMembers[toString(arrayBinding->qualifiedId)] = iter; else if (UiObjectBinding *objectBinding = cast<UiObjectBinding*>(member)) - orderedMembers[flatten(objectBinding->qualifiedId)] = iter; + orderedMembers[toString(objectBinding->qualifiedId)] = iter; else if (cast<UiObjectDefinition*>(member)) orderedMembers[QString::null] = iter; else if (UiScriptBinding *scriptBinding = cast<UiScriptBinding*>(member)) - orderedMembers[flatten(scriptBinding->qualifiedId)] = iter; + orderedMembers[toString(scriptBinding->qualifiedId)] = iter; else if (cast<UiPublicMember*>(member)) orderedMembers[QLatin1String("property")] = iter; } @@ -251,20 +252,6 @@ UiObjectMemberList *Rewriter::searchMemberToInsertAfter(UiObjectMemberList *memb return 0; } -QString Rewriter::flatten(UiQualifiedId *first) -{ - QString flatId; - - for (UiQualifiedId* current = first; current; current = current->next) { - if (current != first) - flatId += '.'; - - flatId += current->name; - } - - return flatId; -} - void Rewriter::changeBinding(UiObjectInitializer *ast, const QString &propertyName, const QString &newValue, @@ -304,7 +291,7 @@ void Rewriter::changeBinding(UiObjectInitializer *ast, // for grouped properties: else if (!prefix.isEmpty()) { if (UiObjectDefinition *def = cast<UiObjectDefinition *>(member)) { - if (flatten(def->qualifiedTypeNameId) == prefix) { + if (toString(def->qualifiedTypeNameId) == prefix) { changeBinding(def->initializer, suffix, newValue, binding); } } @@ -358,11 +345,11 @@ bool Rewriter::isMatchingPropertyMember(const QString &propertyName, if (UiPublicMember *publicMember = cast<UiPublicMember*>(member)) return publicMember->name == propertyName; else if (UiObjectBinding *objectBinding = cast<UiObjectBinding*>(member)) - return flatten(objectBinding->qualifiedId) == propertyName; + return toString(objectBinding->qualifiedId) == propertyName; else if (UiScriptBinding *scriptBinding = cast<UiScriptBinding*>(member)) - return flatten(scriptBinding->qualifiedId) == propertyName; + return toString(scriptBinding->qualifiedId) == propertyName; else if (UiArrayBinding *arrayBinding = cast<UiArrayBinding*>(member)) - return flatten(arrayBinding->qualifiedId) == propertyName; + return toString(arrayBinding->qualifiedId) == propertyName; else return false; } @@ -410,7 +397,7 @@ void Rewriter::removeBindingByName(UiObjectInitializer *ast, const QString &prop // check for grouped properties: else if (!prefix.isEmpty()) { if (UiObjectDefinition *def = cast<UiObjectDefinition *>(member)) { - if (flatten(def->qualifiedTypeNameId) == prefix) { + if (toString(def->qualifiedTypeNameId) == prefix) { removeGroupedProperty(def, propertyName); } } @@ -558,11 +545,11 @@ UiObjectMemberList *QMLRewriter::searchMemberToInsertAfter(UiObjectMemberList *m if (cast<UiObjectDefinition*>(member)) lastObjectDef = iter; else if (UiArrayBinding *arrayBinding = cast<UiArrayBinding*>(member)) - idx = propertyOrder.indexOf(flatten(arrayBinding->qualifiedId)); + idx = propertyOrder.indexOf(toString(arrayBinding->qualifiedId)); else if (UiObjectBinding *objectBinding = cast<UiObjectBinding*>(member)) - idx = propertyOrder.indexOf(flatten(objectBinding->qualifiedId)); + idx = propertyOrder.indexOf(toString(objectBinding->qualifiedId)); else if (UiScriptBinding *scriptBinding = cast<UiScriptBinding*>(member)) - idx = propertyOrder.indexOf(flatten(scriptBinding->qualifiedId)); + idx = propertyOrder.indexOf(toString(scriptBinding->qualifiedId)); else if (cast<UiPublicMember*>(member)) idx = propertyOrder.indexOf(QLatin1String("property")); @@ -587,13 +574,13 @@ UiObjectMemberList *QMLRewriter::searchMemberToInsertAfter(UiObjectMemberList *m UiObjectMember *member = iter->member; if (UiArrayBinding *arrayBinding = cast<UiArrayBinding*>(member)) - orderedMembers[flatten(arrayBinding->qualifiedId)] = iter; + orderedMembers[toString(arrayBinding->qualifiedId)] = iter; else if (UiObjectBinding *objectBinding = cast<UiObjectBinding*>(member)) - orderedMembers[flatten(objectBinding->qualifiedId)] = iter; + orderedMembers[toString(objectBinding->qualifiedId)] = iter; else if (cast<UiObjectDefinition*>(member)) orderedMembers[QString::null] = iter; else if (UiScriptBinding *scriptBinding = cast<UiScriptBinding*>(member)) - orderedMembers[flatten(scriptBinding->qualifiedId)] = iter; + orderedMembers[toString(scriptBinding->qualifiedId)] = iter; else if (cast<UiPublicMember*>(member)) orderedMembers[QLatin1String("property")] = iter; } |