diff --git a/src/plugins/cppeditor/cpprefactoringchanges.cpp b/src/plugins/cppeditor/cpprefactoringchanges.cpp index e5c33acfdb2..a1514a9efbf 100644 --- a/src/plugins/cppeditor/cpprefactoringchanges.cpp +++ b/src/plugins/cppeditor/cpprefactoringchanges.cpp @@ -52,7 +52,7 @@ CppRefactoringFilePtr CppRefactoringChanges::file(TextEditor::TextEditorWidget * TextEditor::RefactoringFilePtr CppRefactoringChanges::file(const FilePath &filePath) const { - CppRefactoringFilePtr result(new CppRefactoringFile(filePath, m_data)); + CppRefactoringFilePtr result(new CppRefactoringFile(filePath, m_data.staticCast())); return result; } @@ -67,7 +67,7 @@ CppRefactoringFileConstPtr CppRefactoringChanges::fileNoEditor(const FilePath &f if (const auto source = data()->m_workingCopy.source(filePath)) document = new QTextDocument(QString::fromUtf8(*source)); CppRefactoringFilePtr result(new CppRefactoringFile(document, filePath)); - result->m_data = m_data; + result->m_data = m_data.staticCast(); return result; } @@ -77,10 +77,10 @@ const Snapshot &CppRefactoringChanges::snapshot() const return data()->m_snapshot; } -CppRefactoringFile::CppRefactoringFile(const FilePath &filePath, const QSharedPointer &data) - : RefactoringFile(filePath, data) +CppRefactoringFile::CppRefactoringFile(const FilePath &filePath, const QSharedPointer &data) + : RefactoringFile(filePath), m_data(data) { - const Snapshot &snapshot = this->data()->m_snapshot; + const Snapshot &snapshot = data->m_snapshot; m_cppDocument = snapshot.document(filePath); m_formattingEnabled = true; } @@ -102,7 +102,7 @@ Document::Ptr CppRefactoringFile::cppDocument() const if (!m_cppDocument || !m_cppDocument->translationUnit() || !m_cppDocument->translationUnit()->ast()) { const QByteArray source = document()->toPlainText().toUtf8(); - const Snapshot &snapshot = data()->m_snapshot; + const Snapshot &snapshot = m_data->m_snapshot; m_cppDocument = snapshot.preprocessedDocument(source, filePath()); m_cppDocument->check(); @@ -239,11 +239,6 @@ const Token &CppRefactoringFile::tokenAt(unsigned index) const return cppDocument()->translationUnit()->tokenAt(index); } -CppRefactoringChangesData *CppRefactoringFile::data() const -{ - return static_cast(m_data.data()); -} - void CppRefactoringFile::fileChanged() { QTC_ASSERT(!m_filePath.isEmpty(), return); diff --git a/src/plugins/cppeditor/cpprefactoringchanges.h b/src/plugins/cppeditor/cpprefactoringchanges.h index 878c38d4342..972aae34918 100644 --- a/src/plugins/cppeditor/cpprefactoringchanges.h +++ b/src/plugins/cppeditor/cpprefactoringchanges.h @@ -52,12 +52,10 @@ public: QString textOf(const CPlusPlus::AST *ast) const; private: - CppRefactoringFile(const Utils::FilePath &filePath, const QSharedPointer &data); + CppRefactoringFile(const Utils::FilePath &filePath, const QSharedPointer &data); CppRefactoringFile(QTextDocument *document, const Utils::FilePath &filePath); explicit CppRefactoringFile(TextEditor::TextEditorWidget *editor); - CppRefactoringChangesData *data() const; - void fileChanged() override; void indentSelection(const QTextCursor &selection, const TextEditor::TextDocument *textDocument) const override; @@ -69,6 +67,7 @@ private: int startIndex) const; mutable CPlusPlus::Document::Ptr m_cppDocument; + QSharedPointer m_data; friend class CppRefactoringChanges; // for access to constructor }; diff --git a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp index 24bd14f52b0..617d5292e99 100644 --- a/src/plugins/qmljstools/qmljsrefactoringchanges.cpp +++ b/src/plugins/qmljstools/qmljsrefactoringchanges.cpp @@ -36,7 +36,7 @@ QmlJSRefactoringChanges::QmlJSRefactoringChanges(ModelManagerInterface *modelMan TextEditor::RefactoringFilePtr QmlJSRefactoringChanges::file(const Utils::FilePath &filePath) const { - return QmlJSRefactoringFilePtr(new QmlJSRefactoringFile(filePath, m_data)); + return QmlJSRefactoringFilePtr(new QmlJSRefactoringFile(filePath, m_data.staticCast())); } QmlJSRefactoringFilePtr QmlJSRefactoringChanges::qmlJSFile(const Utils::FilePath &filePath) const @@ -61,8 +61,8 @@ QmlJSRefactoringChangesData *QmlJSRefactoringChanges::data() const } QmlJSRefactoringFile::QmlJSRefactoringFile( - const Utils::FilePath &filePath, const QSharedPointer &data) - : RefactoringFile(filePath, data) + const Utils::FilePath &filePath, const QSharedPointer &data) + : RefactoringFile(filePath), m_data(data) { // the RefactoringFile is invalid if its not for a file with qml or js code if (ModelManagerInterface::guessLanguageOfFile(filePath) == Dialect::NoLanguage) @@ -81,7 +81,7 @@ Document::Ptr QmlJSRefactoringFile::qmljsDocument() const { if (!m_qmljsDocument) { const QString source = document()->toPlainText(); - const Snapshot &snapshot = data()->m_snapshot; + const Snapshot &snapshot = m_data->m_snapshot; Document::MutablePtr newDoc = snapshot.documentFromSource(source, @@ -139,16 +139,11 @@ bool QmlJSRefactoringFile::isCursorOn(SourceLocation loc) const return pos >= loc.begin() && pos <= loc.end(); } -QmlJSRefactoringChangesData *QmlJSRefactoringFile::data() const -{ - return static_cast(m_data.data()); -} - void QmlJSRefactoringFile::fileChanged() { QTC_ASSERT(!m_filePath.isEmpty(), return); m_qmljsDocument.clear(); - data()->m_modelManager->updateSourceFiles({filePath()}, true); + m_data->m_modelManager->updateSourceFiles({filePath()}, true); } void QmlJSRefactoringFile::indentSelection(const QTextCursor &selection, diff --git a/src/plugins/qmljstools/qmljsrefactoringchanges.h b/src/plugins/qmljstools/qmljsrefactoringchanges.h index 8c5cf8501ae..11d23b382d6 100644 --- a/src/plugins/qmljstools/qmljsrefactoringchanges.h +++ b/src/plugins/qmljstools/qmljsrefactoringchanges.h @@ -36,11 +36,9 @@ public: private: QmlJSRefactoringFile(const Utils::FilePath &filePath, - const QSharedPointer &data); + const QSharedPointer &data); QmlJSRefactoringFile(TextEditor::TextEditorWidget *editor, QmlJS::Document::Ptr document); - QmlJSRefactoringChangesData *data() const; - void fileChanged() override; void indentSelection(const QTextCursor &selection, const TextEditor::TextDocument *textDocument) const override; @@ -48,6 +46,7 @@ private: const TextEditor::TextDocument *textDocument) const override; mutable QmlJS::Document::Ptr m_qmljsDocument; + QSharedPointer m_data; friend class QmlJSRefactoringChanges; }; diff --git a/src/plugins/texteditor/refactoringchanges.cpp b/src/plugins/texteditor/refactoringchanges.cpp index 659d06b1b9a..1f655bf7d63 100644 --- a/src/plugins/texteditor/refactoringchanges.cpp +++ b/src/plugins/texteditor/refactoringchanges.cpp @@ -78,7 +78,7 @@ TextEditorWidget *RefactoringChanges::openEditor(const FilePath &filePath, RefactoringFilePtr RefactoringChanges::file(const FilePath &filePath) const { - return RefactoringFilePtr(new RefactoringFile(filePath, m_data)); + return RefactoringFilePtr(new RefactoringFile(filePath)); } RefactoringFile::RefactoringFile(QTextDocument *document, const FilePath &filePath) @@ -91,10 +91,7 @@ RefactoringFile::RefactoringFile(TextEditorWidget *editor) , m_editor(editor) { } -RefactoringFile::RefactoringFile(const FilePath &filePath, - const QSharedPointer &data) - : m_filePath(filePath) - , m_data(data) +RefactoringFile::RefactoringFile(const FilePath &filePath) : m_filePath(filePath) { QList editors = DocumentModel::editorsForFilePath(filePath); if (!editors.isEmpty()) { @@ -307,7 +304,7 @@ bool RefactoringFile::apply() bool result = true; // apply changes, if any - if (m_data && !(m_indentRanges.isEmpty() && m_changes.isEmpty())) { + if (!m_indentRanges.isEmpty() || !m_changes.isEmpty()) { QTextDocument *doc = mutableDocument(); if (doc) { QTextCursor c = cursor(); diff --git a/src/plugins/texteditor/refactoringchanges.h b/src/plugins/texteditor/refactoringchanges.h index a147ba00826..95e250e9e01 100644 --- a/src/plugins/texteditor/refactoringchanges.h +++ b/src/plugins/texteditor/refactoringchanges.h @@ -68,8 +68,7 @@ protected: RefactoringFile(QTextDocument *document, const Utils::FilePath &filePath); RefactoringFile(TextEditorWidget *editor); - RefactoringFile(const Utils::FilePath &filePath, - const QSharedPointer &data); + RefactoringFile(const Utils::FilePath &filePath); QTextDocument *mutableDocument() const; @@ -88,7 +87,6 @@ protected: const TextDocument *textDocument) const; Utils::FilePath m_filePath; - QSharedPointer m_data; mutable Utils::TextFileFormat m_textFileFormat; mutable QTextDocument *m_document = nullptr; TextEditorWidget *m_editor = nullptr;