1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
|
/*
* Copyright 2015 Laszlo Kis-Adam <laszlo.kis-adam@kdemail.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <shell/problem.h>
#include <interfaces/iassistant.h>
#include <language/editor/documentrange.h>
#include <KLocalizedString>
namespace KDevelop
{
class DetectedProblemPrivate
{
public:
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;
const QString m_pluginName;
KDevelop::IProblem::Severity m_severity;
KDevelop::IProblem::Source m_source;
KDevelop::DocumentRange m_range;
QVector<KDevelop::IProblem::Ptr> m_diagnostics;
KDevelop::IProblem::FinalLocationMode m_finalLocationMode;
};
DetectedProblem::DetectedProblem()
: d_ptr(new DetectedProblemPrivate(i18n("Plugin")))
{
}
DetectedProblem::DetectedProblem(const QString& pluginName)
: d_ptr(new DetectedProblemPrivate(pluginName))
{
setSource(Plugin);
}
DetectedProblem::~DetectedProblem()
{
clearDiagnostics();
}
IProblem::Source DetectedProblem::source() const
{
Q_D(const DetectedProblem);
return d->m_source;
}
void DetectedProblem::setSource(Source source)
{
Q_D(DetectedProblem);
d->m_source = source;
}
QString DetectedProblem::sourceString() const
{
Q_D(const DetectedProblem);
switch(d->m_source)
{
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 {};
}
DocumentRange DetectedProblem::finalLocation() const
{
Q_D(const DetectedProblem);
return d->m_range;
}
void DetectedProblem::setFinalLocation(const DocumentRange &location)
{
Q_D(DetectedProblem);
d->m_range = location;
}
IProblem::FinalLocationMode DetectedProblem::finalLocationMode() const
{
Q_D(const DetectedProblem);
return d->m_finalLocationMode;
}
void DetectedProblem::setFinalLocationMode(IProblem::FinalLocationMode mode)
{
Q_D(DetectedProblem);
d->m_finalLocationMode = mode;
}
QString DetectedProblem::description() const
{
Q_D(const DetectedProblem);
return d->m_description;
}
void DetectedProblem::setDescription(const QString &description)
{
Q_D(DetectedProblem);
d->m_description = description;
}
QString DetectedProblem::explanation() const
{
Q_D(const DetectedProblem);
return d->m_explanation;
}
void DetectedProblem::setExplanation(const QString &explanation)
{
Q_D(DetectedProblem);
d->m_explanation = explanation;
}
IProblem::Severity DetectedProblem::severity() const
{
Q_D(const DetectedProblem);
return d->m_severity;
}
void DetectedProblem::setSeverity(Severity severity)
{
Q_D(DetectedProblem);
d->m_severity = severity;
}
QString DetectedProblem::severityString() const
{
Q_D(const DetectedProblem);
QString s;
switch(d->m_severity)
{
case Hint: s = i18nc("@item problem severity", "Hint"); break;
case Warning: s = i18nc("@item problem severity", "Warning"); break;
case Error: s = i18nc("@item problem severity", "Error"); break;
default: break;
}
return s;
}
QVector<IProblem::Ptr> DetectedProblem::diagnostics() const
{
Q_D(const DetectedProblem);
return d->m_diagnostics;
}
void DetectedProblem::setDiagnostics(const QVector<Ptr> &diagnostics)
{
clearDiagnostics();
for (const Ptr& diagnostic : diagnostics) {
addDiagnostic(diagnostic);
}
}
void DetectedProblem::addDiagnostic(const Ptr &diagnostic)
{
Q_D(DetectedProblem);
auto *dp = dynamic_cast<DetectedProblem*>(diagnostic.data());
Q_ASSERT(dp);
d->m_diagnostics.push_back(diagnostic);
}
void DetectedProblem::clearDiagnostics()
{
Q_D(DetectedProblem);
d->m_diagnostics.clear();
}
QExplicitlySharedDataPointer<IAssistant> DetectedProblem::solutionAssistant() const
{
return {};
}
}
|