Commit dc859db1 authored by Erik Verbruggen's avatar Erik Verbruggen
Browse files

Fixed a bug where a property could be inserted after an object.

parent 83e40337
......@@ -72,7 +72,7 @@ bool AddObjectVisitor::visit(QmlJS::AST::UiObjectDefinition *ast)
void AddObjectVisitor::insertInto(QmlJS::AST::UiObjectInitializer *ast)
{
UiObjectMemberList *insertAfter = searchMemberToInsertAfter(ast->members, QString(), m_propertyOrder);
UiObjectMemberList *insertAfter = searchMemberToInsertAfter(ast->members, m_propertyOrder);
int insertionPoint;
int depth;
......
......@@ -87,7 +87,7 @@ private:
{
if (targetPropertyName.isEmpty()) {
// insert as UiObjectDefinition:
UiObjectMemberList *insertAfter = searchMemberToInsertAfter(ast->members, QString(), propertyOrder);
UiObjectMemberList *insertAfter = searchMemberToInsertAfter(ast->members, propertyOrder);
if (insertAfter && insertAfter->member) {
moveInfo.destination = insertAfter->member->lastSourceLocation().end();
......
......@@ -270,6 +270,34 @@ void QMLRewriter::includeLeadingEmptyLine(int &start) const
start = prevBlock.position();
}
UiObjectMemberList *QMLRewriter::searchMemberToInsertAfter(UiObjectMemberList *members, const QStringList &propertyOrder)
{
const int objectDefinitionInsertionPoint = propertyOrder.indexOf(QString::null);
UiObjectMemberList *previous = 0;
for (UiObjectMemberList *iter = members; iter; iter = iter->next) {
UiObjectMember *member = iter->member;
int idx = -1;
if (UiArrayBinding *arrayBinding = cast<UiArrayBinding*>(member))
idx = propertyOrder.indexOf(flatten(arrayBinding->qualifiedId));
else if (UiObjectBinding *objectBinding = cast<UiObjectBinding*>(member))
idx = propertyOrder.indexOf(flatten(objectBinding->qualifiedId));
else if (cast<UiObjectDefinition*>(member))
idx = propertyOrder.indexOf(QString::null);
else if (UiScriptBinding *scriptBinding = cast<UiScriptBinding*>(member))
idx = propertyOrder.indexOf(flatten(scriptBinding->qualifiedId));
else if (cast<UiPublicMember*>(member))
idx = propertyOrder.indexOf(QLatin1String("property"));
if (idx > objectDefinitionInsertionPoint)
return iter;
previous = iter;
}
return previous;
}
UiObjectMemberList *QMLRewriter::searchMemberToInsertAfter(UiObjectMemberList *members, const QString &propertyName, const QStringList &propertyOrder)
{
if (!members)
......@@ -298,9 +326,9 @@ UiObjectMemberList *QMLRewriter::searchMemberToInsertAfter(UiObjectMemberList *m
if (idx == -1)
idx = propertyOrder.size() - 1;
for (; idx >= 0; --idx) {
const QString prop = propertyOrder.at(idx);
UiObjectMemberList *candidate = orderedMembers[prop];
for (; idx > 0; --idx) {
const QString prop = propertyOrder.at(idx - 1);
UiObjectMemberList *candidate = orderedMembers.value(prop, 0);
if (candidate != 0)
return candidate;
}
......
......@@ -79,6 +79,7 @@ protected:
bool includeSurroundingWhitespace(int &start, int &end) const;
void includeLeadingEmptyLine(int &start) const;
static QmlJS::AST::UiObjectMemberList *searchMemberToInsertAfter(QmlJS::AST::UiObjectMemberList *members, const QStringList &propertyOrder);
static QmlJS::AST::UiObjectMemberList *searchMemberToInsertAfter(QmlJS::AST::UiObjectMemberList *members, const QString &propertyName, const QStringList &propertyOrder);
protected:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment