File indexing completed on 2024-04-28 04:37:21
0001 /* 0002 SPDX-FileCopyrightText: 2015 Laszlo Kis-Adam <laszlo.kis-adam@kdemail.net> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #ifndef PROBLEM_H 0008 #define PROBLEM_H 0009 0010 #include <interfaces/iproblem.h> 0011 0012 #include <shell/shellexport.h> 0013 0014 #include <QScopedPointer> 0015 0016 namespace KDevelop 0017 { 0018 class DetectedProblemPrivate; 0019 0020 /** 0021 * @brief Represents a problem as one unit with the IProblem interface so can be used with anything that can handle IProblem. 0022 * 0023 * You should have it wrapped in an IProblem::Ptr which is a shared pointer for it. 0024 * It is basically a mirror of DUChain's Problem class. 0025 * However that class is strongly coupled with DUChain's internals due to DUChain's needs (special serialization). 0026 * 0027 * Usage example: 0028 * @code 0029 * IProblem::Ptr problem(new DetectedProblem()); 0030 * problem->setSource(IProblem::Plugin); 0031 * problem->setSeverity(IProblem::Warning); 0032 * problem->setDescription(QStringLiteral("Warning message")); 0033 * problem->setExplanation(QStringLiteral("Warning explanation")); 0034 * 0035 * DocumentRange range; 0036 * range.document = IndexedString("/path/to/source/file"); 0037 * range.setBothLines(1337); 0038 * range.setBothColumns(12); 0039 * problem->setFinalLocation(range); 0040 * @endcode 0041 * 0042 */ 0043 class KDEVPLATFORMSHELL_EXPORT DetectedProblem : public IProblem 0044 { 0045 public: 0046 /// Creates new empty DetectedProblem with default properties: 0047 /// severity - KDevelop::IProblem::Error; 0048 /// source - KDevelop::IProblem::Unknown; 0049 /// finalLocationMode - KDevelop::IProblem::Range. 0050 DetectedProblem(); 0051 0052 /// Creates new DetectedProblem, produced by some plugin, for example by analyzer plugins 0053 /// like cppcheck/clang-tydy/valgrind/etc. 0054 /// Default values of problem properties are: 0055 /// severity - KDevelop::IProblem::Error; 0056 /// source - KDevelop::IProblem::Plugin; 0057 /// sourceString - passed pluginName parameter; 0058 /// finalLocationMode - KDevelop::IProblem::Range. 0059 explicit DetectedProblem(const QString& pluginName); 0060 0061 ~DetectedProblem() override; 0062 0063 Source source() const override; 0064 void setSource(Source source) override; 0065 QString sourceString() const override; 0066 0067 DocumentRange finalLocation() const override; 0068 void setFinalLocation(const DocumentRange& location) override; 0069 0070 FinalLocationMode finalLocationMode() const override; 0071 void setFinalLocationMode(FinalLocationMode mode) override; 0072 0073 QString description() const override; 0074 void setDescription(const QString& description) override; 0075 0076 QString explanation() const override; 0077 void setExplanation(const QString& explanation) override; 0078 0079 Severity severity() const override; 0080 void setSeverity(Severity severity) override; 0081 QString severityString() const override; 0082 0083 QVector<Ptr> diagnostics() const override; 0084 void setDiagnostics(const QVector<Ptr> &diagnostics) override; 0085 void addDiagnostic(const Ptr &diagnostic) override; 0086 void clearDiagnostics() override; 0087 0088 QExplicitlySharedDataPointer<IAssistant> solutionAssistant() const override; 0089 0090 private: 0091 const QScopedPointer<class DetectedProblemPrivate> d_ptr; 0092 Q_DECLARE_PRIVATE(DetectedProblem) 0093 }; 0094 0095 } 0096 0097 #endif 0098