2018-05-24 09:03:44 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#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;
|
|
|
|
|
FixitsRefactoringFile(const QString &filePath) : m_filePath(filePath) {}
|
2018-06-27 15:29:14 +02:00
|
|
|
~FixitsRefactoringFile() { qDeleteAll(m_documents); }
|
2018-05-24 09:03:44 +02:00
|
|
|
|
|
|
|
|
bool isValid() const { return !m_filePath.isEmpty(); }
|
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,
|
|
|
|
|
const TextEditor::Replacements &replacements,
|
|
|
|
|
int startIndex);
|
|
|
|
|
bool hasIntersection(const QString &fileName,
|
|
|
|
|
const TextEditor::Replacements &replacements,
|
|
|
|
|
int startIndex) const;
|
|
|
|
|
|
2018-05-24 09:03:44 +02:00
|
|
|
QString m_filePath;
|
|
|
|
|
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
|