forked from qt-creator/qt-creator
CppEditor: Remove WorkingCopy::{revision,source}(QString) overloads
... and fix fallout. Change-Id: I3748d0f90345c0d92321d465abfc3d324ee49a0c Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -3,8 +3,6 @@
|
|||||||
|
|
||||||
#include "cpprefactoringchanges.h"
|
#include "cpprefactoringchanges.h"
|
||||||
|
|
||||||
#include "cppqtstyleindenter.h"
|
|
||||||
#include "cppcodeformatter.h"
|
|
||||||
#include "cppeditorconstants.h"
|
#include "cppeditorconstants.h"
|
||||||
|
|
||||||
#include <projectexplorer/editorconfiguration.h>
|
#include <projectexplorer/editorconfiguration.h>
|
||||||
@@ -12,16 +10,18 @@
|
|||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <texteditor/icodestylepreferencesfactory.h>
|
#include <texteditor/icodestylepreferencesfactory.h>
|
||||||
|
#include <texteditor/tabsettings.h>
|
||||||
#include <texteditor/textdocument.h>
|
#include <texteditor/textdocument.h>
|
||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
|
||||||
using namespace CPlusPlus;
|
using namespace CPlusPlus;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace CppEditor {
|
namespace CppEditor {
|
||||||
|
|
||||||
static std::unique_ptr<TextEditor::Indenter> createIndenter(const Utils::FilePath &filePath,
|
static std::unique_ptr<TextEditor::Indenter> createIndenter(const FilePath &filePath,
|
||||||
QTextDocument *textDocument)
|
QTextDocument *textDocument)
|
||||||
{
|
{
|
||||||
TextEditor::ICodeStylePreferencesFactory *factory
|
TextEditor::ICodeStylePreferencesFactory *factory
|
||||||
@@ -48,18 +48,17 @@ CppRefactoringFilePtr CppRefactoringChanges::file(TextEditor::TextEditorWidget *
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CppRefactoringFilePtr CppRefactoringChanges::file(const Utils::FilePath &filePath) const
|
CppRefactoringFilePtr CppRefactoringChanges::file(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
CppRefactoringFilePtr result(new CppRefactoringFile(filePath, m_data));
|
CppRefactoringFilePtr result(new CppRefactoringFile(filePath, m_data));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
CppRefactoringFileConstPtr CppRefactoringChanges::fileNoEditor(const Utils::FilePath &filePath) const
|
CppRefactoringFileConstPtr CppRefactoringChanges::fileNoEditor(const FilePath &filePath) const
|
||||||
{
|
{
|
||||||
QTextDocument *document = nullptr;
|
QTextDocument *document = nullptr;
|
||||||
const QString fileName = filePath.toString();
|
if (data()->m_workingCopy.contains(filePath))
|
||||||
if (data()->m_workingCopy.contains(fileName))
|
document = new QTextDocument(QString::fromUtf8(data()->m_workingCopy.source(filePath)));
|
||||||
document = new QTextDocument(QString::fromUtf8(data()->m_workingCopy.source(fileName)));
|
|
||||||
CppRefactoringFilePtr result(new CppRefactoringFile(document, filePath));
|
CppRefactoringFilePtr result(new CppRefactoringFile(document, filePath));
|
||||||
result->m_data = m_data;
|
result->m_data = m_data;
|
||||||
|
|
||||||
@@ -71,14 +70,14 @@ const Snapshot &CppRefactoringChanges::snapshot() const
|
|||||||
return data()->m_snapshot;
|
return data()->m_snapshot;
|
||||||
}
|
}
|
||||||
|
|
||||||
CppRefactoringFile::CppRefactoringFile(const Utils::FilePath &filePath, const QSharedPointer<TextEditor::RefactoringChangesData> &data)
|
CppRefactoringFile::CppRefactoringFile(const FilePath &filePath, const QSharedPointer<TextEditor::RefactoringChangesData> &data)
|
||||||
: RefactoringFile(filePath, data)
|
: RefactoringFile(filePath, data)
|
||||||
{
|
{
|
||||||
const Snapshot &snapshot = this->data()->m_snapshot;
|
const Snapshot &snapshot = this->data()->m_snapshot;
|
||||||
m_cppDocument = snapshot.document(filePath.toString());
|
m_cppDocument = snapshot.document(filePath.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
CppRefactoringFile::CppRefactoringFile(QTextDocument *document, const Utils::FilePath &filePath)
|
CppRefactoringFile::CppRefactoringFile(QTextDocument *document, const FilePath &filePath)
|
||||||
: RefactoringFile(document, filePath)
|
: RefactoringFile(document, filePath)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
@@ -134,7 +133,7 @@ bool CppRefactoringFile::isCursorOn(const AST *ast) const
|
|||||||
return cursorBegin >= start && cursorBegin <= end;
|
return cursorBegin >= start && cursorBegin <= end;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::ChangeSet::Range CppRefactoringFile::range(unsigned tokenIndex) const
|
ChangeSet::Range CppRefactoringFile::range(unsigned tokenIndex) const
|
||||||
{
|
{
|
||||||
const Token &token = tokenAt(tokenIndex);
|
const Token &token = tokenAt(tokenIndex);
|
||||||
int line, column;
|
int line, column;
|
||||||
@@ -143,7 +142,7 @@ Utils::ChangeSet::Range CppRefactoringFile::range(unsigned tokenIndex) const
|
|||||||
return {start, start + token.utf16chars()};
|
return {start, start + token.utf16chars()};
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::ChangeSet::Range CppRefactoringFile::range(const AST *ast) const
|
ChangeSet::Range CppRefactoringFile::range(const AST *ast) const
|
||||||
{
|
{
|
||||||
return {startOf(ast), endOf(ast)};
|
return {startOf(ast), endOf(ast)};
|
||||||
}
|
}
|
||||||
@@ -218,7 +217,7 @@ CppRefactoringChangesData::CppRefactoringChangesData(const Snapshot &snapshot)
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
void CppRefactoringChangesData::indentSelection(const QTextCursor &selection,
|
void CppRefactoringChangesData::indentSelection(const QTextCursor &selection,
|
||||||
const Utils::FilePath &filePath,
|
const FilePath &filePath,
|
||||||
const TextEditor::TextDocument *textDocument) const
|
const TextEditor::TextDocument *textDocument) const
|
||||||
{
|
{
|
||||||
if (textDocument) { // use the indenter from the textDocument if there is one, can be ClangFormat
|
if (textDocument) { // use the indenter from the textDocument if there is one, can be ClangFormat
|
||||||
@@ -231,7 +230,7 @@ void CppRefactoringChangesData::indentSelection(const QTextCursor &selection,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CppRefactoringChangesData::reindentSelection(const QTextCursor &selection,
|
void CppRefactoringChangesData::reindentSelection(const QTextCursor &selection,
|
||||||
const Utils::FilePath &filePath,
|
const FilePath &filePath,
|
||||||
const TextEditor::TextDocument *textDocument) const
|
const TextEditor::TextDocument *textDocument) const
|
||||||
{
|
{
|
||||||
if (textDocument) { // use the indenter from the textDocument if there is one, can be ClangFormat
|
if (textDocument) { // use the indenter from the textDocument if there is one, can be ClangFormat
|
||||||
@@ -243,9 +242,9 @@ void CppRefactoringChangesData::reindentSelection(const QTextCursor &selection,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppRefactoringChangesData::fileChanged(const Utils::FilePath &filePath)
|
void CppRefactoringChangesData::fileChanged(const FilePath &filePath)
|
||||||
{
|
{
|
||||||
m_modelManager->updateSourceFiles({filePath.toString()});
|
m_modelManager->updateSourceFiles({filePath.toString()});
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace CppEditor
|
} // CppEditor
|
||||||
|
@@ -30,15 +30,9 @@ public:
|
|||||||
bool contains(const Utils::FilePath &fileName) const
|
bool contains(const Utils::FilePath &fileName) const
|
||||||
{ return _elements.contains(fileName); }
|
{ return _elements.contains(fileName); }
|
||||||
|
|
||||||
QByteArray source(const QString &fileName) const
|
|
||||||
{ return source(Utils::FilePath::fromString(fileName)); }
|
|
||||||
|
|
||||||
QByteArray source(const Utils::FilePath &fileName) const
|
QByteArray source(const Utils::FilePath &fileName) const
|
||||||
{ return _elements.value(fileName).first; }
|
{ return _elements.value(fileName).first; }
|
||||||
|
|
||||||
unsigned revision(const QString &fileName) const
|
|
||||||
{ return revision(Utils::FilePath::fromString(fileName)); }
|
|
||||||
|
|
||||||
unsigned revision(const Utils::FilePath &fileName) const
|
unsigned revision(const Utils::FilePath &fileName) const
|
||||||
{ return _elements.value(fileName).second; }
|
{ return _elements.value(fileName).second; }
|
||||||
|
|
||||||
|
@@ -223,16 +223,16 @@ static Function *findDeclaration(const Class *cl, const QString &functionName)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline BaseTextEditor *editorAt(const QString &fileName, int line, int column)
|
static BaseTextEditor *editorAt(const FilePath &filePath, int line, int column)
|
||||||
{
|
{
|
||||||
return qobject_cast<BaseTextEditor *>(
|
return qobject_cast<BaseTextEditor *>(
|
||||||
Core::EditorManager::openEditorAt({FilePath::fromString(fileName), line, column},
|
Core::EditorManager::openEditorAt({filePath, line, column},
|
||||||
Utils::Id(),
|
Utils::Id(),
|
||||||
Core::EditorManager::DoNotMakeVisible));
|
Core::EditorManager::DoNotMakeVisible));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addDeclaration(const Snapshot &snapshot,
|
static void addDeclaration(const Snapshot &snapshot,
|
||||||
const QString &fileName,
|
const FilePath &filePath,
|
||||||
const Class *cl,
|
const Class *cl,
|
||||||
const QString &functionName)
|
const QString &functionName)
|
||||||
{
|
{
|
||||||
@@ -241,13 +241,13 @@ static void addDeclaration(const Snapshot &snapshot,
|
|||||||
CppEditor::CppRefactoringChanges refactoring(snapshot);
|
CppEditor::CppRefactoringChanges refactoring(snapshot);
|
||||||
CppEditor::InsertionPointLocator find(refactoring);
|
CppEditor::InsertionPointLocator find(refactoring);
|
||||||
const CppEditor::InsertionLocation loc = find.methodDeclarationInClass(
|
const CppEditor::InsertionLocation loc = find.methodDeclarationInClass(
|
||||||
FilePath::fromString(fileName), cl, CppEditor::InsertionPointLocator::PrivateSlot);
|
filePath, cl, CppEditor::InsertionPointLocator::PrivateSlot);
|
||||||
|
|
||||||
//
|
//
|
||||||
//! \todo change this to use the Refactoring changes.
|
//! \todo change this to use the Refactoring changes.
|
||||||
//
|
//
|
||||||
|
|
||||||
if (BaseTextEditor *editor = editorAt(fileName, loc.line(), loc.column() - 1)) {
|
if (BaseTextEditor *editor = editorAt(filePath, loc.line(), loc.column() - 1)) {
|
||||||
QTextCursor tc = editor->textCursor();
|
QTextCursor tc = editor->textCursor();
|
||||||
int pos = tc.position();
|
int pos = tc.position();
|
||||||
tc.beginEditBlock();
|
tc.beginEditBlock();
|
||||||
@@ -383,20 +383,20 @@ static inline const QStringList uiClassNames(QString formObjectName)
|
|||||||
return {formObjectName, alt};
|
return {formObjectName, alt};
|
||||||
}
|
}
|
||||||
|
|
||||||
static Document::Ptr getParsedDocument(const QString &fileName,
|
static Document::Ptr getParsedDocument(const FilePath &filePath,
|
||||||
CppEditor::WorkingCopy &workingCopy,
|
CppEditor::WorkingCopy &workingCopy,
|
||||||
Snapshot &snapshot)
|
Snapshot &snapshot)
|
||||||
{
|
{
|
||||||
QByteArray src;
|
QByteArray src;
|
||||||
if (workingCopy.contains(fileName)) {
|
if (workingCopy.contains(filePath)) {
|
||||||
src = workingCopy.source(fileName);
|
src = workingCopy.source(filePath);
|
||||||
} else {
|
} else {
|
||||||
Utils::FileReader reader;
|
Utils::FileReader reader;
|
||||||
if (reader.fetch(Utils::FilePath::fromString(fileName))) // ### FIXME error reporting
|
if (reader.fetch(filePath)) // ### FIXME error reporting
|
||||||
src = QString::fromLocal8Bit(reader.data()).toUtf8();
|
src = QString::fromLocal8Bit(reader.data()).toUtf8();
|
||||||
}
|
}
|
||||||
|
|
||||||
Document::Ptr doc = snapshot.preprocessedDocument(src, FilePath::fromString(fileName));
|
Document::Ptr doc = snapshot.preprocessedDocument(src, filePath);
|
||||||
doc->check();
|
doc->check();
|
||||||
snapshot.insert(doc);
|
snapshot.insert(doc);
|
||||||
return doc;
|
return doc;
|
||||||
@@ -503,11 +503,11 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
|
|||||||
qDebug() << Q_FUNC_INFO << "Found " << uiClass << declDoc->filePath() << " checking " << functionName << functionNameWithParameterNames;
|
qDebug() << Q_FUNC_INFO << "Found " << uiClass << declDoc->filePath() << " checking " << functionName << functionNameWithParameterNames;
|
||||||
|
|
||||||
Function *fun = findDeclaration(cl, functionName);
|
Function *fun = findDeclaration(cl, functionName);
|
||||||
QString declFilePath;
|
FilePath declFilePath;
|
||||||
if (!fun) {
|
if (!fun) {
|
||||||
// add function declaration to cl
|
// add function declaration to cl
|
||||||
CppEditor::WorkingCopy workingCopy = CppEditor::CppModelManager::instance()->workingCopy();
|
CppEditor::WorkingCopy workingCopy = CppEditor::CppModelManager::instance()->workingCopy();
|
||||||
declFilePath = declDoc->filePath().toString();
|
declFilePath = declDoc->filePath();
|
||||||
getParsedDocument(declFilePath, workingCopy, docTable);
|
getParsedDocument(declFilePath, workingCopy, docTable);
|
||||||
addDeclaration(docTable, declFilePath, cl, functionNameWithParameterNames);
|
addDeclaration(docTable, declFilePath, cl, functionNameWithParameterNames);
|
||||||
|
|
||||||
@@ -532,7 +532,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
|
|||||||
QTC_ASSERT(cl, return false);
|
QTC_ASSERT(cl, return false);
|
||||||
fun = findDeclaration(cl, functionName);
|
fun = findDeclaration(cl, functionName);
|
||||||
} else {
|
} else {
|
||||||
declFilePath = QLatin1String(fun->fileName());
|
declFilePath = FilePath::fromString(QLatin1String(fun->fileName()));
|
||||||
}
|
}
|
||||||
QTC_ASSERT(fun, return false);
|
QTC_ASSERT(fun, return false);
|
||||||
|
|
||||||
@@ -543,11 +543,12 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
|
|||||||
{FilePath::fromString(QString::fromUtf8(funImpl->fileName())), funImpl->line() + 2});
|
{FilePath::fromString(QString::fromUtf8(funImpl->fileName())), funImpl->line() + 2});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const QString implFilePath = CppEditor::correspondingHeaderOrSource(declFilePath);
|
const QString implFilePath = CppEditor::correspondingHeaderOrSource(declFilePath.toString());
|
||||||
const CppEditor::InsertionLocation location = CppEditor::insertLocationForMethodDefinition
|
const CppEditor::InsertionLocation location = CppEditor::insertLocationForMethodDefinition
|
||||||
(fun, false, CppEditor::NamespaceHandling::CreateMissing, refactoring, implFilePath);
|
(fun, false, CppEditor::NamespaceHandling::CreateMissing, refactoring, implFilePath);
|
||||||
|
|
||||||
if (BaseTextEditor *editor = editorAt(location.fileName(), location.line(), location.column())) {
|
if (BaseTextEditor *editor = editorAt(FilePath::fromString(location.fileName()),
|
||||||
|
location.line(), location.column())) {
|
||||||
Overview o;
|
Overview o;
|
||||||
const QString className = o.prettyName(cl->name());
|
const QString className = o.prettyName(cl->name());
|
||||||
const QString definition = location.prefix() + "void " + className + "::"
|
const QString definition = location.prefix() + "void " + className + "::"
|
||||||
|
Reference in New Issue
Block a user