Commit 12b58356 authored by Fawzi Mohamed's avatar Fawzi Mohamed
Browse files

qmljs: make refactoring work on Object Bindings



“Move Component to Separate File” and “Wrap Component in Loader” did
work only for UiObjectDefinitions, extended them to UiObjectBindings.

Task-number: QTCREATORBUG-12904
Change-Id: I5216110c1edfc6e4536f83eba39e74919c918d50
Reviewed-by: default avatarTim Jenssen <tim.jenssen@digia.com>
parent d19628dd
......@@ -60,18 +60,12 @@ namespace {
class Operation: public QmlJSQuickFixOperation
{
UiObjectDefinition *m_objDef;
QString m_idName, m_componentName;
SourceLocation m_firstSourceLocation;
SourceLocation m_lastSourceLocation;
public:
Operation(const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface,
UiObjectDefinition *objDef)
: QmlJSQuickFixOperation(interface, 0)
, m_objDef(objDef)
void init()
{
Q_ASSERT(m_objDef != 0);
m_idName = idOfObject(m_objDef);
if (!m_idName.isEmpty()) {
m_componentName = m_idName;
m_componentName[0] = m_componentName.at(0).toUpper();
......@@ -81,6 +75,26 @@ public:
"Move Component into Separate File"));
}
Operation(const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface,
UiObjectDefinition *objDef)
: QmlJSQuickFixOperation(interface, 0),
m_idName(idOfObject(objDef)),
m_firstSourceLocation(objDef->firstSourceLocation()),
m_lastSourceLocation(objDef->lastSourceLocation())
{
init();
}
Operation(const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface,
UiObjectBinding *objDef)
: QmlJSQuickFixOperation(interface, 0),
m_idName(idOfObject(objDef)),
m_firstSourceLocation(objDef->qualifiedTypeNameId->firstSourceLocation()),
m_lastSourceLocation(objDef->lastSourceLocation())
{
init();
}
virtual void performChanges(QmlJSRefactoringFilePtr currentFile,
const QmlJSRefactoringChanges &refactoring)
{
......@@ -102,8 +116,8 @@ public:
imports = currentFile->textOf(start, end);
}
const int start = currentFile->startOf(m_objDef->firstSourceLocation());
const int end = currentFile->startOf(m_objDef->lastSourceLocation());
const int start = currentFile->startOf(m_firstSourceLocation);
const int end = currentFile->startOf(m_lastSourceLocation);
const QString txt = imports + currentFile->textOf(start, end)
+ QLatin1String("}\n");
......@@ -165,6 +179,11 @@ void ComponentFromObjectDef::match(const QmlJSQuickFixInterface &interface, Quic
result.append(QuickFixOperation::Ptr(new Operation(interface, objDef)));
return;
}
} else if (UiObjectBinding *objBinding = cast<UiObjectBinding *>(node)) {
if (!interface->currentFile()->isCursorOn(objBinding->qualifiedTypeNameId))
return;
result.append(QuickFixOperation::Ptr(new Operation(interface, objBinding)));
return;
}
}
}
......
......@@ -77,15 +77,16 @@ protected:
Result result;
};
template <typename T>
class Operation: public QmlJSQuickFixOperation
{
Q_DECLARE_TR_FUNCTIONS(QmlJSEditor::Internal::Operation)
UiObjectDefinition *m_objDef;
T *m_objDef;
public:
Operation(const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface,
UiObjectDefinition *objDef)
T *objDef)
: QmlJSQuickFixOperation(interface, 0)
, m_objDef(objDef)
{
......@@ -156,7 +157,7 @@ public:
changes.insert(afterOpenBrace, innerIdForwarders);
}
const int objDefStart = m_objDef->firstSourceLocation().begin();
const int objDefStart = m_objDef->qualifiedTypeNameId->firstSourceLocation().begin();
const int objDefEnd = m_objDef->lastSourceLocation().end();
changes.insert(objDefStart, comment +
QString::fromLatin1("Component {\n"
......@@ -188,9 +189,14 @@ void WrapInLoader::match(const QmlJSQuickFixInterface &interface, QuickFixOperat
return;
// check that the node is not the root node
if (i > 0 && !cast<UiProgram*>(path.at(i - 1))) {
result.append(QuickFixOperation::Ptr(new Operation(interface, objDef)));
result.append(QuickFixOperation::Ptr(new Operation<UiObjectDefinition>(interface, objDef)));
return;
}
} else if (UiObjectBinding *objBinding = cast<UiObjectBinding *>(node)) {
if (!interface->currentFile()->isCursorOn(objBinding->qualifiedTypeNameId))
return;
result.append(QuickFixOperation::Ptr(new Operation<UiObjectBinding>(interface, objBinding)));
return;
}
}
}
......
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