forked from qt-creator/qt-creator
ClangTools: Move CSA's project settings into ClangToolsProjectSettings
Change-Id: I830c280e718aae416cd487eb5d02caf1e873f7c1 Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
@@ -26,8 +26,7 @@
|
||||
#include "clangstaticanalyzerdiagnosticview.h"
|
||||
|
||||
#include "clangtoolsdiagnosticmodel.h"
|
||||
#include "clangstaticanalyzerprojectsettings.h"
|
||||
#include "clangstaticanalyzerprojectsettingsmanager.h"
|
||||
#include "clangtoolsprojectsettings.h"
|
||||
#include "clangtoolsutils.h"
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
@@ -70,7 +69,7 @@ void ClangStaticAnalyzerDiagnosticView::suppressCurrentDiagnostic()
|
||||
filePath = relativeFilePath;
|
||||
const SuppressedDiagnostic supDiag(filePath, diag.description, diag.issueContextKind,
|
||||
diag.issueContext, diag.explainingSteps.count());
|
||||
ProjectSettingsManager::getSettings(project)->addSuppressedDiagnostic(supDiag);
|
||||
ClangToolsProjectSettingsManager::getSettings(project)->addSuppressedDiagnostic(supDiag);
|
||||
} else {
|
||||
filterModel->addSuppressedDiagnostic(SuppressedDiagnostic(diag));
|
||||
}
|
||||
|
||||
@@ -1,145 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "clangstaticanalyzerprojectsettings.h"
|
||||
|
||||
#include "clangtoolsdiagnostic.h"
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
namespace ClangTools {
|
||||
namespace Internal {
|
||||
|
||||
static QString suppressedDiagnosticsKey()
|
||||
{
|
||||
return QLatin1String("ClangStaticAnalyzer.SuppressedDiagnostics");
|
||||
}
|
||||
|
||||
static QString suppressedDiagnosticFilePathKey()
|
||||
{
|
||||
return QLatin1String("ClangStaticAnalyzer.SuppressedDiagnosticFilePath");
|
||||
}
|
||||
|
||||
static QString suppressedDiagnosticMessageKey()
|
||||
{
|
||||
return QLatin1String("ClangStaticAnalyzer.SuppressedDiagnosticMessage");
|
||||
}
|
||||
|
||||
static QString suppressedDiagnosticContextKindKey()
|
||||
{
|
||||
return QLatin1String("ClangStaticAnalyzer.SuppressedDiagnosticContextKind");
|
||||
}
|
||||
|
||||
static QString suppressedDiagnosticContextKey()
|
||||
{
|
||||
return QLatin1String("ClangStaticAnalyzer.SuppressedDiagnosticContext");
|
||||
}
|
||||
|
||||
static QString suppressedDiagnosticUniquifierKey()
|
||||
{
|
||||
return QLatin1String("ClangStaticAnalyzer.SuppressedDiagnosticUniquifier");
|
||||
}
|
||||
|
||||
ProjectSettings::ProjectSettings(ProjectExplorer::Project *project) : m_project(project)
|
||||
{
|
||||
load();
|
||||
connect(project, &ProjectExplorer::Project::aboutToSaveSettings, this,
|
||||
&ProjectSettings::store);
|
||||
}
|
||||
|
||||
void ProjectSettings::addSuppressedDiagnostic(const SuppressedDiagnostic &diag)
|
||||
{
|
||||
QTC_ASSERT(!m_suppressedDiagnostics.contains(diag), return);
|
||||
m_suppressedDiagnostics << diag;
|
||||
emit suppressedDiagnosticsChanged();
|
||||
}
|
||||
|
||||
void ProjectSettings::removeSuppressedDiagnostic(const SuppressedDiagnostic &diag)
|
||||
{
|
||||
const bool wasPresent = m_suppressedDiagnostics.removeOne(diag);
|
||||
QTC_ASSERT(wasPresent, return);
|
||||
emit suppressedDiagnosticsChanged();
|
||||
}
|
||||
|
||||
void ProjectSettings::removeAllSuppressedDiagnostics()
|
||||
{
|
||||
m_suppressedDiagnostics.clear();
|
||||
emit suppressedDiagnosticsChanged();
|
||||
}
|
||||
|
||||
void ProjectSettings::load()
|
||||
{
|
||||
const QVariantList list = m_project->namedSettings(suppressedDiagnosticsKey()).toList();
|
||||
foreach (const QVariant &v, list) {
|
||||
const QVariantMap diag = v.toMap();
|
||||
const QString fp = diag.value(suppressedDiagnosticFilePathKey()).toString();
|
||||
if (fp.isEmpty())
|
||||
continue;
|
||||
const QString message = diag.value(suppressedDiagnosticMessageKey()).toString();
|
||||
if (message.isEmpty())
|
||||
continue;
|
||||
Utils::FileName fullPath = Utils::FileName::fromString(fp);
|
||||
if (fullPath.toFileInfo().isRelative()) {
|
||||
fullPath = m_project->projectDirectory();
|
||||
fullPath.appendPath(fp);
|
||||
}
|
||||
if (!fullPath.exists())
|
||||
continue;
|
||||
const QString contextKind = diag.value(suppressedDiagnosticContextKindKey()).toString();
|
||||
const QString context = diag.value(suppressedDiagnosticContextKey()).toString();
|
||||
const int uniquifier = diag.value(suppressedDiagnosticUniquifierKey()).toInt();
|
||||
m_suppressedDiagnostics << SuppressedDiagnostic(Utils::FileName::fromString(fp), message,
|
||||
contextKind, context, uniquifier);
|
||||
}
|
||||
emit suppressedDiagnosticsChanged();
|
||||
}
|
||||
|
||||
void ProjectSettings::store()
|
||||
{
|
||||
QVariantList list;
|
||||
foreach (const SuppressedDiagnostic &diag, m_suppressedDiagnostics) {
|
||||
QVariantMap diagMap;
|
||||
diagMap.insert(suppressedDiagnosticFilePathKey(), diag.filePath.toString());
|
||||
diagMap.insert(suppressedDiagnosticMessageKey(), diag.description);
|
||||
diagMap.insert(suppressedDiagnosticContextKindKey(), diag.contextKind);
|
||||
diagMap.insert(suppressedDiagnosticContextKey(), diag.context);
|
||||
diagMap.insert(suppressedDiagnosticUniquifierKey(), diag.uniquifier);
|
||||
list << diagMap;
|
||||
}
|
||||
m_project->setNamedSettings(suppressedDiagnosticsKey(), list);
|
||||
}
|
||||
|
||||
|
||||
SuppressedDiagnostic::SuppressedDiagnostic(const Diagnostic &diag)
|
||||
: filePath(Utils::FileName::fromString(diag.location.filePath))
|
||||
, description(diag.description)
|
||||
, contextKind(diag.issueContextKind)
|
||||
, context(diag.issueContext)
|
||||
, uniquifier(diag.explainingSteps.count())
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangTools
|
||||
@@ -1,92 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
#include <QList>
|
||||
#include <QObject>
|
||||
|
||||
namespace ClangTools {
|
||||
namespace Internal {
|
||||
class Diagnostic;
|
||||
|
||||
class SuppressedDiagnostic
|
||||
{
|
||||
public:
|
||||
SuppressedDiagnostic(const Utils::FileName &filePath, const QString &description,
|
||||
const QString &contextKind, const QString &context, int uniquifier)
|
||||
: filePath(filePath)
|
||||
, description(description)
|
||||
, contextKind(contextKind)
|
||||
, context(context)
|
||||
, uniquifier(uniquifier)
|
||||
{
|
||||
}
|
||||
|
||||
SuppressedDiagnostic(const Diagnostic &diag);
|
||||
|
||||
Utils::FileName filePath; // Relative for files in project, absolute otherwise.
|
||||
QString description;
|
||||
QString contextKind;
|
||||
QString context;
|
||||
int uniquifier;
|
||||
};
|
||||
|
||||
inline bool operator==(const SuppressedDiagnostic &d1, const SuppressedDiagnostic &d2)
|
||||
{
|
||||
return d1.filePath == d2.filePath && d1.description == d2.description
|
||||
&& d1.contextKind == d2.contextKind && d1.context == d2.context
|
||||
&& d1.uniquifier == d2.uniquifier;
|
||||
}
|
||||
|
||||
typedef QList<SuppressedDiagnostic> SuppressedDiagnosticsList;
|
||||
|
||||
class ProjectSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectSettings(ProjectExplorer::Project *project);
|
||||
|
||||
SuppressedDiagnosticsList suppressedDiagnostics() const { return m_suppressedDiagnostics; }
|
||||
void addSuppressedDiagnostic(const SuppressedDiagnostic &diag);
|
||||
void removeSuppressedDiagnostic(const SuppressedDiagnostic &diag);
|
||||
void removeAllSuppressedDiagnostics();
|
||||
|
||||
signals:
|
||||
void suppressedDiagnosticsChanged();
|
||||
|
||||
private:
|
||||
void load();
|
||||
void store();
|
||||
|
||||
ProjectExplorer::Project * const m_project;
|
||||
SuppressedDiagnosticsList m_suppressedDiagnostics;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangTools
|
||||
@@ -1,58 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "clangstaticanalyzerprojectsettingsmanager.h"
|
||||
|
||||
#include "clangstaticanalyzerprojectsettings.h"
|
||||
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
namespace ClangTools {
|
||||
namespace Internal {
|
||||
|
||||
ProjectSettingsManager::ProjectSettingsManager()
|
||||
{
|
||||
QObject::connect(ProjectExplorer::SessionManager::instance(),
|
||||
&ProjectExplorer::SessionManager::aboutToRemoveProject,
|
||||
&ProjectSettingsManager::handleProjectToBeRemoved);
|
||||
}
|
||||
|
||||
ProjectSettings *ProjectSettingsManager::getSettings(ProjectExplorer::Project *project)
|
||||
{
|
||||
auto &settings = m_settings[project];
|
||||
if (!settings)
|
||||
settings.reset(new ProjectSettings(project));
|
||||
return settings.data();
|
||||
}
|
||||
|
||||
void ProjectSettingsManager::handleProjectToBeRemoved(ProjectExplorer::Project *project)
|
||||
{
|
||||
m_settings.remove(project);
|
||||
}
|
||||
|
||||
ProjectSettingsManager::SettingsMap ProjectSettingsManager::m_settings;
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangTools
|
||||
@@ -1,52 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 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
|
||||
|
||||
namespace ProjectExplorer { class Project; }
|
||||
|
||||
#include <QHash>
|
||||
#include <QSharedPointer>
|
||||
|
||||
namespace ClangTools {
|
||||
namespace Internal {
|
||||
class ProjectSettings;
|
||||
|
||||
class ProjectSettingsManager
|
||||
{
|
||||
public:
|
||||
ProjectSettingsManager();
|
||||
|
||||
static ProjectSettings *getSettings(ProjectExplorer::Project *project);
|
||||
|
||||
private:
|
||||
static void handleProjectToBeRemoved(ProjectExplorer::Project *project);
|
||||
|
||||
typedef QHash<ProjectExplorer::Project *, QSharedPointer<ProjectSettings>> SettingsMap;
|
||||
static SettingsMap m_settings;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangTools
|
||||
@@ -26,8 +26,7 @@
|
||||
#include "clangstaticanalyzerprojectsettingswidget.h"
|
||||
#include "ui_clangstaticanalyzerprojectsettingswidget.h"
|
||||
|
||||
#include "clangstaticanalyzerprojectsettings.h"
|
||||
#include "clangstaticanalyzerprojectsettingsmanager.h"
|
||||
#include "clangtoolsprojectsettings.h"
|
||||
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -59,12 +58,12 @@ private:
|
||||
ProjectSettingsWidget::ProjectSettingsWidget(ProjectExplorer::Project *project, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
m_ui(new Ui::ProjectSettingsWidget)
|
||||
, m_projectSettings(ProjectSettingsManager::getSettings(project))
|
||||
, m_projectSettings(ClangToolsProjectSettingsManager::getSettings(project))
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
auto * const model = new SuppressedDiagnosticsModel(this);
|
||||
model->setDiagnostics(m_projectSettings->suppressedDiagnostics());
|
||||
connect(m_projectSettings, &ProjectSettings::suppressedDiagnosticsChanged,
|
||||
connect(m_projectSettings, &ClangToolsProjectSettings::suppressedDiagnosticsChanged,
|
||||
[model, this] {
|
||||
model->setDiagnostics(m_projectSettings->suppressedDiagnostics());
|
||||
updateButtonStates();
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace ProjectExplorer { class Project; }
|
||||
|
||||
namespace ClangTools {
|
||||
namespace Internal {
|
||||
class ProjectSettings;
|
||||
class ClangToolsProjectSettings;
|
||||
|
||||
namespace Ui { class ProjectSettingsWidget; }
|
||||
|
||||
@@ -50,7 +50,7 @@ private:
|
||||
void removeSelected();
|
||||
|
||||
Ui::ProjectSettingsWidget * const m_ui;
|
||||
ProjectSettings * const m_projectSettings;
|
||||
ClangToolsProjectSettings * const m_projectSettings;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -11,8 +11,6 @@ INCLUDEPATH += $$LLVM_INCLUDEPATH
|
||||
SOURCES += \
|
||||
clangselectablefilesdialog.cpp \
|
||||
clangstaticanalyzerdiagnosticview.cpp \
|
||||
clangstaticanalyzerprojectsettings.cpp \
|
||||
clangstaticanalyzerprojectsettingsmanager.cpp \
|
||||
clangstaticanalyzerprojectsettingswidget.cpp \
|
||||
clangstaticanalyzerruncontrol.cpp \
|
||||
clangstaticanalyzerrunner.cpp \
|
||||
@@ -36,8 +34,6 @@ HEADERS += \
|
||||
clangfileinfo.h \
|
||||
clangselectablefilesdialog.h \
|
||||
clangstaticanalyzerdiagnosticview.h \
|
||||
clangstaticanalyzerprojectsettings.h \
|
||||
clangstaticanalyzerprojectsettingsmanager.h \
|
||||
clangstaticanalyzerprojectsettingswidget.h \
|
||||
clangstaticanalyzerruncontrol.h \
|
||||
clangstaticanalyzerrunner.h \
|
||||
|
||||
@@ -47,10 +47,6 @@ QtcPlugin {
|
||||
"clangselectablefilesdialog.ui",
|
||||
"clangstaticanalyzerdiagnosticview.cpp",
|
||||
"clangstaticanalyzerdiagnosticview.h",
|
||||
"clangstaticanalyzerprojectsettings.cpp",
|
||||
"clangstaticanalyzerprojectsettings.h",
|
||||
"clangstaticanalyzerprojectsettingsmanager.cpp",
|
||||
"clangstaticanalyzerprojectsettingsmanager.h",
|
||||
"clangstaticanalyzerprojectsettingswidget.cpp",
|
||||
"clangstaticanalyzerprojectsettingswidget.h",
|
||||
"clangstaticanalyzerprojectsettingswidget.ui",
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include "clangtoolsdiagnosticmodel.h"
|
||||
|
||||
#include "clangstaticanalyzerdiagnosticview.h"
|
||||
#include "clangstaticanalyzerprojectsettingsmanager.h"
|
||||
#include "clangtoolsprojectsettings.h"
|
||||
#include "clangtoolsutils.h"
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
@@ -323,14 +323,14 @@ void ClangStaticAnalyzerDiagnosticFilterModel::setProject(ProjectExplorer::Proje
|
||||
{
|
||||
QTC_ASSERT(project, return);
|
||||
if (m_project) {
|
||||
disconnect(ProjectSettingsManager::getSettings(m_project),
|
||||
&ProjectSettings::suppressedDiagnosticsChanged, this,
|
||||
disconnect(ClangToolsProjectSettingsManager::getSettings(m_project),
|
||||
&ClangToolsProjectSettings::suppressedDiagnosticsChanged, this,
|
||||
&ClangStaticAnalyzerDiagnosticFilterModel::handleSuppressedDiagnosticsChanged);
|
||||
}
|
||||
m_project = project;
|
||||
m_lastProjectDirectory = m_project->projectDirectory();
|
||||
connect(ProjectSettingsManager::getSettings(m_project),
|
||||
&ProjectSettings::suppressedDiagnosticsChanged,
|
||||
connect(ClangToolsProjectSettingsManager::getSettings(m_project),
|
||||
&ClangToolsProjectSettings::suppressedDiagnosticsChanged,
|
||||
this, &ClangStaticAnalyzerDiagnosticFilterModel::handleSuppressedDiagnosticsChanged);
|
||||
handleSuppressedDiagnosticsChanged();
|
||||
}
|
||||
@@ -367,7 +367,7 @@ void ClangStaticAnalyzerDiagnosticFilterModel::handleSuppressedDiagnosticsChange
|
||||
{
|
||||
QTC_ASSERT(m_project, return);
|
||||
m_suppressedDiagnostics
|
||||
= ProjectSettingsManager::getSettings(m_project)->suppressedDiagnostics();
|
||||
= ClangToolsProjectSettingsManager::getSettings(m_project)->suppressedDiagnostics();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "clangtoolsdiagnostic.h"
|
||||
#include "clangstaticanalyzerprojectsettings.h"
|
||||
#include "clangtoolsprojectsettings.h"
|
||||
|
||||
#include <debugger/analyzer/detailederrorview.h>
|
||||
#include <utils/fileutils.h>
|
||||
|
||||
@@ -24,16 +24,24 @@
|
||||
****************************************************************************/
|
||||
|
||||
#include "clangtoolsprojectsettings.h"
|
||||
#include "clangtoolsdiagnostic.h"
|
||||
|
||||
#include <projectexplorer/session.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
namespace ClangTools {
|
||||
namespace Internal {
|
||||
|
||||
static const char SETTINGS_KEY_SELECTED_DIRS[] = "ClangTools.SelectedDirs";
|
||||
static const char SETTINGS_KEY_SELECTED_FILES[] = "ClangTools.SelectedFiles";
|
||||
static const char SETTINGS_KEY_SUPPRESSED_DIAGS[] = "ClangTools.SuppressedDiagnostics";
|
||||
static const char SETTINGS_KEY_SUPPRESSED_DIAGS_FILEPATH[] = "ClangTools.SuppressedDiagnosticFilePath";
|
||||
static const char SETTINGS_KEY_SUPPRESSED_DIAGS_MESSAGE[] = "ClangTools.SuppressedDiagnosticMessage";
|
||||
static const char SETTINGS_KEY_SUPPRESSED_DIAGS_CONTEXTKIND[] = "ClangTools.SuppressedDiagnosticContextKind";
|
||||
static const char SETTINGS_KEY_SUPPRESSED_DIAGS_CONTEXT[] = "ClangTools.SuppressedDiagnosticContext";
|
||||
static const char SETTINGS_KEY_SUPPRESSED_DIAGS_UNIQIFIER[] = "ClangTools.SuppressedDiagnosticUniquifier";
|
||||
|
||||
ClangToolsProjectSettings::ClangToolsProjectSettings(ProjectExplorer::Project *project)
|
||||
: m_project(project)
|
||||
@@ -50,6 +58,26 @@ ClangToolsProjectSettings::~ClangToolsProjectSettings()
|
||||
store();
|
||||
}
|
||||
|
||||
void ClangToolsProjectSettings::addSuppressedDiagnostic(const SuppressedDiagnostic &diag)
|
||||
{
|
||||
QTC_ASSERT(!m_suppressedDiagnostics.contains(diag), return);
|
||||
m_suppressedDiagnostics << diag;
|
||||
emit suppressedDiagnosticsChanged();
|
||||
}
|
||||
|
||||
void ClangToolsProjectSettings::removeSuppressedDiagnostic(const SuppressedDiagnostic &diag)
|
||||
{
|
||||
const bool wasPresent = m_suppressedDiagnostics.removeOne(diag);
|
||||
QTC_ASSERT(wasPresent, return);
|
||||
emit suppressedDiagnosticsChanged();
|
||||
}
|
||||
|
||||
void ClangToolsProjectSettings::removeAllSuppressedDiagnostics()
|
||||
{
|
||||
m_suppressedDiagnostics.clear();
|
||||
emit suppressedDiagnosticsChanged();
|
||||
}
|
||||
|
||||
void ClangToolsProjectSettings::load()
|
||||
{
|
||||
auto toFileName = [](const QString &s) { return Utils::FileName::fromString(s); };
|
||||
@@ -59,6 +87,30 @@ void ClangToolsProjectSettings::load()
|
||||
|
||||
const QStringList files = m_project->namedSettings(SETTINGS_KEY_SELECTED_FILES).toStringList();
|
||||
m_selectedFiles = Utils::transform<QSet>(files, toFileName);
|
||||
|
||||
const QVariantList list = m_project->namedSettings(SETTINGS_KEY_SUPPRESSED_DIAGS).toList();
|
||||
foreach (const QVariant &v, list) {
|
||||
const QVariantMap diag = v.toMap();
|
||||
const QString fp = diag.value(SETTINGS_KEY_SUPPRESSED_DIAGS_FILEPATH).toString();
|
||||
if (fp.isEmpty())
|
||||
continue;
|
||||
const QString message = diag.value(SETTINGS_KEY_SUPPRESSED_DIAGS_MESSAGE).toString();
|
||||
if (message.isEmpty())
|
||||
continue;
|
||||
Utils::FileName fullPath = Utils::FileName::fromString(fp);
|
||||
if (fullPath.toFileInfo().isRelative()) {
|
||||
fullPath = m_project->projectDirectory();
|
||||
fullPath.appendPath(fp);
|
||||
}
|
||||
if (!fullPath.exists())
|
||||
continue;
|
||||
const QString contextKind = diag.value(SETTINGS_KEY_SUPPRESSED_DIAGS_CONTEXTKIND).toString();
|
||||
const QString context = diag.value(SETTINGS_KEY_SUPPRESSED_DIAGS_CONTEXT).toString();
|
||||
const int uniquifier = diag.value(SETTINGS_KEY_SUPPRESSED_DIAGS_UNIQIFIER).toInt();
|
||||
m_suppressedDiagnostics << SuppressedDiagnostic(Utils::FileName::fromString(fp), message,
|
||||
contextKind, context, uniquifier);
|
||||
}
|
||||
emit suppressedDiagnosticsChanged();
|
||||
}
|
||||
|
||||
void ClangToolsProjectSettings::store()
|
||||
@@ -68,6 +120,18 @@ void ClangToolsProjectSettings::store()
|
||||
|
||||
const QStringList files = Utils::transform(m_selectedFiles.toList(), &Utils::FileName::toString);
|
||||
m_project->setNamedSettings(SETTINGS_KEY_SELECTED_FILES, files);
|
||||
|
||||
QVariantList list;
|
||||
foreach (const SuppressedDiagnostic &diag, m_suppressedDiagnostics) {
|
||||
QVariantMap diagMap;
|
||||
diagMap.insert(SETTINGS_KEY_SUPPRESSED_DIAGS_FILEPATH, diag.filePath.toString());
|
||||
diagMap.insert(SETTINGS_KEY_SUPPRESSED_DIAGS_MESSAGE, diag.description);
|
||||
diagMap.insert(SETTINGS_KEY_SUPPRESSED_DIAGS_CONTEXTKIND, diag.contextKind);
|
||||
diagMap.insert(SETTINGS_KEY_SUPPRESSED_DIAGS_CONTEXT, diag.context);
|
||||
diagMap.insert(SETTINGS_KEY_SUPPRESSED_DIAGS_UNIQIFIER, diag.uniquifier);
|
||||
list << diagMap;
|
||||
}
|
||||
m_project->setNamedSettings(SETTINGS_KEY_SUPPRESSED_DIAGS, list);
|
||||
}
|
||||
|
||||
ClangToolsProjectSettingsManager::ClangToolsProjectSettingsManager()
|
||||
@@ -93,5 +157,14 @@ void ClangToolsProjectSettingsManager::handleProjectToBeRemoved(ProjectExplorer:
|
||||
|
||||
ClangToolsProjectSettingsManager::SettingsMap ClangToolsProjectSettingsManager::m_settings;
|
||||
|
||||
SuppressedDiagnostic::SuppressedDiagnostic(const Diagnostic &diag)
|
||||
: filePath(Utils::FileName::fromString(diag.location.filePath))
|
||||
, description(diag.description)
|
||||
, contextKind(diag.issueContextKind)
|
||||
, context(diag.issueContext)
|
||||
, uniquifier(diag.explainingSteps.count())
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangTools
|
||||
|
||||
@@ -33,8 +33,39 @@
|
||||
|
||||
namespace ClangTools {
|
||||
namespace Internal {
|
||||
class Diagnostic;
|
||||
|
||||
class SuppressedDiagnostic
|
||||
{
|
||||
public:
|
||||
SuppressedDiagnostic(const Utils::FileName &filePath, const QString &description,
|
||||
const QString &contextKind, const QString &context, int uniquifier)
|
||||
: filePath(filePath)
|
||||
, description(description)
|
||||
, contextKind(contextKind)
|
||||
, context(context)
|
||||
, uniquifier(uniquifier)
|
||||
{
|
||||
}
|
||||
|
||||
SuppressedDiagnostic(const Diagnostic &diag);
|
||||
|
||||
Utils::FileName filePath; // Relative for files in project, absolute otherwise.
|
||||
QString description;
|
||||
QString contextKind;
|
||||
QString context;
|
||||
int uniquifier;
|
||||
};
|
||||
|
||||
inline bool operator==(const SuppressedDiagnostic &d1, const SuppressedDiagnostic &d2)
|
||||
{
|
||||
return d1.filePath == d2.filePath && d1.description == d2.description
|
||||
&& d1.contextKind == d2.contextKind && d1.context == d2.context
|
||||
&& d1.uniquifier == d2.uniquifier;
|
||||
}
|
||||
|
||||
typedef QList<SuppressedDiagnostic> SuppressedDiagnosticsList;
|
||||
|
||||
// TODO: Incorporate Clang Static Analyzer's ProjectSettings
|
||||
class ClangToolsProjectSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -49,6 +80,14 @@ public:
|
||||
QSet<Utils::FileName> selectedFiles() const { return m_selectedFiles; }
|
||||
void setSelectedFiles(const QSet<Utils::FileName> &value) { m_selectedFiles = value; }
|
||||
|
||||
SuppressedDiagnosticsList suppressedDiagnostics() const { return m_suppressedDiagnostics; }
|
||||
void addSuppressedDiagnostic(const SuppressedDiagnostic &diag);
|
||||
void removeSuppressedDiagnostic(const SuppressedDiagnostic &diag);
|
||||
void removeAllSuppressedDiagnostics();
|
||||
|
||||
signals:
|
||||
void suppressedDiagnosticsChanged();
|
||||
|
||||
private:
|
||||
void load();
|
||||
void store();
|
||||
@@ -56,9 +95,9 @@ private:
|
||||
ProjectExplorer::Project *m_project;
|
||||
QSet<Utils::FileName> m_selectedDirs;
|
||||
QSet<Utils::FileName> m_selectedFiles;
|
||||
SuppressedDiagnosticsList m_suppressedDiagnostics;
|
||||
};
|
||||
|
||||
// TODO: Incorporate Clang Static Analyzer's ProjectSettingsManager
|
||||
class ClangToolsProjectSettingsManager
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user