2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2018-05-24 09:03:44 +02:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2019-01-16 09:37:54 +01:00
|
|
|
#include <texteditor/indenter.h>
|
|
|
|
|
|
2018-05-24 09:03:44 +02:00
|
|
|
#include <utils/changeset.h>
|
|
|
|
|
#include <utils/textfileformat.h>
|
|
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
#include <QTextDocument>
|
|
|
|
|
#include <QVector>
|
|
|
|
|
|
|
|
|
|
namespace ClangTools {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class ReplacementOperation
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
int pos = -1;
|
|
|
|
|
int length = -1;
|
|
|
|
|
QString text;
|
2018-06-27 15:29:14 +02:00
|
|
|
QString fileName;
|
2018-05-24 09:03:44 +02:00
|
|
|
bool apply = false;
|
|
|
|
|
};
|
|
|
|
|
using ReplacementOperations = QVector<ReplacementOperation *>;
|
|
|
|
|
|
|
|
|
|
/// Simplified version of TextEditor::RefactoringFile that allows
|
|
|
|
|
/// to operate on not owned ReplamentOperations
|
|
|
|
|
class FixitsRefactoringFile
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FixitsRefactoringFile() = default;
|
2018-06-27 15:29:14 +02:00
|
|
|
~FixitsRefactoringFile() { qDeleteAll(m_documents); }
|
2018-05-24 09:03:44 +02:00
|
|
|
|
2018-06-27 15:29:14 +02:00
|
|
|
int position(const QString &filePath, unsigned line, unsigned column) const;
|
2018-05-24 09:03:44 +02:00
|
|
|
|
|
|
|
|
void setReplacements(const ReplacementOperations &ops) { m_replacementOperations = ops; }
|
|
|
|
|
bool apply();
|
|
|
|
|
|
|
|
|
|
private:
|
2018-06-27 15:29:14 +02:00
|
|
|
QTextDocument *document(const QString &filePath) const;
|
2018-05-24 09:03:44 +02:00
|
|
|
void shiftAffectedReplacements(const ReplacementOperation &op, int startIndex);
|
|
|
|
|
|
2019-02-13 14:17:21 +01:00
|
|
|
void format(TextEditor::Indenter &indenter,
|
|
|
|
|
QTextDocument *doc,
|
|
|
|
|
const ReplacementOperations &operationsForFile,
|
|
|
|
|
int firstOperationIndex);
|
2018-11-09 11:07:54 +01:00
|
|
|
void shiftAffectedReplacements(const QString &fileName,
|
2020-01-08 10:43:13 +01:00
|
|
|
const Utils::Text::Replacements &replacements,
|
2018-11-09 11:07:54 +01:00
|
|
|
int startIndex);
|
|
|
|
|
bool hasIntersection(const QString &fileName,
|
2020-01-08 10:43:13 +01:00
|
|
|
const Utils::Text::Replacements &replacements,
|
2018-11-09 11:07:54 +01:00
|
|
|
int startIndex) const;
|
|
|
|
|
|
2018-05-24 09:03:44 +02:00
|
|
|
mutable Utils::TextFileFormat m_textFileFormat;
|
2018-06-27 15:29:14 +02:00
|
|
|
mutable QHash<QString, QTextDocument *> m_documents;
|
2018-05-24 09:03:44 +02:00
|
|
|
ReplacementOperations m_replacementOperations; // Not owned.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ClangTools
|