aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cppeditor
diff options
context:
space:
mode:
authorhjk <hjk@qt.io>2022-11-24 17:00:52 +0100
committerhjk <hjk@qt.io>2022-12-16 14:27:50 +0000
commite42d24fca9fd6d7504e2d9a4cae2cc180abb2a03 (patch)
tree5b0273c9367267d44d92bd9aa8343d12c84ba15e /src/plugins/cppeditor
parentedd0e97ce12b9d2e1fc1cb8bcd34466ebdfc0a89 (diff)
CppEditor: FilePathify some of the refactoring operations
... and adjust surrounding code. Change-Id: I1d36e5a0c6ba14a1d9b8fd59340f1bb2a1e45ad1 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src/plugins/cppeditor')
-rw-r--r--src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp8
-rw-r--r--src/plugins/cppeditor/cppcodegen_test.cpp16
-rw-r--r--src/plugins/cppeditor/cppeditorplugin.cpp31
-rw-r--r--src/plugins/cppeditor/cppfollowsymbolundercursor.cpp3
-rw-r--r--src/plugins/cppeditor/cppfunctiondecldeflink.cpp5
-rw-r--r--src/plugins/cppeditor/cppheadersource_test.cpp9
-rw-r--r--src/plugins/cppeditor/cppinsertvirtualmethods.cpp10
-rw-r--r--src/plugins/cppeditor/cppmodelmanager.cpp12
-rw-r--r--src/plugins/cppeditor/cppquickfixes.cpp240
-rw-r--r--src/plugins/cppeditor/cpptoolsreuse.h6
-rw-r--r--src/plugins/cppeditor/insertionpointlocator.cpp55
-rw-r--r--src/plugins/cppeditor/insertionpointlocator.h19
12 files changed, 197 insertions, 217 deletions
diff --git a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp
index 9d8940b6ed..83a6e12f05 100644
--- a/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp
+++ b/src/plugins/cppeditor/cppbuiltinmodelmanagersupport.cpp
@@ -26,6 +26,7 @@
using namespace Core;
using namespace TextEditor;
+using namespace Utils;
namespace CppEditor::Internal {
namespace {
@@ -54,7 +55,7 @@ private:
tip += evaluator.diagnosis();
setPriority(Priority_Diagnostic);
}
- const Utils::FilePath filePath = editorWidget->textDocument()->filePath();
+ const FilePath filePath = editorWidget->textDocument()->filePath();
const QStringList fallback = identifierWordsUnderCursor(tc);
if (evaluator.identifiedCppElement()) {
const QSharedPointer<CppElement> &cppElement = evaluator.cppElement();
@@ -187,11 +188,10 @@ void BuiltinModelManagerSupport::findUsages(const CursorInEditor &data) const
}
}
-void BuiltinModelManagerSupport::switchHeaderSource(const Utils::FilePath &filePath,
+void BuiltinModelManagerSupport::switchHeaderSource(const FilePath &filePath,
bool inNextSplit)
{
- const auto otherFile = Utils::FilePath::fromString(
- correspondingHeaderOrSource(filePath.toString()));
+ const FilePath otherFile = correspondingHeaderOrSource(filePath);
if (!otherFile.isEmpty())
openEditor(otherFile, inNextSplit);
}
diff --git a/src/plugins/cppeditor/cppcodegen_test.cpp b/src/plugins/cppeditor/cppcodegen_test.cpp
index 49522e8cb0..9a9e92669c 100644
--- a/src/plugins/cppeditor/cppcodegen_test.cpp
+++ b/src/plugins/cppeditor/cppcodegen_test.cpp
@@ -352,7 +352,7 @@ void CodegenTest::testDefinitionEmptyClass()
QList<InsertionLocation> locList = find.methodDefinition(decl);
QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first();
- QCOMPARE(loc.fileName(), sourceDocument->filePath().toString());
+ QCOMPARE(loc.filePath(), sourceDocument->filePath());
QCOMPARE(loc.prefix(), QLatin1String("\n\n"));
QCOMPARE(loc.suffix(), QString());
QCOMPARE(loc.line(), 3);
@@ -410,7 +410,7 @@ void CodegenTest::testDefinitionFirstMember()
QList<InsertionLocation> locList = find.methodDefinition(decl);
QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first();
- QCOMPARE(loc.fileName(), sourceDocument->filePath().toString());
+ QCOMPARE(loc.filePath(), sourceDocument->filePath());
QCOMPARE(loc.line(), 4);
QCOMPARE(loc.column(), 1);
QCOMPARE(loc.suffix(), QLatin1String("\n\n"));
@@ -469,7 +469,7 @@ void CodegenTest::testDefinitionLastMember()
QList<InsertionLocation> locList = find.methodDefinition(decl);
QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first();
- QCOMPARE(loc.fileName(), sourceDocument->filePath().toString());
+ QCOMPARE(loc.filePath(), sourceDocument->filePath());
QCOMPARE(loc.line(), 7);
QCOMPARE(loc.column(), 2);
QCOMPARE(loc.prefix(), QLatin1String("\n\n"));
@@ -535,7 +535,7 @@ void CodegenTest::testDefinitionMiddleMember()
QList<InsertionLocation> locList = find.methodDefinition(decl);
QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first();
- QCOMPARE(loc.fileName(), sourceDocument->filePath().toString());
+ QCOMPARE(loc.filePath(), sourceDocument->filePath());
QCOMPARE(loc.line(), 7);
QCOMPARE(loc.column(), 2);
QCOMPARE(loc.prefix(), QLatin1String("\n\n"));
@@ -595,7 +595,7 @@ void CodegenTest::testDefinitionMiddleMemberSurroundedByUndefined()
QList<InsertionLocation> locList = find.methodDefinition(decl);
QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first();
- QCOMPARE(loc.fileName(), sourceDocument->filePath().toString());
+ QCOMPARE(loc.filePath(), sourceDocument->filePath());
QCOMPARE(loc.line(), 4);
QCOMPARE(loc.column(), 1);
QCOMPARE(loc.prefix(), QString());
@@ -656,14 +656,14 @@ void CodegenTest::testDefinitionMemberSpecificFile()
CppRefactoringChanges changes(snapshot);
InsertionPointLocator find(changes);
QList<InsertionLocation> locList =
- find.methodDefinition(decl, true, sourceDocument->filePath().toString());
+ find.methodDefinition(decl, true, sourceDocument->filePath());
QVERIFY(locList.size() == 1);
InsertionLocation loc = locList.first();
- QCOMPARE(loc.fileName(), sourceDocument->filePath().toString());
+ QCOMPARE(loc.filePath(), sourceDocument->filePath());
QCOMPARE(loc.line(), 7);
QCOMPARE(loc.column(), 2);
QCOMPARE(loc.prefix(), QLatin1String("\n\n"));
QCOMPARE(loc.suffix(), QString());
}
-} // namespace CppEditor::Internal
+} // CppEditor::Internal
diff --git a/src/plugins/cppeditor/cppeditorplugin.cpp b/src/plugins/cppeditor/cppeditorplugin.cpp
index 643a3b3e2e..f2f19cd059 100644
--- a/src/plugins/cppeditor/cppeditorplugin.cpp
+++ b/src/plugins/cppeditor/cppeditorplugin.cpp
@@ -768,10 +768,10 @@ static int commonFilePathLength(const QString &s1, const QString &s2)
return length;
}
-static QString correspondingHeaderOrSourceInProject(const QFileInfo &fileInfo,
- const QStringList &candidateFileNames,
- const Project *project,
- CacheUsage cacheUsage)
+static FilePath correspondingHeaderOrSourceInProject(const QFileInfo &fileInfo,
+ const QStringList &candidateFileNames,
+ const Project *project,
+ CacheUsage cacheUsage)
{
QString bestFileName;
int compareValue = 0;
@@ -789,36 +789,37 @@ static QString correspondingHeaderOrSourceInProject(const QFileInfo &fileInfo,
}
if (!bestFileName.isEmpty()) {
const QFileInfo candidateFi(bestFileName);
- QTC_ASSERT(candidateFi.isFile(), return QString());
+ QTC_ASSERT(candidateFi.isFile(), return {});
if (cacheUsage == CacheUsage::ReadWrite) {
m_headerSourceMapping[fileInfo.absoluteFilePath()] = candidateFi.absoluteFilePath();
m_headerSourceMapping[candidateFi.absoluteFilePath()] = fileInfo.absoluteFilePath();
}
- return candidateFi.absoluteFilePath();
+ return FilePath::fromString(candidateFi.absoluteFilePath());
}
- return QString();
+ return {};
}
} // namespace Internal
using namespace Internal;
-QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader, CacheUsage cacheUsage)
+FilePath correspondingHeaderOrSource(const FilePath &filePath, bool *wasHeader, CacheUsage cacheUsage)
{
+ const QString fileName = filePath.toString();
const QFileInfo fi(fileName);
ProjectFile::Kind kind = ProjectFile::classify(fileName);
const bool isHeader = ProjectFile::isHeader(kind);
if (wasHeader)
*wasHeader = isHeader;
if (m_headerSourceMapping.contains(fi.absoluteFilePath()))
- return m_headerSourceMapping.value(fi.absoluteFilePath());
+ return FilePath::fromString(m_headerSourceMapping.value(fi.absoluteFilePath()));
if (debug)
qDebug() << Q_FUNC_INFO << fileName << kind;
if (kind == ProjectFile::Unsupported)
- return QString();
+ return {};
const QString baseName = fi.completeBaseName();
const QString privateHeaderSuffix = QLatin1String("_p");
@@ -858,7 +859,7 @@ QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader, Ca
if (!isHeader || !baseName.endsWith(privateHeaderSuffix))
m_headerSourceMapping[candidateFi.absoluteFilePath()] = fi.absoluteFilePath();
}
- return candidateFi.absoluteFilePath();
+ return FilePath::fromString(candidateFi.absoluteFilePath());
}
}
}
@@ -866,7 +867,7 @@ QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader, Ca
// Find files in the current project
Project *currentProject = ProjectTree::currentProject();
if (currentProject) {
- const QString path = correspondingHeaderOrSourceInProject(fi, candidateFileNames,
+ const FilePath path = correspondingHeaderOrSourceInProject(fi, candidateFileNames,
currentProject, cacheUsage);
if (!path.isEmpty())
return path;
@@ -880,14 +881,14 @@ QString correspondingHeaderOrSource(const QString &fileName, bool *wasHeader, Ca
if (project == currentProject)
continue; // We have already checked the current project.
- const QString path = correspondingHeaderOrSourceInProject(fi, candidateFileNames,
- project, cacheUsage);
+ const FilePath path = correspondingHeaderOrSourceInProject(fi, candidateFileNames,
+ project, cacheUsage);
if (!path.isEmpty())
return path;
}
}
- return QString();
+ return {};
}
} // namespace CppEditor
diff --git a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp
index 9a73448bd5..bef3b64565 100644
--- a/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp
+++ b/src/plugins/cppeditor/cppfollowsymbolundercursor.cpp
@@ -683,8 +683,7 @@ void FollowSymbolUnderCursor::findLink(
for (const LookupItem &r : resolvedSymbols) {
if (Symbol *d = r.declaration()) {
if (d->asDeclaration() || d->asFunction()) {
- const QString fileName = QString::fromUtf8(d->fileName(), d->fileNameLength());
- if (data.filePath().toString() == fileName) {
+ if (data.filePath() == d->filePath()) {
if (line == d->line() && positionInBlock >= d->column()) {
// TODO: check the end
result = r; // take the symbol under cursor.
diff --git a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
index 0b1528e382..bf339c9e04 100644
--- a/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
+++ b/src/plugins/cppeditor/cppfunctiondecldeflink.cpp
@@ -147,10 +147,7 @@ static QSharedPointer<FunctionDeclDefLink> findLinkHelper(QSharedPointer<Functio
return noResult;
// parse the target file to get the linked decl/def
- const QString targetFileName = QString::fromUtf8(
- target->fileName(), target->fileNameLength());
- CppRefactoringFileConstPtr targetFile = changes.fileNoEditor(
- Utils::FilePath::fromString(targetFileName));
+ CppRefactoringFileConstPtr targetFile = changes.fileNoEditor(target->filePath());
if (!targetFile->isValid())
return noResult;
diff --git a/src/plugins/cppeditor/cppheadersource_test.cpp b/src/plugins/cppeditor/cppheadersource_test.cpp
index 668c191314..820f8d2a70 100644
--- a/src/plugins/cppeditor/cppheadersource_test.cpp
+++ b/src/plugins/cppeditor/cppheadersource_test.cpp
@@ -14,10 +14,13 @@
#include <QDir>
#include <QtTest>
+using namespace Utils;
+
static inline QString _(const QByteArray &ba) { return QString::fromLatin1(ba, ba.size()); }
-static void createTempFile(const QString &fileName)
+static void createTempFile(const FilePath &filePath)
{
+ QString fileName = filePath.toString();
QFile file(fileName);
QDir(QFileInfo(fileName).absolutePath()).mkpath(_("."));
file.open(QFile::WriteOnly);
@@ -40,8 +43,8 @@ void HeaderSourceTest::test()
QVERIFY(temporaryDir.isValid());
const QDir path = QDir(temporaryDir.path() + QLatin1Char('/') + _(QTest::currentDataTag()));
- const QString sourcePath = path.absoluteFilePath(sourceFileName);
- const QString headerPath = path.absoluteFilePath(headerFileName);
+ const FilePath sourcePath = FilePath::fromString(path.absoluteFilePath(sourceFileName));
+ const FilePath headerPath = FilePath::fromString(path.absoluteFilePath(headerFileName));
createTempFile(sourcePath);
createTempFile(headerPath);
diff --git a/src/plugins/cppeditor/cppinsertvirtualmethods.cpp b/src/plugins/cppeditor/cppinsertvirtualmethods.cpp
index 62a25ea960..4e869a2571 100644
--- a/src/plugins/cppeditor/cppinsertvirtualmethods.cpp
+++ b/src/plugins/cppeditor/cppinsertvirtualmethods.cpp
@@ -46,6 +46,7 @@
using namespace CPlusPlus;
using namespace TextEditor;
+using namespace Utils;
namespace CppEditor {
namespace Internal {
@@ -703,8 +704,8 @@ public:
return;
bool isHeaderFile = false;
- m_cppFileName = correspondingHeaderOrSource(interface.filePath().toString(), &isHeaderFile);
- m_factory->setHasImplementationFile(isHeaderFile && !m_cppFileName.isEmpty());
+ m_cppFilePath = correspondingHeaderOrSource(interface.filePath(), &isHeaderFile);
+ m_factory->setHasImplementationFile(isHeaderFile && !m_cppFilePath.isEmpty());
m_valid = true;
}
@@ -881,8 +882,7 @@ public:
if (!clazz)
return;
- CppRefactoringFilePtr implementationFile = refactoring.file(
- Utils::FilePath::fromString(m_cppFileName));
+ CppRefactoringFilePtr implementationFile = refactoring.file(m_cppFilePath);
Utils::ChangeSet implementationChangeSet;
const int insertPos = qMax(0, implementationFile->document()->characterCount() - 1);
@@ -932,7 +932,7 @@ private:
InsertVirtualMethodsDialog *m_factory = nullptr;
const ClassSpecifierAST *m_classAST = nullptr;
bool m_valid = false;
- QString m_cppFileName;
+ FilePath m_cppFilePath;
int m_insertPosDecl = 0;
int m_insertPosOutside = 0;
unsigned m_functionCount = 0;
diff --git a/src/plugins/cppeditor/cppmodelmanager.cpp b/src/plugins/cppeditor/cppmodelmanager.cpp
index 9d524c8c86..1d66e4c43f 100644
--- a/src/plugins/cppeditor/cppmodelmanager.cpp
+++ b/src/plugins/cppeditor/cppmodelmanager.cpp
@@ -1726,17 +1726,17 @@ void CppModelManager::onAboutToLoadSession()
GC();
}
-QSet<QString> CppModelManager::dependingInternalTargets(const Utils::FilePath &file) const
+QSet<QString> CppModelManager::dependingInternalTargets(const FilePath &file) const
{
QSet<QString> result;
const Snapshot snapshot = this->snapshot();
QTC_ASSERT(snapshot.contains(file), return result);
bool wasHeader;
- const QString correspondingFile
- = correspondingHeaderOrSource(file.toString(), &wasHeader, CacheUsage::ReadOnly);
- const Utils::FilePaths dependingFiles = snapshot.filesDependingOn(
- wasHeader ? file : Utils::FilePath::fromString(correspondingFile));
- for (const Utils::FilePath &fn : std::as_const(dependingFiles)) {
+ const FilePath correspondingFile
+ = correspondingHeaderOrSource(file, &wasHeader, CacheUsage::ReadOnly);
+ const FilePaths dependingFiles = snapshot.filesDependingOn(
+ wasHeader ? file : correspondingFile);
+ for (const FilePath &fn : std::as_const(dependingFiles)) {
for (const ProjectPart::ConstPtr &part : projectPart(fn))
result.insert(part->buildSystemTarget);
}
diff --git a/src/plugins/cppeditor/cppquickfixes.cpp b/src/plugins/cppeditor/cppquickfixes.cpp
index 42a6fe679e..5f2e9c9a72 100644
--- a/src/plugins/cppeditor/cppquickfixes.cpp
+++ b/src/plugins/cppeditor/cppquickfixes.cpp
@@ -5,19 +5,17 @@
#include "baseeditordocumentprocessor.h"
#include "cppcodestylesettings.h"
-#include "cppeditorconstants.h"
#include "cppeditordocument.h"
#include "cppeditorwidget.h"
#include "cppfunctiondecldeflink.h"
#include "cppinsertvirtualmethods.h"
-#include "cpplocatorfilter.h"
#include "cpppointerdeclarationformatter.h"
#include "cppquickfixassistant.h"
#include "cppquickfixprojectsettings.h"
#include "cpprefactoringchanges.h"
#include "cpptoolsreuse.h"
-#include "cppvirtualfunctionassistprovider.h"
#include "includeutils.h"
+#include "indexitem.h"
#include "insertionpointlocator.h"
#include "symbolfinder.h"
@@ -103,9 +101,9 @@ const QList<CppQuickFixFactory *> &CppQuickFixFactory::cppQuickFixFactories()
namespace Internal {
-QString inlinePrefix(const QString &targetFile, const std::function<bool()> &extraCondition = {})
+QString inlinePrefix(const FilePath &targetFile, const std::function<bool()> &extraCondition = {})
{
- if (ProjectFile::isHeader(ProjectFile::classify(targetFile))
+ if (ProjectFile::isHeader(ProjectFile::classify(targetFile.path()))
&& (!extraCondition || extraCondition())) {
return "inline ";
}
@@ -2527,10 +2525,10 @@ class InsertDeclOperation: public CppQuickFixOperation
{
public:
InsertDeclOperation(const CppQuickFixInterface &interface,
- const QString &targetFileName, const Class *targetSymbol,
+ const FilePath &targetFilePath, const Class *targetSymbol,
InsertionPointLocator::AccessSpec xsSpec, const QString &decl, int priority)
: CppQuickFixOperation(interface, priority)
- , m_targetFileName(FilePath::fromString(targetFileName))
+ , m_targetFilePath(targetFilePath)
, m_targetSymbol(targetSymbol)
, m_xsSpec(xsSpec)
, m_decl(decl)
@@ -2546,10 +2544,10 @@ public:
InsertionPointLocator locator(refactoring);
const InsertionLocation loc = locator.methodDeclarationInClass(
- m_targetFileName, m_targetSymbol, m_xsSpec);
+ m_targetFilePath, m_targetSymbol, m_xsSpec);
QTC_ASSERT(loc.isValid(), return);
- CppRefactoringFilePtr targetFile = refactoring.file(m_targetFileName);
+ CppRefactoringFilePtr targetFile = refactoring.file(m_targetFilePath);
int targetPosition1 = targetFile->position(loc.line(), loc.column());
int targetPosition2 = qMax(0, targetFile->position(loc.line(), 1) - 1);
@@ -2564,7 +2562,7 @@ public:
static QString generateDeclaration(const Function *function);
private:
- FilePath m_targetFileName;
+ FilePath m_targetFilePath;
const Class *m_targetSymbol;
InsertionPointLocator::AccessSpec m_xsSpec;
QString m_decl;
@@ -2573,22 +2571,22 @@ private:
class DeclOperationFactory
{
public:
- DeclOperationFactory(const CppQuickFixInterface &interface, const QString &fileName,
+ DeclOperationFactory(const CppQuickFixInterface &interface, const FilePath &filePath,
const Class *matchingClass, const QString &decl)
: m_interface(interface)
- , m_fileName(fileName)
+ , m_filePath(filePath)
, m_matchingClass(matchingClass)
, m_decl(decl)
{}
QuickFixOperation *operator()(InsertionPointLocator::AccessSpec xsSpec, int priority)
{
- return new InsertDeclOperation(m_interface, m_fileName, m_matchingClass, xsSpec, m_decl, priority);
+ return new InsertDeclOperation(m_interface, m_filePath, m_matchingClass, xsSpec, m_decl, priority);
}
private:
const CppQuickFixInterface &m_interface;
- const QString &m_fileName;
+ const FilePath &m_filePath;
const Class *m_matchingClass;
const QString &m_decl;
};
@@ -2646,8 +2644,7 @@ void InsertDeclFromDef::match(const CppQuickFixInterface &interface, QuickFixOpe
return;
}
}
- QString fileName = QString::fromUtf8(matchingClass->fileName(),
- matchingClass->fileNameLength());
+ const FilePath fileName = matchingClass->filePath();
const QString decl = InsertDeclOperation::generateDeclaration(fun);
// Add several possible insertion locations for declaration
@@ -2685,23 +2682,23 @@ public:
// Make sure that either loc is valid or targetFileName is not empty.
InsertDefOperation(const CppQuickFixInterface &interface,
Declaration *decl, DeclaratorAST *declAST, const InsertionLocation &loc,
- const DefPos defpos, const QString &targetFileName = QString(),
+ const DefPos defpos, const FilePath &targetFileName = {},
bool freeFunction = false)
: CppQuickFixOperation(interface, 0)
, m_decl(decl)
, m_declAST(declAST)
, m_loc(loc)
, m_defpos(defpos)
- , m_targetFileName(targetFileName)
+ , m_targetFilePath(targetFileName)
{
if (m_defpos == DefPosImplementationFile) {
- const QString declFile = QString::fromUtf8(decl->fileName(), decl->fileNameLength());
- const QDir dir = QFileInfo(declFile).dir();
+ const FilePath declFile = decl->filePath();
+ const FilePath targetFile = m_loc.isValid() ? m_loc.filePath() : m_targetFilePath;
+ const FilePath resolved = targetFile.relativePathFrom(declFile.parentDir());
setPriority(2);
setDescription(QCoreApplication::translate("CppEditor::InsertDefOperation",
"Add Definition in %1")
- .arg(dir.relativeFilePath(m_loc.isValid() ? m_loc.fileName()
- : m_targetFileName)));
+ .arg(resolved.displayName()));
} else if (freeFunction) {
setDescription(QCoreApplication::translate("CppEditor::InsertDefOperation",
"Add Definition Here"));
@@ -2721,7 +2718,7 @@ public:
DefPos defPos,
DeclaratorAST *declAST,
Declaration *decl,
- const QString &targetFilePath,
+ const FilePath &targetFilePath,
ChangeSet *changeSet = nullptr,
QList<ChangeSet::Range> *indentRanges = nullptr)
{
@@ -2731,8 +2728,7 @@ public:
refactoring, targetFilePath);
QTC_ASSERT(loc.isValid(), return);
- CppRefactoringFilePtr targetFile = refactoring.file(
- Utils::FilePath::fromString(loc.fileName()));
+ CppRefactoringFilePtr targetFile = refactoring.file(loc.filePath());
Overview oo = CppCodeStyleSettings::currentProjectCodeStyleOverview();
oo.showFunctionSignatures = true;
oo.showReturnTypes = true;
@@ -2846,14 +2842,14 @@ public:
private:
void perform() override
{
- insertDefinition(this, m_loc, m_defpos, m_declAST, m_decl, m_targetFileName);
+ insertDefinition(this, m_loc, m_defpos, m_declAST, m_decl, m_targetFilePath);
}
Declaration *m_decl;
DeclaratorAST *m_declAST;
InsertionLocation m_loc;
const DefPos m_defpos;
- const QString m_targetFileName;
+ const FilePath m_targetFilePath;
};
} // anonymous namespace
@@ -2894,14 +2890,13 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
// location, because insertLocationForMethodDefinition() should
// be used in perform() to get consistent insert positions.
for (const InsertionLocation &location :
- locator.methodDefinition(decl, false, QString())) {
+ locator.methodDefinition(decl, false, {})) {
if (!location.isValid())
continue;
- const QString fileName = location.fileName();
- if (ProjectFile::isHeader(ProjectFile::classify(fileName))) {
- const QString source
- = correspondingHeaderOrSource(fileName);
+ const FilePath filePath = location.filePath();
+ if (ProjectFile::isHeader(ProjectFile::classify(filePath.path()))) {
+ const FilePath source = correspondingHeaderOrSource(filePath);
if (!source.isEmpty()) {
op = new InsertDefOperation(interface, decl, declAST,
InsertionLocation(),
@@ -2912,7 +2907,7 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
op = new InsertDefOperation(interface, decl, declAST,
InsertionLocation(),
DefPosImplementationFile,
- fileName);
+ filePath);
}
if (op)
@@ -2929,7 +2924,7 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
result << new InsertDefOperation(interface, decl, declAST,
InsertionLocation(),
DefPosOutsideClass,
- interface.filePath().toString());
+ interface.filePath());
}
// Insert Position: Inside Class
@@ -2938,10 +2933,10 @@ void InsertDefFromDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
const CppRefactoringFilePtr file = interface.currentFile();
file->lineAndColumn(file->endOf(simpleDecl), &line, &column);
const InsertionLocation loc
- = InsertionLocation(interface.filePath().toString(), QString(),
+ = InsertionLocation(interface.filePath(), QString(),
QString(), line, column);
result << new InsertDefOperation(interface, decl, declAST, loc,
- DefPosInsideClass, QString(),
+ DefPosInsideClass, FilePath(),
isFreeFunction);
return;
@@ -3229,20 +3224,20 @@ private:
CppRefactoringChanges refactoring(snapshot());
const bool isHeaderFile = ProjectFile::isHeader(ProjectFile::classify(filePath().toString()));
- QString cppFile; // Only set if the class is defined in a header file.
+ FilePath cppFile; // Only set if the class is defined in a header file.
if (isHeaderFile) {
InsertionPointLocator locator(refactoring);
for (const InsertionLocation &location
: locator.methodDefinition(unimplemented.first(), false, {})) {
if (!location.isValid())
continue;
- const QString fileName = location.fileName();
- if (ProjectFile::isHeader(ProjectFile::classify(fileName))) {
- const QString source = correspondingHeaderOrSource(fileName);
+ const FilePath filePath = location.filePath();
+ if (ProjectFile::isHeader(ProjectFile::classify(filePath.path()))) {
+ const FilePath source = correspondingHeaderOrSource(filePath);
if (!source.isEmpty())
cppFile = source;
} else {
- cppFile = fileName;
+ cppFile = filePath;
}
break;
}
@@ -3251,7 +3246,7 @@ private:
MemberFunctionImplSettings settings;
switch (m_mode) {
case InsertDefsFromDecls::Mode::User: {
- AddImplementationsDialog dlg(unimplemented, Utils::FilePath::fromString(cppFile));
+ AddImplementationsDialog dlg(unimplemented, cppFile);
if (dlg.exec() == QDialog::Accepted)
settings = dlg.settings();
break;
@@ -3301,19 +3296,19 @@ private:
SimpleDeclarationAST *m_decl = nullptr;
};
- QHash<QString, QPair<ChangeSet, QList<ChangeSet::Range>>> changeSets;
+ QHash<FilePath, QPair<ChangeSet, QList<ChangeSet::Range>>> changeSets;
for (const MemberFunctionImplSetting &setting : std::as_const(settings)) {
DeclFinder finder(currentFile().data(), setting.func);
finder.accept(m_classAST);
QTC_ASSERT(finder.decl(), continue);
InsertionLocation loc;
- const QString targetFilePath = setting.defPos == DefPosImplementationFile
- ? cppFile : filePath().toString();
+ const FilePath targetFilePath = setting.defPos == DefPosImplementationFile
+ ? cppFile : filePath();
QTC_ASSERT(!targetFilePath.isEmpty(), continue);
if (setting.defPos == DefPosInsideClass) {
int line, column;
currentFile()->lineAndColumn(currentFile()->endOf(finder.decl()), &line, &column);
- loc = InsertionLocation(filePath().toString(), QString(), QString(), line, column);
+ loc = InsertionLocation(filePath(), QString(), QString(), line, column);
}
auto &changeSet = changeSets[targetFilePath];
InsertDefOperation::insertDefinition(
@@ -3322,8 +3317,7 @@ private:
&changeSet.first, &changeSet.second);
}
for (auto it = changeSets.cbegin(); it != changeSets.cend(); ++it) {
- const CppRefactoringFilePtr file = refactoring.file(
- Utils::FilePath::fromString(it.key()));
+ const CppRefactoringFilePtr file = refactoring.file(it.key());
for (const ChangeSet::Range &r : it.value().second)
file->appendIndentRange(r);
file->setChangeSet(it.value().first);
@@ -3444,19 +3438,19 @@ class GetterSetterRefactoringHelper
{
public:
GetterSetterRefactoringHelper(CppQuickFixOperation *operation,
- const QString &fileName,
+ const FilePath &filePath,
Class *clazz)
: m_operation(operation)
, m_changes(m_operation->snapshot())
, m_locator(m_changes)
- , m_headerFile(m_changes.file(Utils::FilePath::fromString(fileName)))
+ , m_headerFile(m_changes.file(filePath))
, m_sourceFile([&] {
- QString cppFileName = correspondingHeaderOrSource(fileName, &m_isHeaderHeaderFile);
- if (!m_isHeaderHeaderFile || !QFile::exists(cppFileName)) {
+ FilePath cppFilePath = correspondingHeaderOrSource(filePath, &m_isHeaderHeaderFile);
+ if (!m_isHeaderHeaderFile || !cppFilePath.exists()) {
// there is no "source" file
return m_headerFile;
} else {
- return m_changes.file(Utils::FilePath::fromString(cppFileName));
+ return m_changes.file(cppFilePath);
}
}())
, m_class(clazz)
@@ -3649,7 +3643,7 @@ protected:
? NamespaceHandling::CreateMissing
: NamespaceHandling::Ignore,
m_changes,
- m_sourceFile->filePath().toString(),
+ m_sourceFile->filePath(),
insertedNamespaces);
if (m_settings->addUsingNamespaceinCppFile()) {
// check if we have to insert a using namespace ...
@@ -3675,7 +3669,7 @@ protected:
ns.resize(ns.size() - 2); // remove last '::'
ns += ";\n";
const auto &loc = m_sourceFileInsertionPoint;
- m_sourceFileInsertionPoint = InsertionLocation(loc.fileName(),
+ m_sourceFileInsertionPoint = InsertionLocation(loc.filePath(),
loc.prefix() + ns,
loc.suffix(),
loc.line(),
@@ -3787,9 +3781,7 @@ public:
void perform() override
{
- GetterSetterRefactoringHelper helper(this,
- currentFile()->filePath().toString(),
- m_data.clazz);
+ GetterSetterRefactoringHelper helper(this, currentFile()->filePath(), m_data.clazz);
helper.performGeneration(m_data, m_generateFlags);
helper.applyChanges();
}
@@ -3976,7 +3968,7 @@ void GetterSetterRefactoringHelper::performGeneration(ExistingGetterSetterData d
false,
NamespaceHandling::Ignore,
m_changes,
- m_headerFile->filePath().toString());
+ m_headerFile->filePath());
const FullySpecifiedType returnType = getReturnTypeAt(m_headerFile, loc);
const QString clazz = symbolAt(data.clazz, m_headerFile, loc);
QString code = overview.prettyType(returnType, clazz + "::" + data.getterName)
@@ -4067,7 +4059,7 @@ void GetterSetterRefactoringHelper::performGeneration(ExistingGetterSetterData d
false,
NamespaceHandling::Ignore,
m_changes,
- m_headerFile->filePath().toString());
+ m_headerFile->filePath());
FullySpecifiedType newParameterType = typeAt(data.declarationSymbol->type(),
data.clazz,
@@ -4141,7 +4133,7 @@ void GetterSetterRefactoringHelper::performGeneration(ExistingGetterSetterData d
false,
NamespaceHandling::Ignore,
m_changes,
- m_headerFile->filePath().toString());
+ m_headerFile->filePath());
const FullySpecifiedType type = typeAt(data.declarationSymbol->type(),
data.clazz,
m_headerFile,
@@ -4722,7 +4714,7 @@ private:
if (m_candidates.empty())
return;
GetterSetterRefactoringHelper helper(this,
- currentFile()->filePath().toString(),
+ currentFile()->filePath(),
m_candidates.front().data.clazz);
for (MemberInfo &mi : m_candidates) {
if (mi.requestedFlags != 0) {
@@ -4907,7 +4899,7 @@ public:
}
funcDef.append(QLatin1String("\n}\n\n"));
funcDef.replace(QChar::ParagraphSeparator, QLatin1String("\n"));
- funcDef.prepend(inlinePrefix(currentFile->filePath().toString()));
+ funcDef.prepend(inlinePrefix(currentFile->filePath()));
funcCall.append(QLatin1Char(';'));
// Get starting indentation from original code.
@@ -5447,7 +5439,6 @@ public:
{
FoundDeclaration result;
Function *func = ast->symbol;
- QString declFileName;
if (Class *matchingClass = isMemberFunction(context(), func)) {
// Dealing with member functions
const QualifiedNameId *qName = func->name()->asQualifiedNameId();
@@ -5460,10 +5451,8 @@ public:
continue;
}
- declFileName = QString::fromUtf8(matchingClass->fileName(),
- matchingClass->fileNameLength());
-
- result.file = refactoring.file(Utils::FilePath::fromString(declFileName));
+ const FilePath declFilePath = matchingClass->filePath();
+ result.file = refactoring.file(declFilePath);
ASTPath astPath(result.file->cppDocument());
const QList<AST *> path = astPath(s->line(), s->column());
SimpleDeclarationAST *simpleDecl = nullptr;
@@ -5483,10 +5472,10 @@ public:
} else if (Namespace *matchingNamespace = isNamespaceFunction(context(), func)) {
// Dealing with free functions and inline member functions.
bool isHeaderFile;
- declFileName = correspondingHeaderOrSource(filePath().toString(), &isHeaderFile);
- if (!QFile::exists(declFileName))
+ FilePath declFilePath = correspondingHeaderOrSource(filePath(), &isHeaderFile);
+ if (!declFilePath.exists())
return FoundDeclaration();
- result.file = refactoring.file(Utils::FilePath::fromString(declFileName));
+ result.file = refactoring.file(declFilePath);
if (!result.file)
return FoundDeclaration();
const LookupContext lc(result.file->cppDocument(), snapshot());
@@ -6295,12 +6284,11 @@ public:
};
MoveFuncDefRefactoringHelper(CppQuickFixOperation *operation, MoveType type,
- const QString &fromFile, const QString &toFile)
+ const FilePath &fromFile, const FilePath &toFile)
: m_operation(operation), m_type(type), m_changes(m_operation->snapshot())
{
- m_fromFile = m_changes.file(Utils::FilePath::fromString(fromFile));
- m_toFile = (m_type == MoveOutside) ? m_fromFile
- : m_changes.file(Utils::FilePath::fromString(toFile));
+ m_fromFile = m_changes.file(fromFile);
+ m_toFile = (m_type == MoveOutside) ? m_fromFile : m_changes.file(toFile);
}
void performMove(FunctionDefinitionAST *funcAST)
@@ -6308,15 +6296,14 @@ public:
// Determine file, insert position and scope
InsertionLocation l = insertLocationForMethodDefinition(
funcAST->symbol, false, NamespaceHandling::Ignore,
- m_changes, m_toFile->filePath().toString());
+ m_changes, m_toFile->filePath());
const QString prefix = l.prefix();
const QString suffix = l.suffix();
const int insertPos = m_toFile->position(l.line(), l.column());
Scope *scopeAtInsertPos = m_toFile->cppDocument()->scopeAt(l.line(), l.column());
// construct definition
- const QString funcDec = inlinePrefix(
- m_toFile->filePath().toString(), [this] { return m_type == MoveOutside; })
+ const QString funcDec = inlinePrefix(m_toFile->filePath(), [this] { return m_type == MoveOutside; })
+ definitionSignature(m_operation, funcAST, m_fromFile, m_toFile,
scopeAtInsertPos);
QString funcDef = prefix + funcDec;
@@ -6372,28 +6359,27 @@ class MoveFuncDefOutsideOp : public CppQuickFixOperation
public:
MoveFuncDefOutsideOp(const CppQuickFixInterface &interface,
MoveFuncDefRefactoringHelper::MoveType type,
- FunctionDefinitionAST *funcDef, const QString &cppFileName)
+ FunctionDefinitionAST *funcDef, const FilePath &cppFilePath)
: CppQuickFixOperation(interface, 0)
, m_funcDef(funcDef)
, m_type(type)
- , m_cppFileName(cppFileName)
- , m_headerFileName(QString::fromUtf8(funcDef->symbol->fileName(),
- funcDef->symbol->fileNameLength()))
+ , m_cppFilePath(cppFilePath)
+ , m_headerFilePath(funcDef->symbol->filePath())
{
if (m_type == MoveFuncDefRefactoringHelper::MoveOutside) {
setDescription(QCoreApplication::translate("CppEditor::QuickFix",
"Move Definition Outside Class"));
} else {
- const QDir dir = QFileInfo(m_headerFileName).dir();
+ const FilePath resolved = m_cppFilePath.relativePathFrom(m_headerFilePath.parentDir());
setDescription(QCoreApplication::translate("CppEditor::QuickFix",
"Move Definition to %1")
- .arg(dir.relativeFilePath(m_cppFileName)));
+ .arg(resolved.displayName()));
}
}
void perform() override
{
- MoveFuncDefRefactoringHelper helper(this, m_type, m_headerFileName, m_cppFileName);
+ MoveFuncDefRefactoringHelper helper(this, m_type, m_headerFilePath, m_cppFilePath);
helper.performMove(m_funcDef);
helper.applyChanges();
}
@@ -6401,8 +6387,8 @@ public:
private:
FunctionDefinitionAST *m_funcDef;
MoveFuncDefRefactoringHelper::MoveType m_type;
- const QString m_cppFileName;
- const QString m_headerFileName;
+ const FilePath m_cppFilePath;
+ const FilePath m_headerFilePath;
};
} // anonymous namespace
@@ -6446,8 +6432,7 @@ void MoveFuncDefOutside::match(const CppQuickFixInterface &interface, QuickFixOp
return;
bool isHeaderFile = false;
- const QString cppFileName = correspondingHeaderOrSource(interface.filePath().toString(),
- &isHeaderFile);
+ const FilePath cppFileName = correspondingHeaderOrSource(interface.filePath(), &isHeaderFile);
if (isHeaderFile && !cppFileName.isEmpty()) {
const MoveFuncDefRefactoringHelper::MoveType type = moveOutsideMemberDefinition
@@ -6458,7 +6443,7 @@ void MoveFuncDefOutside::match(const CppQuickFixInterface &interface, QuickFixOp
if (classAST)
result << new MoveFuncDefOutsideOp(interface, MoveFuncDefRefactoringHelper::MoveOutside,
- funcAST, QLatin1String(""));
+ funcAST, FilePath());
return;
}
@@ -6470,28 +6455,27 @@ class MoveAllFuncDefOutsideOp : public CppQuickFixOperation
public:
MoveAllFuncDefOutsideOp(const CppQuickFixInterface &interface,
MoveFuncDefRefactoringHelper::MoveType type,
- ClassSpecifierAST *classDef, const QString &cppFileName)
+ ClassSpecifierAST *classDef, const FilePath &cppFileName)
: CppQuickFixOperation(interface, 0)
, m_type(type)
, m_classDef(classDef)
- , m_cppFileName(cppFileName)
- , m_headerFileName(QString::fromUtf8(classDef->symbol->fileName(),
- classDef->symbol->fileNameLength()))
+ , m_cppFilePath(cppFileName)
+ , m_headerFilePath(classDef->symbol->filePath())
{
if (m_type == MoveFuncDefRefactoringHelper::MoveOutside) {
setDescription(QCoreApplication::translate("CppEditor::QuickFix", "Move All Function "
"Definitions Outside Class"));
} else {
- const QDir dir = QFileInfo(m_headerFileName).dir();
+ const FilePath resolved = m_cppFilePath.relativePathFrom(m_headerFilePath.parentDir());
setDescription(QCoreApplication::translate("CppEditor::QuickFix",
"Move All Function Definitions to %1")
- .arg(dir.relativeFilePath(m_cppFileName)));
+ .arg(resolved.displayName()));
}
}
void perform() override
{
- MoveFuncDefRefactoringHelper helper(this, m_type, m_headerFileName, m_cppFileName);
+ MoveFuncDefRefactoringHelper helper(this, m_type, m_headerFilePath, m_cppFilePath);
for (DeclarationListAST *it = m_classDef->member_specifier_list; it; it = it->next) {
if (FunctionDefinitionAST *funcAST = it->value->asFunctionDefinition()) {
if (funcAST->symbol && !funcAST->symbol->isGenerated())
@@ -6504,8 +6488,8 @@ public:
private:
MoveFuncDefRefactoringHelper::MoveType m_type;
ClassSpecifierAST *m_classDef;
- const QString m_cppFileName;
- const QString m_headerFileName;
+ const FilePath m_cppFilePath;
+ const FilePath m_headerFilePath;
};
} // anonymous namespace
@@ -6530,15 +6514,14 @@ void MoveAllFuncDefOutside::match(const CppQuickFixInterface &interface, QuickFi
return;
bool isHeaderFile = false;
- const QString cppFileName = correspondingHeaderOrSource(interface.filePath().toString(),
- &isHeaderFile);
+ const FilePath cppFileName = correspondingHeaderOrSource(interface.filePath(), &isHeaderFile);
if (isHeaderFile && !cppFileName.isEmpty()) {
result << new MoveAllFuncDefOutsideOp(interface,
MoveFuncDefRefactoringHelper::MoveToCppFile,
classAST, cppFileName);
}
result << new MoveAllFuncDefOutsideOp(interface, MoveFuncDefRefactoringHelper::MoveOutside,
- classAST, QLatin1String(""));
+ classAST, FilePath());
}
namespace {
@@ -6547,34 +6530,34 @@ class MoveFuncDefToDeclOp : public CppQuickFixOperation
{
public:
MoveFuncDefToDeclOp(const CppQuickFixInterface &interface,
- const QString &fromFileName, const QString &toFileName,
+ const FilePath &fromFilePath, const FilePath &toFilePath,
FunctionDefinitionAST *funcDef, const QString &declText,
const ChangeSet::Range &fromRange,
const ChangeSet::Range &toRange)
: CppQuickFixOperation(interface, 0)
- , m_fromFileName(fromFileName)
- , m_toFileName(toFileName)
+ , m_fromFilePath(fromFilePath)
+ , m_toFilePath(toFilePath)
, m_funcAST(funcDef)
, m_declarationText(declText)
, m_fromRange(fromRange)
, m_toRange(toRange)
{
- if (m_toFileName == m_fromFileName) {
+ if (m_toFilePath == m_fromFilePath) {
setDescription(QCoreApplication::translate("CppEditor::QuickFix",
"Move Definition to Class"));
} else {
- const QDir dir = QFileInfo(m_fromFileName).dir();
+ const FilePath resolved = m_toFilePath.relativePathFrom(m_fromFilePath.parentDir());
setDescription(QCoreApplication::translate("CppEditor::QuickFix",
"Move Definition to %1")
- .arg(dir.relativeFilePath(m_toFileName)));
+ .arg(resolved.displayName()));
}
}
void perform() override
{
CppRefactoringChanges refactoring(snapshot());
- CppRefactoringFilePtr fromFile = refactoring.file(Utils::FilePath::fromString(m_fromFileName));
- CppRefactoringFilePtr toFile = refactoring.file(Utils::FilePath::fromString(m_toFileName));
+ CppRefactoringFilePtr fromFile = refactoring.file(m_fromFilePath);
+ CppRefactoringFilePtr toFile = refactoring.file(m_toFilePath);
const QString wholeFunctionText = m_declarationText
+ fromFile->textOf(fromFile->endOf(m_funcAST->declarator),
@@ -6583,13 +6566,13 @@ public:
// Replace declaration with function and delete old definition
ChangeSet toTarget;
toTarget.replace(m_toRange, wholeFunctionText);
- if (m_toFileName == m_fromFileName)
+ if (m_toFilePath == m_fromFilePath)
toTarget.remove(m_fromRange);
toFile->setChangeSet(toTarget);
toFile->appendIndentRange(m_toRange);
toFile->setOpenEditor(true, m_toRange.start);
toFile->apply();
- if (m_toFileName != m_fromFileName) {
+ if (m_toFilePath != m_fromFilePath) {
ChangeSet fromTarget;
fromTarget.remove(m_fromRange);
fromFile->setChangeSet(fromTarget);
@@ -6598,8 +6581,8 @@ public:
}
private:
- const QString m_fromFileName;
- const QString m_toFileName;
+ const FilePath m_fromFilePath;
+ const FilePath m_toFilePath;
FunctionDefinitionAST *m_funcAST;
const QString m_declarationText;
const ChangeSet::Range m_fromRange;
@@ -6640,9 +6623,9 @@ void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
const ChangeSet::Range defRange = defFile->range(completeDefAST);
// Determine declaration (file, range, text);
- QString declFileName;
ChangeSet::Range declRange;
QString declText;
+ FilePath declFilePath;
Function *func = funcAST->symbol;
if (Class *matchingClass = isMemberFunction(interface.context(), func)) {
@@ -6667,10 +6650,8 @@ void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
continue;
}
- declFileName = QString::fromUtf8(matchingClass->fileName(),
- matchingClass->fileNameLength());
-
- const CppRefactoringFilePtr declFile = refactoring.file(Utils::FilePath::fromString(declFileName));
+ declFilePath = matchingClass->filePath();
+ const CppRefactoringFilePtr declFile = refactoring.file(declFilePath);
ASTPath astPath(declFile->cppDocument());
const QList<AST *> path = astPath(s->line(), s->column());
for (int idx = path.size() - 1; idx > 0; --idx) {
@@ -6691,12 +6672,11 @@ void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
} else if (Namespace *matchingNamespace = isNamespaceFunction(interface.context(), func)) {
// Dealing with free functions
bool isHeaderFile = false;
- declFileName = correspondingHeaderOrSource(interface.filePath().toString(), &isHeaderFile);
+ declFilePath = correspondingHeaderOrSource(interface.filePath(), &isHeaderFile);
if (isHeaderFile)
return;
- const CppRefactoringFilePtr declFile = refactoring.file(
- Utils::FilePath::fromString(declFileName));
+ const CppRefactoringFilePtr declFile = refactoring.file(declFilePath);
const LookupContext lc(declFile->cppDocument(), interface.snapshot());
const QList<LookupItem> candidates = lc.lookup(func->name(), matchingNamespace);
for (const LookupItem &candidate : candidates) {
@@ -6716,16 +6696,16 @@ void MoveFuncDefToDecl::match(const CppQuickFixInterface &interface, QuickFixOpe
}
if (!declText.isEmpty()) {
- declText.prepend(inlinePrefix(declFileName));
+ declText.prepend(inlinePrefix(declFilePath));
break;
}
}
}
- if (!declFileName.isEmpty() && !declText.isEmpty())
+ if (!declFilePath.isEmpty() && !declText.isEmpty())
result << new MoveFuncDefToDeclOp(interface,
- interface.filePath().toString(),
- declFileName,
+ interface.filePath(),
+ declFilePath,
funcAST, declText,
defRange, declRange);
}
@@ -8941,11 +8921,11 @@ private:
const ClassSpecifierAST *m_classAST;
InsertionPointLocator::AccessSpec m_accessSpec;
GenerateConstructorRefactoringHelper(CppQuickFixOperation *operation,
- const QString &fileName,
+ const FilePath &filePath,
Class *clazz,
const ClassSpecifierAST *classAST,
InsertionPointLocator::AccessSpec accessSpec)
- : GetterSetterRefactoringHelper(operation, fileName, clazz)
+ : GetterSetterRefactoringHelper(operation, filePath, clazz)
, m_classAST(classAST)
, m_accessSpec(accessSpec)
{}
@@ -8979,7 +8959,7 @@ private:
false,
NamespaceHandling::Ignore,
m_changes,
- m_headerFile->filePath().toString(),
+ m_headerFile->filePath(),
&insertedNamespaces);
implFile = m_headerFile;
implCode = symbolAt(m_class, m_headerFile, implLoc);
@@ -9086,7 +9066,7 @@ private:
}
};
GenerateConstructorRefactoringHelper helper(this,
- currentFile()->filePath().toString(),
+ currentFile()->filePath(),
m_classAST->symbol,
m_classAST,
accessSpec);
diff --git a/src/plugins/cppeditor/cpptoolsreuse.h b/src/plugins/cppeditor/cpptoolsreuse.h
index 06eba69c69..1b1b1d1f0a 100644
--- a/src/plugins/cppeditor/cpptoolsreuse.h
+++ b/src/plugins/cppeditor/cpptoolsreuse.h
@@ -58,8 +58,10 @@ CppCompletionAssistProcessor CPPEDITOR_EXPORT *getCppCompletionAssistProcessor()
enum class CacheUsage { ReadWrite, ReadOnly };
-QString CPPEDITOR_EXPORT correspondingHeaderOrSource(const QString &fileName, bool *wasHeader = nullptr,
- CacheUsage cacheUsage = CacheUsage::ReadWrite);
+Utils::FilePath CPPEDITOR_EXPORT correspondingHeaderOrSource(
+ const Utils::FilePath &filePath, bool *wasHeader = nullptr,
+ CacheUsage cacheUsage = CacheUsage::ReadWrite);
+
void CPPEDITOR_EXPORT openEditor(const Utils::FilePath &filePath, bool inNextSplit,
Utils::Id editorId = {});
class CppCodeModelSettings;
diff --git a/src/plugins/cppeditor/insertionpointlocator.cpp b/src/plugins/cppeditor/insertionpointlocator.cpp
index 119e39cfb3..72568da9ba 100644
--- a/src/plugins/cppeditor/insertionpointlocator.cpp
+++ b/src/plugins/cppeditor/insertionpointlocator.cpp
@@ -3,7 +3,6 @@
#include "insertionpointlocator.h"
-#include "cppeditorconstants.h"
#include "cppprojectfile.h"
#include "cpptoolsreuse.h"
#include "symbolfinder.h"
@@ -16,6 +15,7 @@
#include <utils/qtcassert.h>
using namespace CPlusPlus;
+using namespace Utils;
namespace CppEditor {
namespace {
@@ -207,11 +207,11 @@ QList<AccessRange> collectAccessRanges(const CPlusPlus::TranslationUnit *tu,
InsertionLocation::InsertionLocation() = default;
-InsertionLocation::InsertionLocation(const QString &fileName,
+InsertionLocation::InsertionLocation(const FilePath &filePath,
const QString &prefix,
const QString &suffix,
int line, int column)
- : m_fileName(fileName)
+ : m_filePath(filePath)
, m_prefix(prefix)
, m_suffix(suffix)
, m_line(line)
@@ -306,7 +306,7 @@ InsertionLocation InsertionPointLocator::methodDeclarationInClass(const Translat
if (needsSuffix)
suffix = QLatin1Char('\n');
const QString fileName = QString::fromUtf8(tu->fileName(), tu->fileNameLength());
- return InsertionLocation(fileName, prefix, suffix, line, column);
+ return InsertionLocation(FilePath::fromString(fileName), prefix, suffix, line, column);
}
InsertionPointLocator::AccessSpec symbolsAccessSpec(Symbol *symbol)
@@ -360,16 +360,17 @@ InsertionLocation InsertionPointLocator::constructorDeclarationInClass(
// we have a constructor with x arguments but there are only ones with < x arguments
--iter; // select greatest one (in terms of argument count)
}
- const QString fileName = QString::fromUtf8(tu->fileName(), tu->fileNameLength());
+ const FilePath filePath =
+ FilePath::fromString(QString::fromUtf8(tu->fileName(), tu->fileNameLength()));
int line, column;
if (iter->first <= constructorArgumentCount) {
tu->getTokenEndPosition(iter->second.second->lastToken() - 1, &line, &column);
- return InsertionLocation(fileName, "\n", "", line, column);
+ return InsertionLocation(filePath, "\n", "", line, column);
}
// before iter
// end pos of firstToken-1 instead of start pos of firstToken to skip leading commend
tu->getTokenEndPosition(iter->second.first->firstToken() - 1, &line, &column);
- return InsertionLocation(fileName, "\n", "", line, column);
+ return InsertionLocation(filePath, "\n", "", line, column);
}
namespace {
@@ -529,7 +530,7 @@ static Declaration *isNonVirtualFunctionDeclaration(Symbol *s)
static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration,
const CppRefactoringChanges &changes,
- const QString& destinationFile)
+ const FilePath &destinationFile)
{
InsertionLocation noResult;
Class *klass = declaration->enclosingClass();
@@ -560,8 +561,7 @@ static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration,
if ((definitionFunction = symbolFinder.findMatchingDefinition(surroundingFunctionDecl,
changes.snapshot())))
{
- if (destinationFile.isEmpty() || destinationFile == QString::fromUtf8(
- definitionFunction->fileName(), definitionFunction->fileNameLength())) {
+ if (destinationFile.isEmpty() || destinationFile == definitionFunction->filePath()) {
prefix = QLatin1String("\n\n");
break;
}
@@ -578,8 +578,7 @@ static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration,
if ((definitionFunction = symbolFinder.findMatchingDefinition(surroundingFunctionDecl,
changes.snapshot())))
{
- if (destinationFile.isEmpty() || destinationFile == QString::fromUtf8(
- definitionFunction->fileName(), definitionFunction->fileNameLength())) {
+ if (destinationFile.isEmpty() || destinationFile == definitionFunction->filePath()) {
suffix = QLatin1String("\n\n");
break;
}
@@ -622,11 +621,11 @@ static InsertionLocation nextToSurroundingDefinitions(Symbol *declaration,
}
}
- return InsertionLocation(QString::fromUtf8(definitionFunction->fileName()), prefix, suffix, line, column);
+ return InsertionLocation(definitionFunction->filePath(), prefix, suffix, line, column);
}
const QList<InsertionLocation> InsertionPointLocator::methodDefinition(
- Symbol *declaration, bool useSymbolFinder, const QString &destinationFile) const
+ Symbol *declaration, bool useSymbolFinder, const FilePath &destinationFile) const
{
QList<InsertionLocation> result;
if (!declaration)
@@ -646,17 +645,15 @@ const QList<InsertionLocation> InsertionPointLocator::methodDefinition(
return result;
}
- const QString declFileName = QString::fromUtf8(declaration->fileName(),
- declaration->fileNameLength());
- QString target = declFileName;
- if (!ProjectFile::isSource(ProjectFile::classify(declFileName))) {
- QString candidate = correspondingHeaderOrSource(declFileName);
+ const FilePath declFilePath = declaration->filePath();
+ FilePath target = declFilePath;
+ if (!ProjectFile::isSource(ProjectFile::classify(declFilePath.path()))) {
+ FilePath candidate = correspondingHeaderOrSource(declFilePath);
if (!candidate.isEmpty())
target = candidate;
}
- CppRefactoringFilePtr targetFile = m_refactoringChanges.file(
- Utils::FilePath::fromString(target));
+ CppRefactoringFilePtr targetFile = m_refactoringChanges.file(target);
Document::Ptr doc = targetFile->cppDocument();
if (doc.isNull())
return result;
@@ -759,12 +756,12 @@ InsertionLocation insertLocationForMethodDefinition(Symbol *symbol,
const bool useSymbolFinder,
NamespaceHandling namespaceHandling,
const CppRefactoringChanges &refactoring,
- const QString &fileName,
+ const FilePath &filePath,
QStringList *insertedNamespaces)
{
QTC_ASSERT(symbol, return InsertionLocation());
- CppRefactoringFilePtr file = refactoring.file(Utils::FilePath::fromString(fileName));
+ CppRefactoringFilePtr file = refactoring.file(filePath);
QStringList requiredNamespaces;
if (namespaceHandling == NamespaceHandling::CreateMissing) {
requiredNamespaces = getNamespaceNames(symbol);
@@ -775,8 +772,8 @@ InsertionLocation insertLocationForMethodDefinition(Symbol *symbol,
// (or provide enough context).
const InsertionPointLocator locator(refactoring);
const QList<InsertionLocation> list
- = locator.methodDefinition(symbol, useSymbolFinder, fileName);
- const bool isHeader = ProjectFile::isHeader(ProjectFile::classify(fileName));
+ = locator.methodDefinition(symbol, useSymbolFinder, filePath);
+ const bool isHeader = ProjectFile::isHeader(ProjectFile::classify(filePath.path()));
const bool hasIncludeGuard = isHeader
&& !file->cppDocument()->includeGuardMacroName().isEmpty();
int lastLine;
@@ -787,7 +784,7 @@ InsertionLocation insertLocationForMethodDefinition(Symbol *symbol,
int i = 0;
for ( ; i < list.count(); ++i) {
InsertionLocation location = list.at(i);
- if (!location.isValid() || location.fileName() != fileName)
+ if (!location.isValid() || location.filePath() != filePath)
continue;
if (hasIncludeGuard && location.line() == lastLine)
continue;
@@ -805,11 +802,11 @@ InsertionLocation insertLocationForMethodDefinition(Symbol *symbol,
// if class member try to get position right after class
int line = 0, column = 0;
if (Class *clazz = symbol->enclosingClass()) {
- if (symbol->fileName() == fileName.toUtf8()) {
+ if (symbol->filePath() == filePath) {
file->cppDocument()->translationUnit()->getPosition(clazz->endOffset(), &line, &column);
if (line != 0) {
++column; // Skipping the ";"
- return InsertionLocation(fileName, QLatin1String("\n\n"), QLatin1String(""),
+ return InsertionLocation(filePath, QLatin1String("\n\n"), QLatin1String(""),
line, column);
}
}
@@ -834,7 +831,7 @@ InsertionLocation insertLocationForMethodDefinition(Symbol *symbol,
//TODO watch for moc-includes
file->lineAndColumn(pos, &line, &column);
- return InsertionLocation(fileName, prefix, suffix, line, column);
+ return InsertionLocation(filePath, prefix, suffix, line, column);
}
} // namespace CppEditor;
diff --git a/src/plugins/cppeditor/insertionpointlocator.h b/src/plugins/cppeditor/insertionpointlocator.h
index 8dc5f561a7..1eff9463e9 100644
--- a/src/plugins/cppeditor/insertionpointlocator.h
+++ b/src/plugins/cppeditor/insertionpointlocator.h
@@ -6,6 +6,8 @@
#include "cppeditor_global.h"
#include "cpprefactoringchanges.h"
+#include <utils/filepath.h>
+
namespace CPlusPlus {
class Namespace;
class NamespaceAST;
@@ -18,11 +20,11 @@ class CPPEDITOR_EXPORT InsertionLocation
{
public:
InsertionLocation();
- InsertionLocation(const QString &fileName, const QString &prefix,
+ InsertionLocation(const Utils::FilePath &filePath, const QString &prefix,
const QString &suffix, int line, int column);
- QString fileName() const
- { return m_fileName; }
+ const Utils::FilePath &filePath() const
+ { return m_filePath; }
/// \returns The prefix to insert before any other text.
QString prefix() const
@@ -41,10 +43,10 @@ public:
{ return m_column; }
bool isValid() const
- { return !m_fileName.isEmpty() && m_line > 0 && m_column > 0; }
+ { return !m_filePath.isEmpty() && m_line > 0 && m_column > 0; }
private:
- QString m_fileName;
+ Utils::FilePath m_filePath;
QString m_prefix;
QString m_suffix;
int m_line = 0;
@@ -99,10 +101,9 @@ public:
AccessSpec xsSpec,
int constructorArgumentCount) const;
- const QList<InsertionLocation> methodDefinition(
- CPlusPlus::Symbol *declaration,
+ const QList<InsertionLocation> methodDefinition(CPlusPlus::Symbol *declaration,
bool useSymbolFinder = true,
- const QString &destinationFile = QString()) const;
+ const Utils::FilePath &destinationFile = {}) const;
private:
CppRefactoringChanges m_refactoringChanges;
@@ -115,7 +116,7 @@ insertLocationForMethodDefinition(CPlusPlus::Symbol *symbol,
const bool useSymbolFinder,
NamespaceHandling namespaceHandling,
const CppRefactoringChanges &refactoring,
- const QString &fileName,
+ const Utils::FilePath &fileName,
QStringList *insertedNamespaces = nullptr);
} // namespace CppEditor