forked from qt-creator/qt-creator
TextEditor: filepathify RefactoringChanges
Change-Id: Ie97e484bcdeaa0cb2f5d04b3c79ace55ff2e426c Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -1465,7 +1465,8 @@ void CppModelManager::renameIncludes(const QString &oldFileName, const QString &
|
||||
const TextEditor::RefactoringChanges changes;
|
||||
|
||||
foreach (Snapshot::IncludeLocation loc, snapshot().includeLocationsOfDocument(oldFileName)) {
|
||||
TextEditor::RefactoringFilePtr file = changes.file(loc.first->fileName());
|
||||
TextEditor::RefactoringFilePtr file = changes.file(
|
||||
Utils::FilePath::fromString(loc.first->fileName()));
|
||||
const QTextBlock &block = file->document()->findBlockByNumber(loc.second - 1);
|
||||
const int replaceStart = block.text().indexOf(oldFileInfo.fileName());
|
||||
if (replaceStart > -1) {
|
||||
|
||||
@@ -47,13 +47,13 @@ namespace CppTools {
|
||||
|
||||
class CppRefactoringChangesData : public TextEditor::RefactoringChangesData
|
||||
{
|
||||
static std::unique_ptr<TextEditor::Indenter> createIndenter(const QString &fileName,
|
||||
static std::unique_ptr<TextEditor::Indenter> createIndenter(const Utils::FilePath &filePath,
|
||||
QTextDocument *textDocument)
|
||||
{
|
||||
TextEditor::ICodeStylePreferencesFactory *factory
|
||||
= TextEditor::TextEditorSettings::codeStyleFactory(CppTools::Constants::CPP_SETTINGS_ID);
|
||||
std::unique_ptr<TextEditor::Indenter> indenter(factory->createIndenter(textDocument));
|
||||
indenter->setFileName(Utils::FilePath::fromString(fileName));
|
||||
indenter->setFileName(filePath);
|
||||
return indenter;
|
||||
}
|
||||
|
||||
@@ -65,34 +65,36 @@ public:
|
||||
{}
|
||||
|
||||
void indentSelection(const QTextCursor &selection,
|
||||
const QString &fileName,
|
||||
const Utils::FilePath &filePath,
|
||||
const TextEditor::TextDocument *textDocument) const override
|
||||
{
|
||||
if (textDocument) { // use the indenter from the textDocument if there is one, can be ClangFormat
|
||||
textDocument->indenter()->indent(selection, QChar::Null, textDocument->tabSettings());
|
||||
} else {
|
||||
const auto &tabSettings = ProjectExplorer::actualTabSettings(fileName, textDocument);
|
||||
auto indenter = createIndenter(fileName, selection.document());
|
||||
const auto &tabSettings = ProjectExplorer::actualTabSettings(filePath.toString(),
|
||||
textDocument);
|
||||
auto indenter = createIndenter(filePath, selection.document());
|
||||
indenter->indent(selection, QChar::Null, tabSettings);
|
||||
}
|
||||
}
|
||||
|
||||
void reindentSelection(const QTextCursor &selection,
|
||||
const QString &fileName,
|
||||
const Utils::FilePath &filePath,
|
||||
const TextEditor::TextDocument *textDocument) const override
|
||||
{
|
||||
if (textDocument) { // use the indenter from the textDocument if there is one, can be ClangFormat
|
||||
textDocument->indenter()->reindent(selection, textDocument->tabSettings());
|
||||
} else {
|
||||
const auto &tabSettings = ProjectExplorer::actualTabSettings(fileName, textDocument);
|
||||
auto indenter = createIndenter(fileName, selection.document());
|
||||
const auto &tabSettings = ProjectExplorer::actualTabSettings(filePath.toString(),
|
||||
textDocument);
|
||||
auto indenter = createIndenter(filePath, selection.document());
|
||||
indenter->reindent(selection, tabSettings);
|
||||
}
|
||||
}
|
||||
|
||||
void fileChanged(const QString &fileName) override
|
||||
void fileChanged(const Utils::FilePath &filePath) override
|
||||
{
|
||||
m_modelManager->updateSourceFiles(QSet<QString>() << fileName);
|
||||
m_modelManager->updateSourceFiles({filePath.toString()});
|
||||
}
|
||||
|
||||
Snapshot m_snapshot;
|
||||
@@ -118,18 +120,19 @@ CppRefactoringFilePtr CppRefactoringChanges::file(TextEditor::TextEditorWidget *
|
||||
return result;
|
||||
}
|
||||
|
||||
CppRefactoringFilePtr CppRefactoringChanges::file(const QString &fileName) const
|
||||
CppRefactoringFilePtr CppRefactoringChanges::file(const Utils::FilePath &filePath) const
|
||||
{
|
||||
CppRefactoringFilePtr result(new CppRefactoringFile(fileName, m_data));
|
||||
CppRefactoringFilePtr result(new CppRefactoringFile(filePath, m_data));
|
||||
return result;
|
||||
}
|
||||
|
||||
CppRefactoringFileConstPtr CppRefactoringChanges::fileNoEditor(const QString &fileName) const
|
||||
CppRefactoringFileConstPtr CppRefactoringChanges::fileNoEditor(const Utils::FilePath &filePath) const
|
||||
{
|
||||
QTextDocument *document = nullptr;
|
||||
const QString fileName = filePath.toString();
|
||||
if (data()->m_workingCopy.contains(fileName))
|
||||
document = new QTextDocument(QString::fromUtf8(data()->m_workingCopy.source(fileName)));
|
||||
CppRefactoringFilePtr result(new CppRefactoringFile(document, fileName));
|
||||
CppRefactoringFilePtr result(new CppRefactoringFile(document, filePath));
|
||||
result->m_data = m_data;
|
||||
|
||||
return result;
|
||||
@@ -140,15 +143,15 @@ const Snapshot &CppRefactoringChanges::snapshot() const
|
||||
return data()->m_snapshot;
|
||||
}
|
||||
|
||||
CppRefactoringFile::CppRefactoringFile(const QString &fileName, const QSharedPointer<TextEditor::RefactoringChangesData> &data)
|
||||
: RefactoringFile(fileName, data)
|
||||
CppRefactoringFile::CppRefactoringFile(const Utils::FilePath &filePath, const QSharedPointer<TextEditor::RefactoringChangesData> &data)
|
||||
: RefactoringFile(filePath, data)
|
||||
{
|
||||
const Snapshot &snapshot = this->data()->m_snapshot;
|
||||
m_cppDocument = snapshot.document(fileName);
|
||||
m_cppDocument = snapshot.document(filePath.toString());
|
||||
}
|
||||
|
||||
CppRefactoringFile::CppRefactoringFile(QTextDocument *document, const QString &fileName)
|
||||
: RefactoringFile(document, fileName)
|
||||
CppRefactoringFile::CppRefactoringFile(QTextDocument *document, const Utils::FilePath &filePath)
|
||||
: RefactoringFile(document, filePath)
|
||||
{ }
|
||||
|
||||
CppRefactoringFile::CppRefactoringFile(TextEditor::TextEditorWidget *editor)
|
||||
@@ -160,7 +163,7 @@ Document::Ptr CppRefactoringFile::cppDocument() const
|
||||
if (!m_cppDocument || !m_cppDocument->translationUnit() ||
|
||||
!m_cppDocument->translationUnit()->ast()) {
|
||||
const QByteArray source = document()->toPlainText().toUtf8();
|
||||
const QString name = fileName();
|
||||
const QString name = filePath().toString();
|
||||
const Snapshot &snapshot = data()->m_snapshot;
|
||||
|
||||
m_cppDocument = snapshot.preprocessedDocument(source, name);
|
||||
|
||||
@@ -67,8 +67,8 @@ public:
|
||||
QString textOf(const CPlusPlus::AST *ast) const;
|
||||
|
||||
protected:
|
||||
CppRefactoringFile(const QString &fileName, const QSharedPointer<TextEditor::RefactoringChangesData> &data);
|
||||
CppRefactoringFile(QTextDocument *document, const QString &fileName);
|
||||
CppRefactoringFile(const Utils::FilePath &filePath, const QSharedPointer<TextEditor::RefactoringChangesData> &data);
|
||||
CppRefactoringFile(QTextDocument *document, const Utils::FilePath &filePath);
|
||||
explicit CppRefactoringFile(TextEditor::TextEditorWidget *editor);
|
||||
|
||||
CppRefactoringChangesData *data() const;
|
||||
@@ -86,9 +86,9 @@ public:
|
||||
|
||||
static CppRefactoringFilePtr file(TextEditor::TextEditorWidget *editor,
|
||||
const CPlusPlus::Document::Ptr &document);
|
||||
CppRefactoringFilePtr file(const QString &fileName) const;
|
||||
CppRefactoringFilePtr file(const Utils::FilePath &filePath) const;
|
||||
// safe to use from non-gui threads
|
||||
CppRefactoringFileConstPtr fileNoEditor(const QString &fileName) const;
|
||||
CppRefactoringFileConstPtr fileNoEditor(const Utils::FilePath &filePath) const;
|
||||
|
||||
const CPlusPlus::Snapshot &snapshot() const;
|
||||
|
||||
|
||||
@@ -276,7 +276,8 @@ InsertionLocation InsertionPointLocator::methodDeclarationInClass(
|
||||
AccessSpec xsSpec,
|
||||
ForceAccessSpec forceAccessSpec) const
|
||||
{
|
||||
const Document::Ptr doc = m_refactoringChanges.file(fileName)->cppDocument();
|
||||
const Document::Ptr doc = m_refactoringChanges.file(Utils::FilePath::fromString(fileName))
|
||||
->cppDocument();
|
||||
if (doc) {
|
||||
FindInClass find(doc->translationUnit(), clazz);
|
||||
ClassSpecifierAST *classAST = find();
|
||||
@@ -620,7 +621,8 @@ static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration,
|
||||
targetDoc->translationUnit()->getPosition(definitionFunction->endOffset(), &line, &column);
|
||||
} else {
|
||||
// we don't have an offset to the start of the function definition, so we need to manually find it...
|
||||
CppRefactoringFilePtr targetFile = changes.file(QString::fromUtf8(definitionFunction->fileName()));
|
||||
CppRefactoringFilePtr targetFile = changes.file(
|
||||
Utils::FilePath::fromString(QString::fromUtf8(definitionFunction->fileName())));
|
||||
if (!targetFile->isValid())
|
||||
return noResult;
|
||||
|
||||
@@ -675,7 +677,8 @@ const QList<InsertionLocation> InsertionPointLocator::methodDefinition(
|
||||
target = candidate;
|
||||
}
|
||||
|
||||
CppRefactoringFilePtr targetFile = m_refactoringChanges.file(target);
|
||||
CppRefactoringFilePtr targetFile = m_refactoringChanges.file(
|
||||
Utils::FilePath::fromString(target));
|
||||
Document::Ptr doc = targetFile->cppDocument();
|
||||
if (doc.isNull())
|
||||
return result;
|
||||
@@ -783,7 +786,7 @@ InsertionLocation insertLocationForMethodDefinition(Symbol *symbol,
|
||||
{
|
||||
QTC_ASSERT(symbol, return InsertionLocation());
|
||||
|
||||
CppRefactoringFilePtr file = refactoring.file(fileName);
|
||||
CppRefactoringFilePtr file = refactoring.file(Utils::FilePath::fromString(fileName));
|
||||
QStringList requiredNamespaces;
|
||||
if (namespaceHandling == NamespaceHandling::CreateMissing) {
|
||||
requiredNamespaces = getNamespaceNames(symbol);
|
||||
|
||||
Reference in New Issue
Block a user