2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2010-06-14 14:52:43 +02:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2010-06-14 14:52:43 +02:00
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
#include "cppeditor_global.h"
|
2010-06-14 14:52:43 +02:00
|
|
|
|
2022-02-03 10:36:40 +01:00
|
|
|
#include "cppmodelmanager.h"
|
|
|
|
|
#include "cppworkingcopy.h"
|
|
|
|
|
|
2015-03-05 08:22:48 +01:00
|
|
|
#include <cplusplus/CppDocument.h>
|
2010-06-14 14:52:43 +02:00
|
|
|
|
2015-03-05 08:22:48 +01:00
|
|
|
#include <texteditor/refactoringchanges.h>
|
2013-03-27 18:54:03 +01:00
|
|
|
|
2023-07-10 12:58:26 +02:00
|
|
|
#include <optional>
|
|
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
namespace CppEditor {
|
2010-06-14 14:52:43 +02:00
|
|
|
|
2010-08-13 11:48:29 +02:00
|
|
|
class CppRefactoringChanges;
|
2011-08-17 11:35:57 +02:00
|
|
|
class CppRefactoringFile;
|
|
|
|
|
class CppRefactoringChangesData;
|
2019-01-14 01:40:53 +01:00
|
|
|
using CppRefactoringFilePtr = QSharedPointer<CppRefactoringFile>;
|
|
|
|
|
using CppRefactoringFileConstPtr = QSharedPointer<const CppRefactoringFile>;
|
2010-08-13 11:48:29 +02:00
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
class CPPEDITOR_EXPORT CppRefactoringFile: public TextEditor::RefactoringFile
|
2010-08-13 11:48:29 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CPlusPlus::Document::Ptr cppDocument() const;
|
2011-08-10 09:50:04 +02:00
|
|
|
void setCppDocument(CPlusPlus::Document::Ptr document);
|
2010-08-13 11:48:29 +02:00
|
|
|
|
|
|
|
|
CPlusPlus::Scope *scopeAt(unsigned index) const;
|
|
|
|
|
|
|
|
|
|
bool isCursorOn(unsigned tokenIndex) const;
|
|
|
|
|
bool isCursorOn(const CPlusPlus::AST *ast) const;
|
|
|
|
|
|
|
|
|
|
Range range(int start, int end) const;
|
|
|
|
|
Range range(unsigned tokenIndex) const;
|
2020-10-16 16:38:25 +02:00
|
|
|
Range range(const CPlusPlus::AST *ast) const;
|
2010-08-13 11:48:29 +02:00
|
|
|
|
|
|
|
|
const CPlusPlus::Token &tokenAt(unsigned index) const;
|
|
|
|
|
|
|
|
|
|
int startOf(unsigned index) const;
|
|
|
|
|
int startOf(const CPlusPlus::AST *ast) const;
|
|
|
|
|
int endOf(unsigned index) const;
|
|
|
|
|
int endOf(const CPlusPlus::AST *ast) const;
|
|
|
|
|
|
|
|
|
|
void startAndEndOf(unsigned index, int *start, int *end) const;
|
|
|
|
|
|
2023-07-10 12:58:26 +02:00
|
|
|
QList<CPlusPlus::Token> tokensForCursor() const;
|
|
|
|
|
|
2010-08-13 11:48:29 +02:00
|
|
|
using TextEditor::RefactoringFile::textOf;
|
|
|
|
|
QString textOf(const CPlusPlus::AST *ast) const;
|
|
|
|
|
|
2011-08-10 09:50:04 +02:00
|
|
|
protected:
|
2021-05-28 12:02:36 +02:00
|
|
|
CppRefactoringFile(const Utils::FilePath &filePath, const QSharedPointer<TextEditor::RefactoringChangesData> &data);
|
|
|
|
|
CppRefactoringFile(QTextDocument *document, const Utils::FilePath &filePath);
|
2019-01-14 01:40:53 +01:00
|
|
|
explicit CppRefactoringFile(TextEditor::TextEditorWidget *editor);
|
2011-08-10 09:50:04 +02:00
|
|
|
|
2011-08-17 11:35:57 +02:00
|
|
|
CppRefactoringChangesData *data() const;
|
2018-05-07 15:06:32 +02:00
|
|
|
void fileChanged() override;
|
2010-08-13 11:48:29 +02:00
|
|
|
|
2023-07-10 12:58:26 +02:00
|
|
|
int tokenIndexForPosition(const std::vector<CPlusPlus::Token> &tokens, int pos,
|
|
|
|
|
int startIndex) const;
|
|
|
|
|
|
2010-08-13 11:48:29 +02:00
|
|
|
mutable CPlusPlus::Document::Ptr m_cppDocument;
|
2011-08-10 09:50:04 +02:00
|
|
|
|
|
|
|
|
friend class CppRefactoringChanges; // for access to constructor
|
2010-08-13 11:48:29 +02:00
|
|
|
};
|
|
|
|
|
|
2022-02-03 10:36:40 +01:00
|
|
|
class CPPEDITOR_EXPORT CppRefactoringChangesData : public TextEditor::RefactoringChangesData
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit CppRefactoringChangesData(const CPlusPlus::Snapshot &snapshot);
|
|
|
|
|
|
|
|
|
|
void indentSelection(const QTextCursor &selection,
|
|
|
|
|
const Utils::FilePath &filePath,
|
|
|
|
|
const TextEditor::TextDocument *textDocument) const override;
|
|
|
|
|
|
|
|
|
|
void reindentSelection(const QTextCursor &selection,
|
|
|
|
|
const Utils::FilePath &filePath,
|
|
|
|
|
const TextEditor::TextDocument *textDocument) const override;
|
|
|
|
|
|
|
|
|
|
void fileChanged(const Utils::FilePath &filePath) override;
|
|
|
|
|
|
|
|
|
|
CPlusPlus::Snapshot m_snapshot;
|
|
|
|
|
WorkingCopy m_workingCopy;
|
|
|
|
|
};
|
|
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
class CPPEDITOR_EXPORT CppRefactoringChanges: public TextEditor::RefactoringChanges
|
2010-06-14 14:52:43 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2019-01-14 01:40:53 +01:00
|
|
|
explicit CppRefactoringChanges(const CPlusPlus::Snapshot &snapshot);
|
2010-06-14 14:52:43 +02:00
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
static CppRefactoringFilePtr file(TextEditor::TextEditorWidget *editor,
|
2011-08-17 11:35:57 +02:00
|
|
|
const CPlusPlus::Document::Ptr &document);
|
2023-11-16 15:45:02 +01:00
|
|
|
TextEditor::RefactoringFilePtr file(const Utils::FilePath &filePath) const override;
|
|
|
|
|
|
|
|
|
|
CppRefactoringFilePtr cppFile(const Utils::FilePath &filePath) const;
|
|
|
|
|
|
2011-08-17 11:35:57 +02:00
|
|
|
// safe to use from non-gui threads
|
2021-05-28 12:02:36 +02:00
|
|
|
CppRefactoringFileConstPtr fileNoEditor(const Utils::FilePath &filePath) const;
|
2010-08-12 14:18:36 +02:00
|
|
|
|
2011-08-17 11:35:57 +02:00
|
|
|
const CPlusPlus::Snapshot &snapshot() const;
|
2010-08-12 11:34:48 +02:00
|
|
|
|
2010-06-14 14:52:43 +02:00
|
|
|
private:
|
2011-08-17 11:35:57 +02:00
|
|
|
CppRefactoringChangesData *data() const;
|
2010-06-14 14:52:43 +02:00
|
|
|
};
|
|
|
|
|
|
2021-08-30 10:58:08 +02:00
|
|
|
} // namespace CppEditor
|