Commit 74e8027a authored by Kai Koehne's avatar Kai Koehne
Browse files

QmlJS Rewriter: Return ranges for addX methods

This way one can reindent afterwards.

Reviewed-by: Erik Verbruggen
parent 715aafab
......@@ -52,22 +52,22 @@ Rewriter::Rewriter(const QString &originalText,
Q_ASSERT(changeSet);
}
void Rewriter::addBinding(AST::UiObjectInitializer *ast,
const QString &propertyName,
const QString &propertyValue,
BindingType bindingType)
Rewriter::Range 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);
return addBinding(ast, propertyName, propertyValue, bindingType, insertAfter);
}
void Rewriter::addBinding(AST::UiObjectInitializer *ast,
const QString &propertyName,
const QString &propertyValue,
BindingType bindingType,
UiObjectMemberList *insertAfter)
Rewriter::Range Rewriter::addBinding(AST::UiObjectInitializer *ast,
const QString &propertyName,
const QString &propertyValue,
BindingType bindingType,
UiObjectMemberList *insertAfter)
{
SourceLocation endOfPreviousMember;
SourceLocation startOfNextMember;
......@@ -138,6 +138,8 @@ void Rewriter::addBinding(AST::UiObjectInitializer *ast,
m_changeSet->insert(endOfPreviousMember.end(),
newPropertyTemplate.arg(propertyName, propertyValue));
return Range(endOfPreviousMember.end(), endOfPreviousMember.end());
}
UiObjectMemberList *Rewriter::searchMemberToInsertAfter(UiObjectMemberList *members,
......@@ -577,13 +579,13 @@ void Rewriter::appendToArrayBinding(UiArrayBinding *arrayBinding,
m_changeSet->insert(insertionPoint, QLatin1String(",\n") + content);
}
void Rewriter::addObject(UiObjectInitializer *ast, const QString &content)
Rewriter::Range Rewriter::addObject(UiObjectInitializer *ast, const QString &content)
{
UiObjectMemberList *insertAfter = searchMemberToInsertAfter(ast->members, m_propertyOrder);
addObject(ast, content, insertAfter);
return addObject(ast, content, insertAfter);
}
void Rewriter::addObject(UiObjectInitializer *ast, const QString &content, UiObjectMemberList *insertAfter)
Rewriter::Range Rewriter::addObject(UiObjectInitializer *ast, const QString &content, UiObjectMemberList *insertAfter)
{
int insertionPoint;
QString textToInsert;
......@@ -596,6 +598,8 @@ void Rewriter::addObject(UiObjectInitializer *ast, const QString &content, UiObj
textToInsert += content;
m_changeSet->insert(insertionPoint, QLatin1String("\n") + textToInsert);
return Range(insertionPoint, insertionPoint);
}
void Rewriter::removeObjectMember(UiObjectMember *member, UiObjectMember *parent)
......
......@@ -31,15 +31,11 @@
#define QMLJSREWRITER_H
#include <qmljs/qmljs_global.h>
#include <qmljs/parser/qmljsastfwd_p.h>
#include <utils/changeset.h>
#include <QtCore/QStringList>
namespace Utils {
class ChangeSet;
}
namespace QmlJS {
class QMLJS_EXPORT Rewriter
......@@ -51,17 +47,19 @@ public:
ArrayBinding
};
typedef Utils::ChangeSet::Range Range;
public:
Rewriter(const QString &originalText,
Utils::ChangeSet *changeSet,
const QStringList &propertyOrder);
void addBinding(AST::UiObjectInitializer *ast,
Range addBinding(AST::UiObjectInitializer *ast,
const QString &propertyName,
const QString &propertyValue,
BindingType bindingType);
void addBinding(AST::UiObjectInitializer *ast,
Range addBinding(AST::UiObjectInitializer *ast,
const QString &propertyName,
const QString &propertyValue,
BindingType bindingType,
......@@ -76,8 +74,8 @@ public:
void appendToArrayBinding(AST::UiArrayBinding *arrayBinding,
const QString &content);
void addObject(AST::UiObjectInitializer *ast, const QString &content);
void addObject(AST::UiObjectInitializer *ast, const QString &content, AST::UiObjectMemberList *insertAfter);
Range addObject(AST::UiObjectInitializer *ast, const QString &content);
Range 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