File indexing completed on 2024-04-28 04:36:30

0001 /*
0002     SPDX-FileCopyrightText: 2015 Laszlo Kis-Adam
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef IPROBLEM_H
0008 #define IPROBLEM_H
0009 
0010 #include <QExplicitlySharedDataPointer>
0011 #include <QVector>
0012 #include <QMetaType>
0013 
0014 #include "interfacesexport.h"
0015 
0016 class QIcon;
0017 
0018 namespace KDevelop
0019 {
0020 class IAssistant;
0021 class DocumentRange;
0022 
0023 /// Interface for the Problem classes
0024 class KDEVPLATFORMINTERFACES_EXPORT IProblem : public QSharedData
0025 {
0026 public:
0027     using Ptr = QExplicitlySharedDataPointer<IProblem>;
0028 
0029     /// The source of the problem. That is which tool / which part found this problem.
0030     enum Source {
0031         Unknown,
0032         Disk,
0033         Preprocessor,
0034         Lexer,
0035         Parser,
0036         DUChainBuilder,
0037         SemanticAnalysis,
0038         ToDo,
0039         Plugin             /// The source is a problem checker plugin
0040     };
0041 
0042     /// Severity of the problem. That is, how serious is the found problem.
0043     enum Severity {
0044         NoSeverity = 0,
0045         Error = 1,
0046         Warning = 2,
0047         Hint = 4
0048     };
0049     Q_DECLARE_FLAGS(Severities, Severity)
0050 
0051     /// Final location mode of the problem. Used during highlighting.
0052     enum FinalLocationMode
0053     {
0054         /// Location range used "As Is"
0055         Range = 0,
0056 
0057         /// Location range used to highlight whole line.
0058         ///
0059         /// Mode applied only if location range is wholly contained within one line
0060         WholeLine,
0061 
0062         /// Location range used to highlight only trimmed part of the line.
0063         /// For example for the line: "   int x = 0;  \t"
0064         /// only "int x = 0;" will be highlighted.
0065         ///
0066         /// Mode applied only if location range is wholly contained within one line
0067         TrimmedLine
0068     };
0069 
0070     static QIcon iconForSeverity(IProblem::Severity severity);
0071 
0072     IProblem();
0073     virtual ~IProblem();
0074 
0075     /// Returns the source of the problem
0076     virtual Source source() const = 0;
0077 
0078     /// Sets the source of the problem
0079     virtual void setSource(Source source) = 0;
0080 
0081     /// Returns a string containing the source of the problem
0082     virtual QString sourceString() const = 0;
0083 
0084     /// Returns the location of the problem (path, line, column)
0085     virtual KDevelop::DocumentRange finalLocation() const = 0;
0086 
0087     /// Sets the location of the problem (path, line, column)
0088     virtual void setFinalLocation(const KDevelop::DocumentRange& location) = 0;
0089 
0090     /// Returns the final location mode of the problem
0091     virtual FinalLocationMode finalLocationMode() const = 0;
0092 
0093     /// Sets the final location mode of the problem
0094     virtual void setFinalLocationMode(FinalLocationMode mode) = 0;
0095 
0096     /// Returns the short description of the problem.
0097     virtual QString description() const = 0;
0098 
0099     /// Sets the short description of the problem
0100     virtual void setDescription(const QString& description) = 0;
0101 
0102     /// Returns the detailed explanation of the problem.
0103     virtual QString explanation() const = 0;
0104 
0105     /// Sets the detailed explanation of the problem
0106     virtual void setExplanation(const QString& explanation) = 0;
0107 
0108     /// Returns the severity of the problem
0109     virtual Severity severity() const = 0;
0110 
0111     /// Sets the severity of the problem
0112     virtual void setSeverity(Severity severity) = 0;
0113 
0114     /// Returns a string containing the severity of the problem
0115     virtual QString severityString() const = 0;
0116 
0117     /// Returns the diagnostics of the problem.
0118     virtual QVector<Ptr> diagnostics() const = 0;
0119 
0120     /// Sets the diagnostics of the problem
0121     virtual void setDiagnostics(const QVector<Ptr> &diagnostics) = 0;
0122 
0123     /// Adds a diagnostic line to the problem
0124     virtual void addDiagnostic(const Ptr &diagnostic) = 0;
0125 
0126     /// Clears all diagnostics
0127     virtual void clearDiagnostics() = 0;
0128 
0129     /// Returns a solution assistant for the problem, if applicable that is.
0130     virtual QExplicitlySharedDataPointer<KDevelop::IAssistant> solutionAssistant() const = 0;
0131 };
0132 
0133 Q_DECLARE_OPERATORS_FOR_FLAGS(IProblem::Severities)
0134 
0135 }
0136 
0137 Q_DECLARE_METATYPE(KDevelop::IProblem::Ptr)
0138 
0139 #endif