diff --git a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp index 85c5d679c60..0d21a6101a5 100644 --- a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp +++ b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp @@ -46,8 +46,23 @@ using namespace QmlJSEditor::Internal; namespace { +static QString toString(Statement *statement) +{ + ExpressionStatement *expStmt = cast(statement); + if (!expStmt) + return QString::null; + if (IdentifierExpression *idExp = cast(expStmt->expression)) { + return idExp->name->asString(); + } else if (StringLiteral *strExp = cast(expStmt->expression)) { + return strExp->value->asString(); + } + return QString::null; +} + static QString getIdProperty(UiObjectDefinition *def) { + QString objectName; + if (def && def->initializer) { for (UiObjectMemberList *iter = def->initializer->members; iter; iter = iter->next) { if (UiScriptBinding *script = cast(iter->member)) { @@ -56,22 +71,16 @@ static QString getIdProperty(UiObjectDefinition *def) if (script->qualifiedId->next) continue; if (script->qualifiedId->name) { - if (script->qualifiedId->name->asString() == QLatin1String("id")) { - ExpressionStatement *expStmt = cast(script->statement); - if (!expStmt) - continue; - if (IdentifierExpression *idExp = cast(expStmt->expression)) { - return idExp->name->asString(); - } else if (StringLiteral *strExp = cast(expStmt->expression)) { - return strExp->value->asString(); - } - } + if (script->qualifiedId->name->asString() == QLatin1String("id")) + return toString(script->statement); + if (script->qualifiedId->name->asString() == QLatin1String("objectName")) + objectName = toString(script->statement); } } } } - return QString(); + return objectName; } class Operation: public QmlJSQuickFixOperation @@ -90,7 +99,7 @@ public: if (m_componentName.isEmpty()) { setDescription(QCoreApplication::translate("QmlJSEditor::ComponentFromObjectDef", - "Move Component into separate file'")); + "Move Component into separate file")); } else { m_componentName[0] = m_componentName.at(0).toUpper(); setDescription(QCoreApplication::translate("QmlJSEditor::ComponentFromObjectDef",