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 #include <shell/problem.h> 0008 0009 #include <interfaces/iassistant.h> 0010 #include <language/editor/documentrange.h> 0011 0012 #include <KLocalizedString> 0013 0014 namespace KDevelop 0015 { 0016 0017 class DetectedProblemPrivate 0018 { 0019 public: 0020 DetectedProblemPrivate(const QString& pluginName) 0021 : m_pluginName(pluginName) 0022 , m_severity(KDevelop::IProblem::Error) 0023 , m_source(KDevelop::IProblem::Unknown) 0024 , m_finalLocationMode(KDevelop::IProblem::Range) 0025 { 0026 } 0027 0028 QString m_description; 0029 QString m_explanation; 0030 const QString m_pluginName; 0031 KDevelop::IProblem::Severity m_severity; 0032 KDevelop::IProblem::Source m_source; 0033 KDevelop::DocumentRange m_range; 0034 QVector<KDevelop::IProblem::Ptr> m_diagnostics; 0035 KDevelop::IProblem::FinalLocationMode m_finalLocationMode; 0036 }; 0037 0038 0039 DetectedProblem::DetectedProblem() 0040 : d_ptr(new DetectedProblemPrivate(i18n("Plugin"))) 0041 { 0042 } 0043 0044 DetectedProblem::DetectedProblem(const QString& pluginName) 0045 : d_ptr(new DetectedProblemPrivate(pluginName)) 0046 { 0047 setSource(Plugin); 0048 } 0049 0050 DetectedProblem::~DetectedProblem() 0051 { 0052 clearDiagnostics(); 0053 } 0054 0055 IProblem::Source DetectedProblem::source() const 0056 { 0057 Q_D(const DetectedProblem); 0058 0059 return d->m_source; 0060 } 0061 0062 void DetectedProblem::setSource(Source source) 0063 { 0064 Q_D(DetectedProblem); 0065 0066 d->m_source = source; 0067 } 0068 0069 QString DetectedProblem::sourceString() const 0070 { 0071 Q_D(const DetectedProblem); 0072 0073 switch(d->m_source) 0074 { 0075 case Unknown: return i18n("Unknown"); 0076 case Disk: return i18n("Disk"); 0077 case Preprocessor: return i18n("Preprocessor"); 0078 case Lexer: return i18n("Lexer"); 0079 case Parser: return i18n("Parser"); 0080 case DUChainBuilder: return i18n("DuchainBuilder"); 0081 case SemanticAnalysis: return i18n("Semantic analysis"); 0082 case ToDo: return i18n("Todo"); 0083 case Plugin: return d->m_pluginName; 0084 } 0085 0086 return {}; 0087 } 0088 0089 DocumentRange DetectedProblem::finalLocation() const 0090 { 0091 Q_D(const DetectedProblem); 0092 0093 return d->m_range; 0094 } 0095 0096 void DetectedProblem::setFinalLocation(const DocumentRange &location) 0097 { 0098 Q_D(DetectedProblem); 0099 0100 d->m_range = location; 0101 } 0102 0103 IProblem::FinalLocationMode DetectedProblem::finalLocationMode() const 0104 { 0105 Q_D(const DetectedProblem); 0106 0107 return d->m_finalLocationMode; 0108 } 0109 0110 void DetectedProblem::setFinalLocationMode(IProblem::FinalLocationMode mode) 0111 { 0112 Q_D(DetectedProblem); 0113 0114 d->m_finalLocationMode = mode; 0115 } 0116 0117 QString DetectedProblem::description() const 0118 { 0119 Q_D(const DetectedProblem); 0120 0121 return d->m_description; 0122 } 0123 0124 void DetectedProblem::setDescription(const QString &description) 0125 { 0126 Q_D(DetectedProblem); 0127 0128 d->m_description = description; 0129 } 0130 0131 QString DetectedProblem::explanation() const 0132 { 0133 Q_D(const DetectedProblem); 0134 0135 return d->m_explanation; 0136 } 0137 0138 void DetectedProblem::setExplanation(const QString &explanation) 0139 { 0140 Q_D(DetectedProblem); 0141 0142 d->m_explanation = explanation; 0143 } 0144 0145 IProblem::Severity DetectedProblem::severity() const 0146 { 0147 Q_D(const DetectedProblem); 0148 0149 return d->m_severity; 0150 } 0151 0152 void DetectedProblem::setSeverity(Severity severity) 0153 { 0154 Q_D(DetectedProblem); 0155 0156 d->m_severity = severity; 0157 } 0158 0159 QString DetectedProblem::severityString() const 0160 { 0161 Q_D(const DetectedProblem); 0162 0163 QString s; 0164 0165 switch(d->m_severity) 0166 { 0167 case Hint: s = i18nc("@item problem severity", "Hint"); break; 0168 case Warning: s = i18nc("@item problem severity", "Warning"); break; 0169 case Error: s = i18nc("@item problem severity", "Error"); break; 0170 default: break; 0171 } 0172 0173 return s; 0174 } 0175 0176 QVector<IProblem::Ptr> DetectedProblem::diagnostics() const 0177 { 0178 Q_D(const DetectedProblem); 0179 0180 return d->m_diagnostics; 0181 } 0182 0183 void DetectedProblem::setDiagnostics(const QVector<Ptr> &diagnostics) 0184 { 0185 clearDiagnostics(); 0186 0187 for (const Ptr& diagnostic : diagnostics) { 0188 addDiagnostic(diagnostic); 0189 } 0190 } 0191 0192 void DetectedProblem::addDiagnostic(const Ptr &diagnostic) 0193 { 0194 Q_D(DetectedProblem); 0195 0196 auto *dp = dynamic_cast<DetectedProblem*>(diagnostic.data()); 0197 0198 Q_ASSERT(dp); 0199 0200 d->m_diagnostics.push_back(diagnostic); 0201 } 0202 0203 void DetectedProblem::clearDiagnostics() 0204 { 0205 Q_D(DetectedProblem); 0206 0207 d->m_diagnostics.clear(); 0208 } 0209 0210 0211 QExplicitlySharedDataPointer<IAssistant> DetectedProblem::solutionAssistant() const 0212 { 0213 return {}; 0214 } 0215 0216 } 0217