summaryrefslogtreecommitdiff
path: root/src/plugins/qmljseditor
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2011-08-17 11:35:57 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2011-08-19 11:12:09 +0200
commit8a6d767a8f2f98ea4e04847f92cff40d661b806f (patch)
tree586e5c539adfbb18623246d00dec5e894288c8e1 /src/plugins/qmljseditor
parenta07acad516b5fa1ac503493b4ec28d595f6e1ea0 (diff)
downloadqt-creator-8a6d767a8f2f98ea4e04847f92cff40d661b806f.tar.gz
Refactoring changes: Cleanup and improvements.
Previously RefactoringFiles were usually passed around by value. However, since a RefactoringFile may sometimes own a QTextDocument (when it was read from a file), that's not great and caused the file to be reread after every copy. With this change RefactoringFile becomes noncopyable and is always owned by a shared pointer. This change also allowed having const RefactoringFiles which is useful because they can be safely used from other threads. See CppRefactoringChanges::fileNoEditor. Change-Id: I9045921d6d0f6349f9558ff2a3d8317ea172193b Reviewed-on: http://codereview.qt.nokia.com/3084 Reviewed-by: Leandro T. C. Melo <leandro.melo@nokia.com>
Diffstat (limited to 'src/plugins/qmljseditor')
-rw-r--r--src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp14
-rw-r--r--src/plugins/qmljseditor/qmljsquickfix.cpp5
-rw-r--r--src/plugins/qmljseditor/qmljsquickfix.h4
-rw-r--r--src/plugins/qmljseditor/qmljsquickfixassist.cpp5
-rw-r--r--src/plugins/qmljseditor/qmljsquickfixassist.h3
-rw-r--r--src/plugins/qmljseditor/qmljsquickfixes.cpp10
-rw-r--r--src/plugins/qmljseditor/qmloutlinemodel.cpp7
7 files changed, 27 insertions, 21 deletions
diff --git a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
index bf78bed93d..f8baece7e8 100644
--- a/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
+++ b/src/plugins/qmljseditor/qmljscomponentfromobjectdef.cpp
@@ -114,7 +114,8 @@ public:
}
}
- virtual void performChanges(QmlJSRefactoringFile *currentFile, QmlJSRefactoringChanges *refactoring)
+ virtual void performChanges(QmlJSRefactoringFilePtr currentFile,
+ const QmlJSRefactoringChanges &refactoring)
{
QString componentName = m_componentName;
QString path = QFileInfo(fileName()).path();
@@ -142,7 +143,7 @@ public:
+ QLatin1String("}\n");
// stop if we can't create the new file
- if (!refactoring->createFile(newFileName, txt))
+ if (!refactoring.createFile(newFileName, txt))
return;
QString replacement = componentName + QLatin1String(" {\n");
@@ -152,8 +153,9 @@ public:
Utils::ChangeSet changes;
changes.replace(start, end, replacement);
- currentFile->change(changes);
- currentFile->indent(Range(start, end + 1));
+ currentFile->setChangeSet(changes);
+ currentFile->appendIndentRange(Range(start, end + 1));
+ currentFile->apply();
}
};
@@ -163,13 +165,13 @@ public:
QList<QmlJSQuickFixOperation::Ptr> ComponentFromObjectDef::match(
const QSharedPointer<const QmlJSQuickFixAssistInterface> &interface)
{
- const int pos = interface->currentFile().cursor().position();
+ const int pos = interface->currentFile()->cursor().position();
QList<Node *> path = interface->semanticInfo().rangePath(pos);
for (int i = path.size() - 1; i >= 0; --i) {
Node *node = path.at(i);
if (UiObjectDefinition *objDef = cast<UiObjectDefinition *>(node)) {
- if (!interface->currentFile().isCursorOn(objDef->qualifiedTypeNameId))
+ if (!interface->currentFile()->isCursorOn(objDef->qualifiedTypeNameId))
return noResult();
// check that the node is not the root node
if (i > 0 && !cast<UiProgram*>(path.at(i - 1))) {
diff --git a/src/plugins/qmljseditor/qmljsquickfix.cpp b/src/plugins/qmljseditor/qmljsquickfix.cpp
index f00a0eddd1..186442dcd0 100644
--- a/src/plugins/qmljseditor/qmljsquickfix.cpp
+++ b/src/plugins/qmljseditor/qmljsquickfix.cpp
@@ -66,11 +66,10 @@ QmlJSQuickFixOperation::~QmlJSQuickFixOperation()
void QmlJSQuickFixOperation::perform()
{
QmlJSRefactoringChanges refactoring(ExtensionSystem::PluginManager::instance()->getObject<QmlJS::ModelManagerInterface>(),
- //_state.snapshot());
m_interface->semanticInfo().snapshot);
- QmlJSRefactoringFile current = refactoring.file(fileName());
+ QmlJSRefactoringFilePtr current = refactoring.file(fileName());
- performChanges(&current, &refactoring);
+ performChanges(current, refactoring);
}
const QmlJSQuickFixAssistInterface *QmlJSQuickFixOperation::assistInterface() const
diff --git a/src/plugins/qmljseditor/qmljsquickfix.h b/src/plugins/qmljseditor/qmljsquickfix.h
index 99b8b60737..7cdbb79eab 100644
--- a/src/plugins/qmljseditor/qmljsquickfix.h
+++ b/src/plugins/qmljseditor/qmljsquickfix.h
@@ -79,8 +79,8 @@ public:
protected:
typedef Utils::ChangeSet::Range Range;
- virtual void performChanges(QmlJSTools::QmlJSRefactoringFile *currentFile,
- QmlJSTools::QmlJSRefactoringChanges *refactoring) = 0;
+ virtual void performChanges(QmlJSTools::QmlJSRefactoringFilePtr currentFile,
+ const QmlJSTools::QmlJSRefactoringChanges &refactoring) = 0;
const Internal::QmlJSQuickFixAssistInterface *assistInterface() const;
diff --git a/src/plugins/qmljseditor/qmljsquickfixassist.cpp b/src/plugins/qmljseditor/qmljsquickfixassist.cpp
index 99a60eaa68..0d30dae873 100644
--- a/src/plugins/qmljseditor/qmljsquickfixassist.cpp
+++ b/src/plugins/qmljseditor/qmljsquickfixassist.cpp
@@ -51,6 +51,7 @@ QmlJSQuickFixAssistInterface::QmlJSQuickFixAssistInterface(QmlJSTextEditorWidget
: DefaultAssistInterface(editor->document(), editor->position(), editor->file(), reason)
, m_editor(editor)
, m_semanticInfo(editor->semanticInfo())
+ , m_currentFile(QmlJSRefactoringChanges::file(m_editor, m_semanticInfo.document))
{}
QmlJSQuickFixAssistInterface::~QmlJSQuickFixAssistInterface()
@@ -61,9 +62,9 @@ const SemanticInfo &QmlJSQuickFixAssistInterface::semanticInfo() const
return m_semanticInfo;
}
-const QmlJSTools::QmlJSRefactoringFile QmlJSQuickFixAssistInterface::currentFile() const
+QmlJSRefactoringFilePtr QmlJSQuickFixAssistInterface::currentFile() const
{
- return QmlJSRefactoringFile(m_editor, m_semanticInfo.document);
+ return m_currentFile;
}
QWidget *QmlJSQuickFixAssistInterface::widget() const
diff --git a/src/plugins/qmljseditor/qmljsquickfixassist.h b/src/plugins/qmljseditor/qmljsquickfixassist.h
index 3427cb1b41..50d2ec00e5 100644
--- a/src/plugins/qmljseditor/qmljsquickfixassist.h
+++ b/src/plugins/qmljseditor/qmljsquickfixassist.h
@@ -51,12 +51,13 @@ public:
virtual ~QmlJSQuickFixAssistInterface();
const SemanticInfo &semanticInfo() const;
- const QmlJSTools::QmlJSRefactoringFile currentFile() const;
+ QmlJSTools::QmlJSRefactoringFilePtr currentFile() const;
QWidget *widget() const;
private:
QmlJSTextEditorWidget *m_editor;
SemanticInfo m_semanticInfo;
+ QmlJSTools::QmlJSRefactoringFilePtr m_currentFile;
};
diff --git a/src/plugins/qmljseditor/qmljsquickfixes.cpp b/src/plugins/qmljseditor/qmljsquickfixes.cpp
index 84fd0de6fe..394e8c1d1c 100644
--- a/src/plugins/qmljseditor/qmljsquickfixes.cpp
+++ b/src/plugins/qmljseditor/qmljsquickfixes.cpp
@@ -70,7 +70,7 @@ public:
{
UiObjectInitializer *objectInitializer = 0;
- const int pos = interface->currentFile().cursor().position();
+ const int pos = interface->currentFile()->cursor().position();
if (QmlJS::AST::Node *member = interface->semanticInfo().rangeAt(pos)) {
if (QmlJS::AST::UiObjectBinding *b = QmlJS::AST::cast<QmlJS::AST::UiObjectBinding *>(member)) {
@@ -104,7 +104,8 @@ private:
"Split initializer"));
}
- virtual void performChanges(QmlJSRefactoringFile *currentFile, QmlJSRefactoringChanges *)
+ virtual void performChanges(QmlJSRefactoringFilePtr currentFile,
+ const QmlJSRefactoringChanges &)
{
Q_ASSERT(_objectInitializer != 0);
@@ -123,9 +124,10 @@ private:
changes.insert(currentFile->startOf(_objectInitializer->rbraceToken),
QLatin1String("\n"));
- currentFile->change(changes);
- currentFile->indent(Range(currentFile->startOf(_objectInitializer->lbraceToken),
+ currentFile->setChangeSet(changes);
+ currentFile->appendIndentRange(Range(currentFile->startOf(_objectInitializer->lbraceToken),
currentFile->startOf(_objectInitializer->rbraceToken)));
+ currentFile->apply();
}
};
};
diff --git a/src/plugins/qmljseditor/qmloutlinemodel.cpp b/src/plugins/qmljseditor/qmloutlinemodel.cpp
index 63569ec622..cd19095c7a 100644
--- a/src/plugins/qmljseditor/qmloutlinemodel.cpp
+++ b/src/plugins/qmljseditor/qmloutlinemodel.cpp
@@ -775,11 +775,12 @@ void QmlOutlineModel::reparentNodes(QmlOutlineItem *targetItem, int row, QList<Q
}
QmlJSRefactoringChanges refactoring(ModelManagerInterface::instance(), m_semanticInfo.snapshot);
- TextEditor::RefactoringFile file = refactoring.file(m_semanticInfo.document->fileName());
- file.change(changeSet);
+ TextEditor::RefactoringFilePtr file = refactoring.file(m_semanticInfo.document->fileName());
+ file->setChangeSet(changeSet);
foreach (const Utils::ChangeSet::Range &range, changedRanges) {
- file.indent(range);
+ file->appendIndentRange(range);
}
+ file->apply();
}
void QmlOutlineModel::moveObjectMember(AST::UiObjectMember *toMove,