forked from qt-creator/qt-creator
ClangTools: Replace FilePath::toString
Replace occurrences of FilePath::toString with more sensible alternatives. Use FilePath capabilities instead of QDir/QFile's where applicable. Use FilePath instead of QString where it makes sense. Change-Id: Idc352dbff846c2678f1e3295ac34b3285a711574 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -61,7 +61,7 @@ static Tree *createDirNode(const QString &name, const FilePath &filePath = FileP
|
||||
static Tree *createFileNode(const FileInfo &fileInfo, bool displayFullPath = false)
|
||||
{
|
||||
auto node = new TreeWithFileInfo;
|
||||
node->name = displayFullPath ? fileInfo.file.toString() : fileInfo.file.fileName();
|
||||
node->name = displayFullPath ? fileInfo.file.toUserOutput() : fileInfo.file.fileName();
|
||||
node->fullPath = fileInfo.file;
|
||||
node->info = fileInfo;
|
||||
|
||||
|
@@ -1250,7 +1250,7 @@ void ClangTool::setState(State state)
|
||||
QSet<Diagnostic> ClangTool::diagnostics() const
|
||||
{
|
||||
return Utils::filtered(m_diagnosticModel->diagnostics(), [](const Diagnostic &diagnostic) {
|
||||
return ProjectFile::isSource(ProjectFile::classify(diagnostic.location.filePath.toString()));
|
||||
return ProjectFile::isSource(ProjectFile::classify(diagnostic.location.filePath));
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -653,7 +653,7 @@ bool DiagnosticFilterModel::filterAcceptsRow(int sourceRow, const QModelIndex &s
|
||||
continue;
|
||||
Utils::FilePath filePath = d.filePath;
|
||||
if (d.filePath.toFileInfo().isRelative())
|
||||
filePath = m_lastProjectDirectory.pathAppended(filePath.toString());
|
||||
filePath = m_lastProjectDirectory.resolvePath(filePath);
|
||||
if (filePath == diag.location.filePath) {
|
||||
diagnosticItem->setTextMarkVisible(false);
|
||||
return false;
|
||||
|
@@ -129,7 +129,7 @@ public:
|
||||
|
||||
Debugger::DiagnosticLocation toDiagnosticLocation() const
|
||||
{
|
||||
FileCache::Item &cacheItem = m_fileCache.item(m_filePath.toString());
|
||||
FileCache::Item &cacheItem = m_fileCache.item(m_filePath.toUserOutput());
|
||||
const QByteArray fileContents = cacheItem.fileContents();
|
||||
|
||||
const char *data = fileContents.data();
|
||||
|
@@ -139,31 +139,27 @@ void ClangToolsProjectSettings::load()
|
||||
// Read map
|
||||
m_useGlobalSettings = map.value(SETTINGS_KEY_USE_GLOBAL_SETTINGS).toBool();
|
||||
|
||||
auto toFileName = [](const QString &s) { return Utils::FilePath::fromString(s); };
|
||||
const QStringList dirs = map.value(SETTINGS_KEY_SELECTED_DIRS).toStringList();
|
||||
m_selectedDirs = Utils::transform<QSet>(dirs, toFileName);
|
||||
const QVariantList dirs = map.value(SETTINGS_KEY_SELECTED_DIRS).toList();
|
||||
m_selectedDirs = Utils::transform<QSet>(dirs, Utils::FilePath::fromSettings);
|
||||
|
||||
const QStringList files = map.value(SETTINGS_KEY_SELECTED_FILES).toStringList();
|
||||
m_selectedFiles = Utils::transform<QSet>(files, toFileName);
|
||||
const QVariantList files = map.value(SETTINGS_KEY_SELECTED_FILES).toList();
|
||||
m_selectedFiles = Utils::transform<QSet>(files, Utils::FilePath::fromSettings);
|
||||
|
||||
const QVariantList list = map.value(SETTINGS_KEY_SUPPRESSED_DIAGS).toList();
|
||||
for (const QVariant &v : list) {
|
||||
const Store diag = storeFromVariant(v);
|
||||
const QString fp = diag.value(SETTINGS_KEY_SUPPRESSED_DIAGS_FILEPATH).toString();
|
||||
const auto fp = Utils::FilePath::fromSettings(
|
||||
diag.value(SETTINGS_KEY_SUPPRESSED_DIAGS_FILEPATH));
|
||||
if (fp.isEmpty())
|
||||
continue;
|
||||
const QString message = diag.value(SETTINGS_KEY_SUPPRESSED_DIAGS_MESSAGE).toString();
|
||||
if (message.isEmpty())
|
||||
continue;
|
||||
Utils::FilePath fullPath = Utils::FilePath::fromString(fp);
|
||||
if (fullPath.toFileInfo().isRelative())
|
||||
fullPath = m_project->projectDirectory().pathAppended(fp);
|
||||
const Utils::FilePath fullPath = m_project->projectDirectory().resolvePath(fp);
|
||||
if (!fullPath.exists())
|
||||
continue;
|
||||
const int uniquifier = diag.value(SETTINGS_KEY_SUPPRESSED_DIAGS_UNIQIFIER).toInt();
|
||||
m_suppressedDiagnostics << SuppressedDiagnostic(Utils::FilePath::fromString(fp),
|
||||
message,
|
||||
uniquifier);
|
||||
m_suppressedDiagnostics << SuppressedDiagnostic(fp, message, uniquifier);
|
||||
}
|
||||
emit suppressedDiagnosticsChanged();
|
||||
|
||||
@@ -178,16 +174,17 @@ void ClangToolsProjectSettings::store()
|
||||
Store map;
|
||||
map.insert(SETTINGS_KEY_USE_GLOBAL_SETTINGS, m_useGlobalSettings);
|
||||
|
||||
const QStringList dirs = Utils::transform<QList>(m_selectedDirs, &Utils::FilePath::toString);
|
||||
const QVariantList dirs = Utils::transform<QList>(m_selectedDirs, &Utils::FilePath::toSettings);
|
||||
map.insert(SETTINGS_KEY_SELECTED_DIRS, dirs);
|
||||
|
||||
const QStringList files = Utils::transform<QList>(m_selectedFiles, &Utils::FilePath::toString);
|
||||
const QVariantList files
|
||||
= Utils::transform<QList>(m_selectedFiles, &Utils::FilePath::toSettings);
|
||||
map.insert(SETTINGS_KEY_SELECTED_FILES, files);
|
||||
|
||||
QVariantList list;
|
||||
for (const SuppressedDiagnostic &diag : std::as_const(m_suppressedDiagnostics)) {
|
||||
Store diagMap;
|
||||
diagMap.insert(SETTINGS_KEY_SUPPRESSED_DIAGS_FILEPATH, diag.filePath.toString());
|
||||
diagMap.insert(SETTINGS_KEY_SUPPRESSED_DIAGS_FILEPATH, diag.filePath.toSettings());
|
||||
diagMap.insert(SETTINGS_KEY_SUPPRESSED_DIAGS_MESSAGE, diag.description);
|
||||
diagMap.insert(SETTINGS_KEY_SUPPRESSED_DIAGS_UNIQIFIER, diag.uniquifier);
|
||||
list << variantFromStore(diagMap);
|
||||
|
@@ -154,7 +154,7 @@ FilePath fullPath(const FilePath &executable)
|
||||
candidate = candidate.withExecutableSuffix();
|
||||
} else {
|
||||
const Environment environment = Environment::systemEnvironment();
|
||||
const FilePath expandedPath = environment.searchInPath(candidate.toString());
|
||||
const FilePath expandedPath = environment.searchInPath(candidate.fileName());
|
||||
if (!expandedPath.isEmpty())
|
||||
candidate = expandedPath;
|
||||
}
|
||||
|
@@ -401,8 +401,7 @@ static void buildTree(ProjectExplorer::Tree *parent,
|
||||
current->name = node.name;
|
||||
current->isDir = node.children.size();
|
||||
if (parent) {
|
||||
current->fullPath = Utils::FilePath::fromString(parent->fullPath.toString()
|
||||
+ current->name);
|
||||
current->fullPath = parent->fullPath.pathAppended(current->name);
|
||||
parent->childDirectories.push_back(current);
|
||||
} else {
|
||||
current->fullPath = Utils::FilePath::fromString(current->name);
|
||||
@@ -413,9 +412,9 @@ static void buildTree(ProjectExplorer::Tree *parent,
|
||||
}
|
||||
|
||||
static bool needsLink(ProjectExplorer::Tree *node) {
|
||||
if (node->fullPath.toString() == "clang-analyzer-")
|
||||
if (node->fullPath.path() == "clang-analyzer-")
|
||||
return true;
|
||||
return !node->isDir && !node->fullPath.toString().startsWith("clang-analyzer-");
|
||||
return !node->isDir && !node->fullPath.startsWith("clang-analyzer-");
|
||||
}
|
||||
|
||||
class BaseChecksTreeModel : public ProjectExplorer::SelectableFilesModel // FIXME: This isn't about files.
|
||||
@@ -591,7 +590,7 @@ public:
|
||||
// 'clang-analyzer-' group
|
||||
if (node->isDir)
|
||||
return CppEditor::Constants::CLANG_STATIC_ANALYZER_DOCUMENTATION_URL;
|
||||
return clangTidyDocUrl(node->fullPath.toString());
|
||||
return clangTidyDocUrl(node->fullPath.path());
|
||||
}
|
||||
|
||||
return BaseChecksTreeModel::data(fullIndex, role);
|
||||
@@ -629,7 +628,7 @@ private:
|
||||
return false;
|
||||
|
||||
auto *node = static_cast<Tree *>(index.internalPointer());
|
||||
const QString nodeName = node->fullPath.toString();
|
||||
const QString nodeName = node->fullPath.path();
|
||||
if ((check.endsWith("*") && nodeName.startsWith(check.left(check.length() - 1)))
|
||||
|| (!node->isDir && nodeName == check)) {
|
||||
result = index;
|
||||
@@ -646,7 +645,7 @@ private:
|
||||
if (root->checked == Qt::Unchecked)
|
||||
return;
|
||||
if (root->checked == Qt::Checked) {
|
||||
checks += "," + root->fullPath.toString();
|
||||
checks += "," + root->fullPath.path();
|
||||
if (root->isDir)
|
||||
checks += "*";
|
||||
return;
|
||||
|
@@ -208,13 +208,14 @@ void DocumentClangToolRunner::run()
|
||||
const AnalyzeUnits units{{m_fileInfo, tool}};
|
||||
const auto diagnosticFilter = [mappedPath = vfso().autoSavedFilePath(m_document)](
|
||||
const FilePath &path) { return path == mappedPath; };
|
||||
const AnalyzeInputData input{tool,
|
||||
runSettings,
|
||||
config,
|
||||
m_temporaryDir.path(),
|
||||
env,
|
||||
vfso().overlayFilePath().toString(),
|
||||
diagnosticFilter};
|
||||
const AnalyzeInputData input{
|
||||
tool,
|
||||
runSettings,
|
||||
config,
|
||||
m_temporaryDir.path(),
|
||||
env,
|
||||
vfso().overlayFilePath().nativePath(),
|
||||
diagnosticFilter};
|
||||
const auto setupHandler = [this, executable](const AnalyzeUnit &) {
|
||||
return !m_document->isModified() || isVFSOverlaySupported(executable);
|
||||
};
|
||||
@@ -317,7 +318,7 @@ bool DocumentClangToolRunner::isSuppressed(const Diagnostic &diagnostic) const
|
||||
return false;
|
||||
FilePath filePath = suppressed.filePath;
|
||||
if (filePath.toFileInfo().isRelative())
|
||||
filePath = m_lastProjectDirectory.pathAppended(filePath.toString());
|
||||
filePath = m_lastProjectDirectory.resolvePath(filePath);
|
||||
return filePath == diagnostic.location.filePath;
|
||||
};
|
||||
return Utils::anyOf(m_suppressed, equalsSuppressed);
|
||||
|
@@ -42,13 +42,12 @@ static Range toRange(const QTextDocument *doc, DiagnosticRange locations)
|
||||
void ClangToolQuickFixOperation::perform()
|
||||
{
|
||||
TextEditor::PlainRefactoringFileFactory changes;
|
||||
QMap<QString, TextEditor::RefactoringFilePtr> refactoringFiles;
|
||||
QMap<Utils::FilePath, TextEditor::RefactoringFilePtr> refactoringFiles;
|
||||
|
||||
for (const ExplainingStep &step : m_diagnostic.explainingSteps) {
|
||||
if (!step.isFixIt)
|
||||
continue;
|
||||
TextEditor::RefactoringFilePtr &refactoringFile
|
||||
= refactoringFiles[step.location.filePath.toString()];
|
||||
TextEditor::RefactoringFilePtr &refactoringFile = refactoringFiles[step.location.filePath];
|
||||
if (refactoringFile.isNull())
|
||||
refactoringFile = changes.file(step.location.filePath);
|
||||
Utils::ChangeSet changeSet = refactoringFile->changeSet();
|
||||
|
@@ -164,9 +164,8 @@ static FilePath queryResourceDir(const FilePath &clangToolPath)
|
||||
[&clangToolPath](const QString &stdOut, const QString &) -> std::optional<FilePath> {
|
||||
QString output = stdOut;
|
||||
QTextStream stream(&output);
|
||||
const QString path = clangToolPath.parentDir().parentDir()
|
||||
.pathAppended(stream.readLine()).toString();
|
||||
const auto filePath = FilePath::fromUserInput(QDir::cleanPath(path));
|
||||
const FilePath filePath
|
||||
= clangToolPath.parentDir().parentDir().pathAppended(stream.readLine()).cleanPath();
|
||||
if (filePath.exists())
|
||||
return filePath;
|
||||
return {};
|
||||
|
@@ -26,9 +26,6 @@ VirtualFileSystemOverlay::VirtualFileSystemOverlay(const QString &rootPattern)
|
||||
void VirtualFileSystemOverlay::update()
|
||||
{
|
||||
overlayFilePath().removeRecursively();
|
||||
QFile overlayFile(m_overlayFilePath.toString());
|
||||
if (!overlayFile.open(QFile::ReadWrite))
|
||||
return;
|
||||
std::map<Utils::FilePath, QList<Core::IDocument *>> documentRoots;
|
||||
const QList<Core::IDocument *> &modifiedDocuments = Core::DocumentManager::modifiedDocuments();
|
||||
QHash<Core::IDocument *, AutoSavedPath> newSaved;
|
||||
@@ -87,9 +84,10 @@ void VirtualFileSystemOverlay::update()
|
||||
main["roots"] = jsonRoots;
|
||||
|
||||
QJsonDocument overlay(main);
|
||||
if (!overlayFile.write(overlay.toJson(QJsonDocument::Compact)))
|
||||
const Utils::expected_str<qint64> res = m_overlayFilePath.writeFileContents(
|
||||
overlay.toJson(QJsonDocument::Compact));
|
||||
if (!res)
|
||||
qCDebug(LOG) << "failed to write vfso to " << m_overlayFilePath;
|
||||
overlayFile.close();
|
||||
}
|
||||
|
||||
Utils::FilePath VirtualFileSystemOverlay::overlayFilePath() const { return m_overlayFilePath; }
|
||||
|
Reference in New Issue
Block a user