Commit 715aafab authored by Kai Koehne's avatar Kai Koehne
Browse files

QmlJS Rewriter: Allow disambiguation of where ObjectMember should be added to

With 700975ad one could specify that a UiObjectMember should be inserted
after another one. But 0 'the default parameter' was ambiguous in that
either you want to have it inserted at the beginning of the member list,
or the heuristics should be applied.

Make this explicit by providing two methods.
parent 5df0f0a0
......@@ -52,16 +52,23 @@ Rewriter::Rewriter(const QString &originalText,
Q_ASSERT(changeSet);
}
void Rewriter::addBinding(AST::UiObjectInitializer *ast,
const QString &propertyName,
const QString &propertyValue,
BindingType bindingType)
{
UiObjectMemberList *insertAfter = searchMemberToInsertAfter(ast->members,
propertyName,
m_propertyOrder);
addBinding(ast, propertyName, propertyValue, bindingType, insertAfter);
}
void Rewriter::addBinding(AST::UiObjectInitializer *ast,
const QString &propertyName,
const QString &propertyValue,
BindingType bindingType,
UiObjectMemberList *insertAfter)
{
if (!insertAfter)
insertAfter = searchMemberToInsertAfter(ast->members,
propertyName,
m_propertyOrder);
SourceLocation endOfPreviousMember;
SourceLocation startOfNextMember;
......@@ -570,11 +577,14 @@ void Rewriter::appendToArrayBinding(UiArrayBinding *arrayBinding,
m_changeSet->insert(insertionPoint, QLatin1String(",\n") + content);
}
void Rewriter::addObject(UiObjectInitializer *ast, const QString &content, UiObjectMemberList *insertAfter)
void Rewriter::addObject(UiObjectInitializer *ast, const QString &content)
{
if (!insertAfter)
insertAfter = searchMemberToInsertAfter(ast->members, m_propertyOrder);
UiObjectMemberList *insertAfter = searchMemberToInsertAfter(ast->members, m_propertyOrder);
addObject(ast, content, insertAfter);
}
void Rewriter::addObject(UiObjectInitializer *ast, const QString &content, UiObjectMemberList *insertAfter)
{
int insertionPoint;
QString textToInsert;
if (insertAfter && insertAfter->member) {
......
......@@ -56,11 +56,16 @@ public:
Utils::ChangeSet *changeSet,
const QStringList &propertyOrder);
void addBinding(AST::UiObjectInitializer *ast,
const QString &propertyName,
const QString &propertyValue,
BindingType bindingType);
void addBinding(AST::UiObjectInitializer *ast,
const QString &propertyName,
const QString &propertyValue,
BindingType bindingType,
AST::UiObjectMemberList *insertAfter = 0);
AST::UiObjectMemberList *insertAfter);
void changeProperty(AST::UiObjectInitializer *ast,
const QString &propertyName,
......@@ -71,7 +76,8 @@ public:
void appendToArrayBinding(AST::UiArrayBinding *arrayBinding,
const QString &content);
void addObject(AST::UiObjectInitializer *ast, const QString &content, AST::UiObjectMemberList *insertAfter = 0);
void addObject(AST::UiObjectInitializer *ast, const QString &content);
void addObject(AST::UiObjectInitializer *ast, const QString &content, AST::UiObjectMemberList *insertAfter);
void removeObjectMember(AST::UiObjectMember *member, AST::UiObjectMember *parent);
static AST::UiObjectMemberList *searchMemberToInsertAfter(AST::UiObjectMemberList *members, const QStringList &propertyOrder);
......
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