Vuo 2.4.2
Loading...
Searching...
No Matches
VuoCompilerIssue.cc
Go to the documentation of this file.
1
10#include <sstream>
11#include "VuoCompilerIssue.hh"
12#include "VuoModule.hh"
13#include "VuoStringUtilities.hh"
14
18static string getLineBreak(bool htmlFormatted, int count = 1)
19{
20 string lineBreak = (htmlFormatted ? "<br>" : "\n");
21 string ret;
22 for (int i = 0; i < count; ++i)
23 ret += lineBreak;
24 return ret;
25}
26
31{
32 issueType = VuoCompilerIssue::Error;
33 module = NULL;
34}
35
54VuoCompilerIssue::VuoCompilerIssue(IssueType issueType, const string &action, const string &filePath, const string &summary, const string &details)
55{
56 this->issueType = issueType;
57 this->action = action;
58 this->filePath = filePath;
59 this->summary = summary;
60 this->details = details;
61 module = NULL;
62}
63
67string VuoCompilerIssue::getIssueTypeString(void)
68{
69 string issueTypeStr;
70 switch (issueType)
71 {
72 case Error:
73 issueTypeStr = "Error";
74 break;
75 case Warning:
76 issueTypeStr = "Warning";
77 break;
78 }
79
80 return issueTypeStr;
81}
82
87string VuoCompilerIssue::fillInPlaceholders(const string &s, bool htmlFormatted) const
88{
89 string ret = s;
90
91 {
92 string moduleKeyFormatted = moduleKey;
93 if (htmlFormatted)
94 moduleKeyFormatted = "<code>" + moduleKeyFormatted + "</code>";
95 VuoStringUtilities::replaceAll(ret, "%moduleKey", moduleKeyFormatted);
96 }
97
98 if (module)
99 {
100 string moduleTitleFormatted = module->getDefaultTitle();
101 if (htmlFormatted)
102 moduleTitleFormatted = "<code>" + moduleTitleFormatted + "</code>";
103 string moduleKeyFormatted = module->getModuleKey();
104 if (htmlFormatted)
105 moduleKeyFormatted = "<code>" + moduleKeyFormatted + "</code>";
106 VuoStringUtilities::replaceAll(ret, "%module", moduleTitleFormatted + " (" + moduleKeyFormatted + ")");
107 }
108
109 {
110 string link = (htmlFormatted ?
111 "<a href=\"" + linkUrl + "\">" + linkText + "</a>" :
112 linkText + " (" + linkUrl + ")");
113 VuoStringUtilities::replaceAll(ret, "%link", link);
114 }
115
116 return ret;
117}
118
123{
124 return issueType;
125}
126
131{
132 return summary;
133}
134
140string VuoCompilerIssue::getDetails(bool htmlFormatted) const
141{
142 return fillInPlaceholders(details, htmlFormatted);
143}
144
150string VuoCompilerIssue::getShortDescription(bool htmlFormatted) const
151{
152 string description;
153
154 if (! summary.empty())
155 description += summary + " — ";
156
157 description += getDetails(htmlFormatted);
158
159 return description;
160}
161
167string VuoCompilerIssue::getLongDescription(bool htmlFormatted)
168{
169 string description = getIssueTypeString() + " " + action;
170
171 if (! filePath.empty())
172 {
173 string filePathFormatted = filePath;
174 if (htmlFormatted)
175 filePathFormatted = "<code>" + filePathFormatted + "</code>";
176
177 description += " " + filePathFormatted;
178 }
179
180 description += ":" + getLineBreak(htmlFormatted);
181
182 if (! summary.empty())
183 description += summary + " — ";
184
185 description += getDetails(htmlFormatted);
186
187 return description;
188}
189
195void VuoCompilerIssue::setHint(const string &hint)
196{
197 this->hint = hint;
198}
199
205string VuoCompilerIssue::getHint(bool htmlFormatted)
206{
207 return fillInPlaceholders(hint, htmlFormatted);
208}
209
213void VuoCompilerIssue::setHelpPath(const string &path)
214{
215 this->helpPath = path;
216}
217
222{
223 return helpPath;
224}
225
229void VuoCompilerIssue::setFilePath(const string &filePath)
230{
231 this->filePath = filePath;
232}
233
238{
239 return filePath;
240}
241
246{
247 this->lineNumber = lineNumber;
248}
249
254{
255 return lineNumber;
256}
257
261void VuoCompilerIssue::setModuleKey(const string &moduleKey)
262{
263 this->moduleKey = moduleKey;
264}
265
269void VuoCompilerIssue::setLink(const string &url, const string &text)
270{
271 linkUrl = url;
272 linkText = text;
273}
274
279{
280 this->module = module;
281}
282
287{
288 nodes.clear();
289 nodes.insert(node);
290}
291
295void VuoCompilerIssue::setNodes(const set<VuoNode *> &nodes)
296{
297 this->nodes = nodes;
298}
299
303set<VuoNode *> VuoCompilerIssue::getNodes(void)
304{
305 return nodes;
306}
307
311void VuoCompilerIssue::setCables(const set<VuoCable *> &cables)
312{
313 this->cables = cables;
314}
315
319set<VuoCable *> VuoCompilerIssue::getCables(void)
320{
321 return cables;
322}
323
328{
329 ostringstream s;
330
331 s << getLongDescription(false);
332
333 vector<string> nodeStrings;
334 for (set<VuoNode *>::iterator i = nodes.begin(); i != nodes.end(); ++i)
335 {
336 ostringstream ss;
337 ss << *i;
338 nodeStrings.push_back(ss.str());
339 }
340 sort(nodeStrings.begin(), nodeStrings.end());
341 s << "[" << VuoStringUtilities::join(nodeStrings, ',') << "]";
342
343 vector<string> cableStrings;
344 for (set<VuoCable *>::iterator i = cables.begin(); i != cables.end(); ++i)
345 {
346 ostringstream ss;
347 ss << *i;
348 cableStrings.push_back(ss.str());
349 }
350 s << "[" << VuoStringUtilities::join(cableStrings, ',') << "]";
351
352 return VuoStringUtilities::hash(s.str());
353}
354
355
360{
361}
362
367{
368 issues.push_back(issue);
369}
370
377{
378 vector<string> uniqueDescriptions;
379 for (vector<VuoCompilerIssue>::iterator i = issues.begin(); i != issues.end(); ++i)
380 {
381 string description = (*i).getShortDescription(htmlFormatted);
382 if (find(uniqueDescriptions.begin(), uniqueDescriptions.end(), description) == uniqueDescriptions.end())
383 uniqueDescriptions.push_back(description);
384 }
385
386 return VuoStringUtilities::join(uniqueDescriptions, getLineBreak(htmlFormatted, 2));
387}
388
395{
396 vector<string> uniqueDescriptions;
397 for (vector<VuoCompilerIssue>::iterator i = issues.begin(); i != issues.end(); ++i)
398 {
399 string description = (*i).getLongDescription(htmlFormatted);
400 if (find(uniqueDescriptions.begin(), uniqueDescriptions.end(), description) == uniqueDescriptions.end())
401 uniqueDescriptions.push_back(description);
402 }
403
404 return VuoStringUtilities::join(uniqueDescriptions, getLineBreak(htmlFormatted, 2));
405}
406
412string VuoCompilerIssues::getHint(bool htmlFormatted)
413{
414 vector<string> uniqueHints;
415 for (vector<VuoCompilerIssue>::iterator i = issues.begin(); i != issues.end(); ++i)
416 {
417 string hint = (*i).getHint(htmlFormatted);
418 if (! hint.empty() && find(uniqueHints.begin(), uniqueHints.end(), hint) == uniqueHints.end())
419 uniqueHints.push_back(hint);
420 }
421
422 return VuoStringUtilities::join(uniqueHints, getLineBreak(htmlFormatted, 2));
423}
424
428void VuoCompilerIssues::setFilePathIfEmpty(const string &filePath)
429{
430 for (vector<VuoCompilerIssue>::iterator i = issues.begin(); i != issues.end(); ++i)
431 if ((*i).getFilePath().empty())
432 (*i).setFilePath(filePath);
433}
434
438void VuoCompilerIssues::setFilePath(const string &filePath)
439{
440 for (vector<VuoCompilerIssue>::iterator i = issues.begin(); i != issues.end(); ++i)
441 (*i).setFilePath(filePath);
442}
447{
448 issues.push_back(issue);
449}
450
455{
456 issues.insert(issues.begin(), otherIssues->issues.begin(), otherIssues->issues.end());
457}
458
463{
464 return issues.empty();
465}
466
470vector<VuoCompilerIssue> VuoCompilerIssues::getList(void)
471{
472 return issues;
473}
474
479{
480 VuoCompilerIssues *errors = new VuoCompilerIssues();
481 for (vector<VuoCompilerIssue>::iterator i = issues.begin(); i != issues.end(); ++i)
482 if ((*i).getIssueType() == VuoCompilerIssue::Error)
483 errors->append(*i);
484
485 return errors;
486}