Skip to content

Commit 90a3394

Browse files
committed
use library getGuideline/getClassification in GUI
1 parent 9fb3871 commit 90a3394

File tree

1 file changed

+7
-95
lines changed

1 file changed

+7
-95
lines changed

gui/resultstree.cpp

+7-95
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "application.h"
2222
#include "applicationlist.h"
23+
#include "checkers.h"
2324
#include "common.h"
2425
#include "erroritem.h"
2526
#include "errorlogger.h"
@@ -98,25 +99,11 @@ static constexpr int COLUMN_TAGS = 11;
9899
static constexpr int COLUMN_CWE = 12;
99100

100101
static QString getGuideline(ReportType reportType, const QMap<QString,QString>& guidelines, const QString& errorId, Severity severity) {
101-
if (reportType == ReportType::autosar) {
102-
if (errorId.startsWith("premium-autosar-"))
103-
return errorId.mid(16);
104-
if (errorId.startsWith("premium-misra-cpp-2008-"))
105-
return "M" + errorId.mid(23);
106-
}
107-
if (reportType == ReportType::certC || reportType == ReportType::certCpp) {
108-
if (errorId.startsWith("premium-cert-"))
109-
return errorId.mid(13).toUpper();
110-
}
111-
if (errorId.startsWith("premium-"))
112-
return getGuideline(reportType, guidelines, errorId.mid(8), severity);
113-
if (reportType == ReportType::misraC && (errorId.startsWith("misra-c20") || errorId.startsWith("misra-c-20")))
114-
return errorId.mid(errorId.lastIndexOf("-") + 1);
115-
if (reportType == ReportType::misraCpp2008 && errorId.startsWith("misra-cpp-2008-"))
116-
return errorId.mid(15);
117-
if (reportType == ReportType::misraCpp2023 && errorId.startsWith("misra-cpp-2023-"))
118-
return errorId.mid(15);
119-
const QString& guideline = guidelines.value(errorId);
102+
auto guideline = QString::fromStdString(checkers::getGuideline(errorId.toStdString(), reportType));
103+
if (!guideline.isEmpty())
104+
return guideline;
105+
106+
guideline = guidelines.value(errorId);
120107
if (!guideline.isEmpty())
121108
return guideline;
122109
if (severity == Severity::error || severity == Severity::warning)
@@ -125,82 +112,7 @@ static QString getGuideline(ReportType reportType, const QMap<QString,QString>&
125112
}
126113

127114
static QString getClassification(ReportType reportType, const QString& guideline) {
128-
if (guideline.isEmpty())
129-
return QString();
130-
auto getFromInfo = [](const std::vector<checkers::Info>& info, const QString& guideline) -> QString {
131-
for (const checkers::Info& i: info) {
132-
// cppcheck-suppress useStlAlgorithm
133-
if (guideline.compare(i.guideline, Qt::CaseInsensitive) == 0)
134-
return i.classification;
135-
}
136-
return QString();
137-
};
138-
if (reportType == ReportType::autosar)
139-
return getFromInfo(checkers::autosarInfo, guideline);
140-
if (reportType == ReportType::certC || reportType == ReportType::certCpp) {
141-
if (guideline.endsWith("-CPP"))
142-
return getFromInfo(checkers::certCppInfo, guideline);
143-
if (guideline.endsWith("-C"))
144-
return getFromInfo(checkers::certCInfo, guideline);
145-
}
146-
else if (reportType == ReportType::misraC) {
147-
QStringList list = guideline.split(".");
148-
if (list.size() == 2) {
149-
bool ok = true;
150-
const int a = list[0].toInt(&ok);
151-
if (!ok)
152-
return QString();
153-
const int b = list[1].toInt(&ok);
154-
if (!ok)
155-
return QString();
156-
for (const auto& info: checkers::misraC2012Rules) {
157-
// cppcheck-suppress useStlAlgorithm
158-
if (info.a == a && info.b == b)
159-
return info.str;
160-
}
161-
}
162-
}
163-
else if (reportType == ReportType::misraCpp2008) {
164-
QStringList list = guideline.split("-");
165-
if (list.size() == 3) {
166-
bool ok = true;
167-
const int a = list[0].toInt(&ok);
168-
if (!ok)
169-
return QString();
170-
const int b = list[1].toInt(&ok);
171-
if (!ok)
172-
return QString();
173-
const int c = list[2].toInt(&ok);
174-
if (!ok)
175-
return QString();
176-
for (const auto& info: checkers::misraCpp2008Rules) {
177-
// cppcheck-suppress useStlAlgorithm
178-
if (info.a == a && info.b == b && info.c == c)
179-
return info.classification;
180-
}
181-
}
182-
}
183-
else if (reportType == ReportType::misraCpp2023) {
184-
QStringList list = guideline.split(".");
185-
if (list.size() == 3) {
186-
bool ok = true;
187-
const int a = list[0].toInt(&ok);
188-
if (!ok)
189-
return QString();
190-
const int b = list[1].toInt(&ok);
191-
if (!ok)
192-
return QString();
193-
const int c = list[2].toInt(&ok);
194-
if (!ok)
195-
return QString();
196-
for (const auto& info: checkers::misraCpp2023Rules) {
197-
// cppcheck-suppress useStlAlgorithm
198-
if (info.a == a && info.b == b && info.c == c)
199-
return info.classification;
200-
}
201-
}
202-
}
203-
return QString();
115+
return QString::fromStdString(checkers::getClassification(guideline.toStdString(), reportType));
204116
}
205117

206118
static Severity getSeverityFromClassification(const QString &c) {

0 commit comments

Comments
 (0)