diff --git a/shell/problem.h b/shell/problem.h --- a/shell/problem.h +++ b/shell/problem.h @@ -43,9 +43,9 @@ * @code * IProblem::Ptr problem(new DetectedProblem()); * problem->setSource(IProblem::Plugin); - * problem->setSeverity(IProblem::Error); - * problem->setDescription(QStringLiteral("Error message")); - * problem->setExplanation(QStringLiteral("Error explanation")); + * problem->setSeverity(IProblem::Warning); + * problem->setDescription(QStringLiteral("Warning message")); + * problem->setExplanation(QStringLiteral("Warning explanation")); * * DocumentRange range; * range.document = IndexedString("/path/to/source/file"); @@ -58,8 +58,22 @@ class KDEVPLATFORMSHELL_EXPORT DetectedProblem : public IProblem { public: + /// Creates new empty DetectedProblem with default properties: + /// severity - KDevelop::IProblem::Error; + /// source - KDevelop::IProblem::Unknown; + /// finalLocationMode - KDevelop::IProblem::Range. DetectedProblem(); - virtual ~DetectedProblem(); + + /// Creates new DetectedProblem, produced by some plugin, for example by analyzer plugins + /// like cppcheck/clang-tydy/valgrind/etc. + /// Default values of problem properties are: + /// severity - KDevelop::IProblem::Error; + /// source - KDevelop::IProblem::Plugin; + /// sourceString - passed pluginName parameter; + /// finalLocationMode - KDevelop::IProblem::Range. + DetectedProblem(const QString& pluginName); + + ~DetectedProblem() override; Source source() const override; void setSource(Source source) override; diff --git a/shell/problem.cpp b/shell/problem.cpp --- a/shell/problem.cpp +++ b/shell/problem.cpp @@ -24,15 +24,17 @@ struct DetectedProblemPrivate { - DetectedProblemPrivate() - : m_severity(KDevelop::IProblem::Error) + DetectedProblemPrivate(const QString& pluginName) + : m_pluginName(pluginName) + , m_severity(KDevelop::IProblem::Error) , m_source(KDevelop::IProblem::Unknown) , m_finalLocationMode(KDevelop::IProblem::Range) { } QString m_description; QString m_explanation; + QString m_pluginName; KDevelop::IProblem::Severity m_severity; KDevelop::IProblem::Source m_source; KDevelop::DocumentRange m_range; @@ -44,10 +46,16 @@ { DetectedProblem::DetectedProblem() - :d(new DetectedProblemPrivate()) + : d(new DetectedProblemPrivate(i18n("Plugin"))) { } +DetectedProblem::DetectedProblem(const QString& pluginName) + : d(new DetectedProblemPrivate(pluginName)) +{ + setSource(Plugin); +} + DetectedProblem::~DetectedProblem() { clearDiagnostics(); @@ -65,22 +73,20 @@ QString DetectedProblem::sourceString() const { - QString s; - switch(d->m_source) { - case Unknown: s = i18n("Unknown"); break; - case Disk: s = i18n("Disk"); break; - case Preprocessor: s = i18n("Preprocessor"); break; - case Lexer: s = i18n("Lexer"); break; - case Parser: s = i18n("Parser"); break; - case DUChainBuilder: s = i18n("DuchainBuilder"); break; - case SemanticAnalysis: s = i18n("Semantic analysis"); break; - case ToDo: s = i18n("Todo"); break; - case Plugin: s = i18n("Plugin"); break; + case Unknown: return i18n("Unknown"); + case Disk: return i18n("Disk"); + case Preprocessor: return i18n("Preprocessor"); + case Lexer: return i18n("Lexer"); + case Parser: return i18n("Parser"); + case DUChainBuilder: return i18n("DuchainBuilder"); + case SemanticAnalysis: return i18n("Semantic analysis"); + case ToDo: return i18n("Todo"); + case Plugin: return d->m_pluginName; } - return s; + return {}; } DocumentRange DetectedProblem::finalLocation() const @@ -93,7 +99,6 @@ d->m_range = location; } - IProblem::FinalLocationMode DetectedProblem::finalLocationMode() const { return d->m_finalLocationMode; @@ -149,7 +154,6 @@ return s; } - QVector DetectedProblem::diagnostics() const { return d->m_diagnostics; diff --git a/shell/tests/test_detectedproblem.cpp b/shell/tests/test_detectedproblem.cpp --- a/shell/tests/test_detectedproblem.cpp +++ b/shell/tests/test_detectedproblem.cpp @@ -41,6 +41,7 @@ void testExplanation(); void testFinalLocation(); void testDiagnostics(); + void testPluginName(); private: IProblem::Ptr m_problem; @@ -193,6 +194,27 @@ QCOMPARE(m_problem->diagnostics().size(), 0); } +void TestDetectedProblem::testPluginName() +{ + DetectedProblem p1(QStringLiteral("Plugin1")); + DetectedProblem p2(QStringLiteral("Plugin2")); + DetectedProblem p3(QStringLiteral("")); + DetectedProblem p4; + + QCOMPARE(p1.source(), IProblem::Plugin); + QCOMPARE(p2.source(), IProblem::Plugin); + QCOMPARE(p3.source(), IProblem::Plugin); + QCOMPARE(p4.source(), IProblem::Unknown); + + QCOMPARE(p1.sourceString(), QStringLiteral("Plugin1")); + QCOMPARE(p2.sourceString(), QStringLiteral("Plugin2")); + QCOMPARE(p3.sourceString(), QStringLiteral("")); + QCOMPARE(p4.sourceString(), i18n("Unknown")); + + p4.setSource(IProblem::Plugin); + QCOMPARE(p4.source(), IProblem::Plugin); + QCOMPARE(p4.sourceString(), i18n("Plugin")); +} QTEST_MAIN(TestDetectedProblem)