Commit 2e949c70 authored by Kai Koehne's avatar Kai Koehne
Browse files

QmlJS Rewriter: Remove empty grouped properties

Also remove grouped properties if the last member is removed via removeObjectMember
(removeBindingByName already takes care of this).
parent 35e787e6
......@@ -490,6 +490,23 @@ void Rewriter::includeLeadingEmptyLine(const QString &source, int &start)
start = prevBlock.position();
void Rewriter::includeEmptyGroupedProperty(UiObjectDefinition *groupedProperty, UiObjectMember *memberToBeRemoved, int &start, int &end)
if (groupedProperty->qualifiedTypeNameId
&& groupedProperty->qualifiedTypeNameId->name->asString().at(0).isLower()) {
// grouped property
UiObjectMemberList *memberIter = groupedProperty->initializer->members;
while (memberIter) {
if (memberIter->member != memberToBeRemoved) {
memberIter = memberIter->next;
start = groupedProperty->firstSourceLocation().begin();
end = groupedProperty->lastSourceLocation().end();
#if 0
UiObjectMemberList *QMLRewriter::searchMemberToInsertAfter(UiObjectMemberList *members, const QStringList &propertyOrder)
......@@ -610,6 +627,9 @@ void Rewriter::removeObjectMember(UiObjectMember *member, UiObjectMember *parent
if (UiArrayBinding *parentArray = cast<UiArrayBinding *>(parent)) {
extendToLeadingOrTrailingComma(parentArray, member, start, end);
} else {
if (UiObjectDefinition *parentObjectDefinition = cast<UiObjectDefinition *>(parent)) {
includeEmptyGroupedProperty(parentObjectDefinition, member, start, end);
includeSurroundingWhitespace(m_originalText, start, end);
......@@ -78,7 +78,6 @@ public:
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);
......@@ -87,6 +86,7 @@ public:
static bool includeSurroundingWhitespace(const QString &source, int &start, int &end);
static void includeLeadingEmptyLine(const QString &source, int &start);
static void includeEmptyGroupedProperty(AST::UiObjectDefinition *groupedProperty, AST::UiObjectMember *memberToBeRemoved, int &start, int &end);
void replaceMemberValue(AST::UiObjectMember *propertyMember,
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