forked from qt-creator/qt-creator
TextEditor: Remove RefactoringFile::m_data
There is no use for a generic data member. Change-Id: Iabfbc0587db2cffcc1c19baed832aa866f696ffe 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:
@@ -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<CppRefactoringChangesData>()));
|
||||
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<CppRefactoringChangesData>();
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -77,10 +77,10 @@ const Snapshot &CppRefactoringChanges::snapshot() const
|
||||
return data()->m_snapshot;
|
||||
}
|
||||
|
||||
CppRefactoringFile::CppRefactoringFile(const FilePath &filePath, const QSharedPointer<TextEditor::RefactoringChangesData> &data)
|
||||
: RefactoringFile(filePath, data)
|
||||
CppRefactoringFile::CppRefactoringFile(const FilePath &filePath, const QSharedPointer<CppRefactoringChangesData> &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<CppRefactoringChangesData *>(m_data.data());
|
||||
}
|
||||
|
||||
void CppRefactoringFile::fileChanged()
|
||||
{
|
||||
QTC_ASSERT(!m_filePath.isEmpty(), return);
|
||||
|
||||
@@ -52,12 +52,10 @@ public:
|
||||
QString textOf(const CPlusPlus::AST *ast) const;
|
||||
|
||||
private:
|
||||
CppRefactoringFile(const Utils::FilePath &filePath, const QSharedPointer<TextEditor::RefactoringChangesData> &data);
|
||||
CppRefactoringFile(const Utils::FilePath &filePath, const QSharedPointer<CppRefactoringChangesData> &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<CppRefactoringChangesData> m_data;
|
||||
|
||||
friend class CppRefactoringChanges; // for access to constructor
|
||||
};
|
||||
|
||||
@@ -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<QmlJSRefactoringChangesData>()));
|
||||
}
|
||||
|
||||
QmlJSRefactoringFilePtr QmlJSRefactoringChanges::qmlJSFile(const Utils::FilePath &filePath) const
|
||||
@@ -61,8 +61,8 @@ QmlJSRefactoringChangesData *QmlJSRefactoringChanges::data() const
|
||||
}
|
||||
|
||||
QmlJSRefactoringFile::QmlJSRefactoringFile(
|
||||
const Utils::FilePath &filePath, const QSharedPointer<TextEditor::RefactoringChangesData> &data)
|
||||
: RefactoringFile(filePath, data)
|
||||
const Utils::FilePath &filePath, const QSharedPointer<QmlJSRefactoringChangesData> &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<QmlJSRefactoringChangesData *>(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,
|
||||
|
||||
@@ -36,11 +36,9 @@ public:
|
||||
|
||||
private:
|
||||
QmlJSRefactoringFile(const Utils::FilePath &filePath,
|
||||
const QSharedPointer<TextEditor::RefactoringChangesData> &data);
|
||||
const QSharedPointer<QmlJSRefactoringChangesData> &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<QmlJSRefactoringChangesData> m_data;
|
||||
|
||||
friend class QmlJSRefactoringChanges;
|
||||
};
|
||||
|
||||
@@ -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<RefactoringChangesData> &data)
|
||||
: m_filePath(filePath)
|
||||
, m_data(data)
|
||||
RefactoringFile::RefactoringFile(const FilePath &filePath) : m_filePath(filePath)
|
||||
{
|
||||
QList<IEditor *> 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();
|
||||
|
||||
@@ -68,8 +68,7 @@ protected:
|
||||
RefactoringFile(QTextDocument *document, const Utils::FilePath &filePath);
|
||||
|
||||
RefactoringFile(TextEditorWidget *editor);
|
||||
RefactoringFile(const Utils::FilePath &filePath,
|
||||
const QSharedPointer<RefactoringChangesData> &data);
|
||||
RefactoringFile(const Utils::FilePath &filePath);
|
||||
|
||||
QTextDocument *mutableDocument() const;
|
||||
|
||||
@@ -88,7 +87,6 @@ protected:
|
||||
const TextDocument *textDocument) const;
|
||||
|
||||
Utils::FilePath m_filePath;
|
||||
QSharedPointer<RefactoringChangesData> m_data;
|
||||
mutable Utils::TextFileFormat m_textFileFormat;
|
||||
mutable QTextDocument *m_document = nullptr;
|
||||
TextEditorWidget *m_editor = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user