TextEditor: Remove RefactoringChanges::m_data

There is no use for a data member in the base class.

Change-Id: I126d8713d2a7bf4061ecbd60b4c144d39c08d550
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2023-11-16 17:33:35 +01:00
parent 5d6fc1fc3b
commit 246a878a34
6 changed files with 9 additions and 27 deletions

View File

@@ -34,15 +34,10 @@ static std::unique_ptr<TextEditor::Indenter> createIndenter(const FilePath &file
} }
CppRefactoringChanges::CppRefactoringChanges(const Snapshot &snapshot) CppRefactoringChanges::CppRefactoringChanges(const Snapshot &snapshot)
: RefactoringChanges(new CppRefactoringChangesData(snapshot)) : m_data(new CppRefactoringChangesData(snapshot))
{ {
} }
CppRefactoringChangesData *CppRefactoringChanges::data() const
{
return static_cast<CppRefactoringChangesData *>(m_data.data());
}
CppRefactoringFilePtr CppRefactoringChanges::file(TextEditor::TextEditorWidget *editor, const Document::Ptr &document) CppRefactoringFilePtr CppRefactoringChanges::file(TextEditor::TextEditorWidget *editor, const Document::Ptr &document)
{ {
CppRefactoringFilePtr result(new CppRefactoringFile(editor)); CppRefactoringFilePtr result(new CppRefactoringFile(editor));
@@ -52,8 +47,7 @@ CppRefactoringFilePtr CppRefactoringChanges::file(TextEditor::TextEditorWidget *
TextEditor::RefactoringFilePtr CppRefactoringChanges::file(const FilePath &filePath) const TextEditor::RefactoringFilePtr CppRefactoringChanges::file(const FilePath &filePath) const
{ {
CppRefactoringFilePtr result(new CppRefactoringFile(filePath, m_data.staticCast<CppRefactoringChangesData>())); return TextEditor::RefactoringFilePtr(new CppRefactoringFile(filePath, m_data));
return result;
} }
CppRefactoringFilePtr CppRefactoringChanges::cppFile(const Utils::FilePath &filePath) const CppRefactoringFilePtr CppRefactoringChanges::cppFile(const Utils::FilePath &filePath) const
@@ -64,7 +58,7 @@ CppRefactoringFilePtr CppRefactoringChanges::cppFile(const Utils::FilePath &file
CppRefactoringFileConstPtr CppRefactoringChanges::fileNoEditor(const FilePath &filePath) const CppRefactoringFileConstPtr CppRefactoringChanges::fileNoEditor(const FilePath &filePath) const
{ {
QTextDocument *document = nullptr; QTextDocument *document = nullptr;
if (const auto source = data()->m_workingCopy.source(filePath)) if (const auto source = m_data->m_workingCopy.source(filePath))
document = new QTextDocument(QString::fromUtf8(*source)); document = new QTextDocument(QString::fromUtf8(*source));
CppRefactoringFilePtr result(new CppRefactoringFile(document, filePath)); CppRefactoringFilePtr result(new CppRefactoringFile(document, filePath));
result->m_data = m_data.staticCast<CppRefactoringChangesData>(); result->m_data = m_data.staticCast<CppRefactoringChangesData>();
@@ -74,7 +68,7 @@ CppRefactoringFileConstPtr CppRefactoringChanges::fileNoEditor(const FilePath &f
const Snapshot &CppRefactoringChanges::snapshot() const const Snapshot &CppRefactoringChanges::snapshot() const
{ {
return data()->m_snapshot; return m_data->m_snapshot;
} }
CppRefactoringFile::CppRefactoringFile(const FilePath &filePath, const QSharedPointer<CppRefactoringChangesData> &data) CppRefactoringFile::CppRefactoringFile(const FilePath &filePath, const QSharedPointer<CppRefactoringChangesData> &data)

View File

@@ -98,7 +98,7 @@ public:
const CPlusPlus::Snapshot &snapshot() const; const CPlusPlus::Snapshot &snapshot() const;
private: private:
CppRefactoringChangesData *data() const; const QSharedPointer<CppRefactoringChangesData> m_data;
}; };
} // namespace CppEditor } // namespace CppEditor

View File

@@ -30,13 +30,13 @@ public:
QmlJSRefactoringChanges::QmlJSRefactoringChanges(ModelManagerInterface *modelManager, QmlJSRefactoringChanges::QmlJSRefactoringChanges(ModelManagerInterface *modelManager,
const Snapshot &snapshot) const Snapshot &snapshot)
: RefactoringChanges(new QmlJSRefactoringChangesData(modelManager, snapshot)) : m_data(new QmlJSRefactoringChangesData(modelManager, snapshot))
{ {
} }
TextEditor::RefactoringFilePtr QmlJSRefactoringChanges::file(const Utils::FilePath &filePath) const TextEditor::RefactoringFilePtr QmlJSRefactoringChanges::file(const Utils::FilePath &filePath) const
{ {
return QmlJSRefactoringFilePtr(new QmlJSRefactoringFile(filePath, m_data.staticCast<QmlJSRefactoringChangesData>())); return QmlJSRefactoringFilePtr(new QmlJSRefactoringFile(filePath, m_data));
} }
QmlJSRefactoringFilePtr QmlJSRefactoringChanges::qmlJSFile(const Utils::FilePath &filePath) const QmlJSRefactoringFilePtr QmlJSRefactoringChanges::qmlJSFile(const Utils::FilePath &filePath) const
@@ -52,12 +52,7 @@ QmlJSRefactoringFilePtr QmlJSRefactoringChanges::file(
const Snapshot &QmlJSRefactoringChanges::snapshot() const const Snapshot &QmlJSRefactoringChanges::snapshot() const
{ {
return data()->m_snapshot; return m_data->m_snapshot;
}
QmlJSRefactoringChangesData *QmlJSRefactoringChanges::data() const
{
return static_cast<QmlJSRefactoringChangesData *>(m_data.data());
} }
QmlJSRefactoringFile::QmlJSRefactoringFile( QmlJSRefactoringFile::QmlJSRefactoringFile(

View File

@@ -67,7 +67,7 @@ public:
const QmlJS::Snapshot &snapshot() const; const QmlJS::Snapshot &snapshot() const;
private: private:
QmlJSRefactoringChangesData *data() const; const QSharedPointer<QmlJSRefactoringChangesData> m_data;
}; };
} // namespace QmlJSTools } // namespace QmlJSTools

View File

@@ -26,10 +26,6 @@ using namespace Utils;
namespace TextEditor { namespace TextEditor {
RefactoringChanges::RefactoringChanges(RefactoringChangesData *data)
: m_data(data ? data : new RefactoringChangesData)
{}
RefactoringChanges::~RefactoringChanges() = default; RefactoringChanges::~RefactoringChanges() = default;
RefactoringSelections RefactoringChanges::rangesToSelections(QTextDocument *document, RefactoringSelections RefactoringChanges::rangesToSelections(QTextDocument *document,

View File

@@ -112,7 +112,6 @@ class TEXTEDITOR_EXPORT RefactoringChanges
public: public:
using Range = Utils::ChangeSet::Range; using Range = Utils::ChangeSet::Range;
explicit RefactoringChanges(RefactoringChangesData *data = nullptr);
virtual ~RefactoringChanges(); virtual ~RefactoringChanges();
// TODO: Make pure virtual and introduce dedicated subclass for generic refactoring, // TODO: Make pure virtual and introduce dedicated subclass for generic refactoring,
@@ -132,8 +131,6 @@ protected:
static RefactoringSelections rangesToSelections(QTextDocument *document, static RefactoringSelections rangesToSelections(QTextDocument *document,
const QList<Range> &ranges); const QList<Range> &ranges);
QSharedPointer<RefactoringChangesData> m_data;
friend class RefactoringFile; friend class RefactoringFile;
}; };