src: refactored ErrorInfo to be used as standard error type outside of Storage

This commit is contained in:
Eberhard Graether
2016-10-21 14:48:20 +02:00
parent a5613715db
commit 0e8c0ee18a
20 changed files with 85 additions and 115 deletions
@@ -22,7 +22,7 @@ void ErrorController::handleMessage(MessageFinishedParsing* message)
auto errors = m_storageAccess->getAllErrors();
for (const StorageError& error : errors)
for (const ErrorInfo& error : errors)
{
getView()->addError(error);
}
@@ -30,7 +30,7 @@ void ErrorController::handleMessage(MessageFinishedParsing* message)
void ErrorController::handleMessage(MessageNewErrors* message)
{
for (const StorageError& error : message->errors)
for (const ErrorInfo& error : message->errors)
{
getView()->addError(error);
}
@@ -53,7 +53,7 @@ void ErrorController::handleMessage(MessageShowErrors* message)
auto errors = m_storageAccess->getAllErrors();
for (const StorageError& error : errors)
for (const ErrorInfo& error : errors)
{
getView()->addError(error);
}
+2 -2
View File
@@ -2,7 +2,7 @@
#define ERROR_VIEW_H
#include "component/view/View.h"
#include "data/StorageTypes.h"
#include "data/ErrorInfo.h"
class ErrorView
: public View
@@ -17,7 +17,7 @@ public:
virtual void clear() = 0;
virtual void addError(const StorageError& error) = 0;
virtual void addError(const ErrorInfo& error) = 0;
virtual void setErrorId(Id errorId) = 0;
};
+4 -17
View File
@@ -16,26 +16,13 @@ struct ErrorFilter
bool filter(const ErrorInfo& info) const
{
if (!error && !info.isFatal && info.isIndexed)
if (!error && !info.fatal && info.indexed)
return false;
if (!fatal && info.isFatal && info.isIndexed)
if (!fatal && info.fatal && info.indexed)
return false;
if (!unindexedError && !info.isFatal && !info.isIndexed)
if (!unindexedError && !info.fatal && !info.indexed)
return false;
if (!unindexedFatal && info.isFatal && !info.isIndexed)
return false;
return true;
}
bool filter(const StorageError& storageError) const
{
if (!error && !storageError.fatal && storageError.indexed)
return false;
if (!fatal && storageError.fatal && storageError.indexed)
return false;
if (!unindexedError && !storageError.fatal && !storageError.indexed)
return false;
if (!unindexedFatal && storageError.fatal && !storageError.indexed)
if (!unindexedFatal && info.fatal && !info.indexed)
return false;
return true;
}
+2 -26
View File
@@ -1,32 +1,8 @@
#ifndef ERROR_INFO_H
#define ERROR_INFO_H
#include "utility/file/FilePath.h"
#include "utility/types.h"
#include "data/StorageTypes.h"
struct ErrorInfo
{
ErrorInfo()
: id(0)
, isFatal(false)
, isIndexed(false)
{
}
ErrorInfo(const std::string& message, const FilePath& filePath, Id id, bool isFatal, bool isIndexed)
: message(message)
, filePath(filePath)
, id(id)
, isFatal(isFatal)
, isIndexed(isIndexed)
{
}
std::string message;
FilePath filePath;
Id id;
bool isFatal;
bool isIndexed;
};
typedef StorageError ErrorInfo;
#endif // ERROR_INFO_H
+4 -4
View File
@@ -160,16 +160,16 @@ void IntermediateStorage::addCommentLocation(Id fileNodeId, uint startLine, uint
));
}
void IntermediateStorage::addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol)
void IntermediateStorage::addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed)
{
m_errors.push_back(StorageError(
0,
message,
fatal,
indexed,
filePath,
startLine,
startCol
startCol,
fatal,
indexed
));
}
+1 -1
View File
@@ -24,7 +24,7 @@ public:
virtual void addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
virtual void addComponentAccess(Id nodeId , int type);
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
virtual void addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol);
virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed);
virtual void forEachFile(std::function<void(const Id /*id*/, const StorageFile& /*data*/)> callback) const;
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const;
+10 -11
View File
@@ -139,15 +139,15 @@ void PersistentStorage::addCommentLocation(Id fileNodeId, uint startLine, uint s
}
void PersistentStorage::addError(
const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol)
const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed)
{
m_sqliteStorage.addError(
message,
fatal,
indexed,
filePath,
startLine,
startCol
startCol,
fatal,
indexed
);
}
@@ -231,7 +231,7 @@ void PersistentStorage::finishInjection()
if (m_preInjectionErrorCount != errors.size())
{
MessageNewErrors(std::vector<StorageError>(errors.begin() + m_preInjectionErrorCount, errors.end())).dispatchImmediately();
MessageNewErrors(std::vector<ErrorInfo>(errors.begin() + m_preInjectionErrorCount, errors.end())).dispatchImmediately();
}
}
@@ -1035,13 +1035,13 @@ ErrorCountInfo PersistentStorage::getErrorCount() const
return ErrorCountInfo();
}
std::vector<StorageError> PersistentStorage::getErrors() const
std::vector<ErrorInfo> PersistentStorage::getErrors() const
{
LOG_ERROR("This should never be called.");
return std::vector<StorageError>();
return std::vector<ErrorInfo>();
}
std::vector<StorageError> PersistentStorage::getAllErrors() const
std::vector<ErrorInfo> PersistentStorage::getAllErrors() const
{
return m_sqliteStorage.getAllErrors();
}
@@ -1052,8 +1052,8 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getErrorTokenLocatio
std::shared_ptr<TokenLocationCollection> errorCollection = std::make_shared<TokenLocationCollection>();
std::vector<StorageError> storageErrors = m_sqliteStorage.getAllErrors();
for (const StorageError& error : storageErrors)
*errors = m_sqliteStorage.getAllErrors();
for (const ErrorInfo& error : *errors)
{
// Set first bit to 1 to avoid collisions
Id locationId = ~(~size_t(0) >> 1) + error.id;
@@ -1061,7 +1061,6 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getErrorTokenLocatio
errorCollection->addTokenLocation(
locationId, error.id, error.filePath, error.lineNumber, error.columnNumber, error.lineNumber, error.columnNumber
)->setType(LOCATION_ERROR);
errors->push_back(ErrorInfo(error.message, error.filePath, error.id, error.fatal, error.indexed));
}
return errorCollection;
+3 -3
View File
@@ -34,7 +34,7 @@ public:
virtual void addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
virtual void addComponentAccess(Id nodeId , int type);
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
virtual void addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol);
virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed);
virtual void forEachFile(std::function<void(const Id /*id*/, const StorageFile& /*data*/)> callback) const;
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const;
@@ -114,8 +114,8 @@ public:
virtual StorageStats getStorageStats() const;
virtual ErrorCountInfo getErrorCount() const;
virtual std::vector<StorageError> getErrors() const;
virtual std::vector<StorageError> getAllErrors() const;
virtual std::vector<ErrorInfo> getErrors() const;
virtual std::vector<ErrorInfo> getAllErrors() const;
virtual std::shared_ptr<TokenLocationCollection> getErrorTokenLocations(std::vector<ErrorInfo>* errors) const;
+4 -4
View File
@@ -215,7 +215,7 @@ Id SqliteStorage::addCommentLocation(Id fileNodeId, uint startLine, uint startCo
return m_database.lastRowId();
}
Id SqliteStorage::addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint lineNumber, uint columnNumber)
Id SqliteStorage::addError(const std::string& message, const FilePath& filePath, uint lineNumber, uint columnNumber, bool fatal, bool indexed)
{
std::string sanitizedMessage = utility::replace(message, "'", "''");
@@ -225,7 +225,7 @@ Id SqliteStorage::addError(const std::string& message, bool fatal, bool indexed,
"SELECT * FROM error WHERE "
"message == ? AND "
"fatal == " + std::to_string(fatal) + " AND "
"file_path == '" + filePath + "' AND "
"file_path == '" + filePath.str() + "' AND "
"line_number == " + std::to_string(lineNumber) + " AND "
"column_number == " + std::to_string(columnNumber) + ";"
).c_str());
@@ -242,7 +242,7 @@ Id SqliteStorage::addError(const std::string& message, bool fatal, bool indexed,
stmt = m_database.compileStatement((
"INSERT INTO error(message, fatal, indexed, file_path, line_number, column_number) "
"VALUES (?, " + std::to_string(fatal) + ", " + std::to_string(indexed) + ", '" + filePath +
"VALUES (?, " + std::to_string(fatal) + ", " + std::to_string(indexed) + ", '" + filePath.str() +
"', " + std::to_string(lineNumber) + ", " + std::to_string(columnNumber) + ");"
).c_str());
@@ -1084,7 +1084,7 @@ std::vector<StorageError> SqliteStorage::getAll<StorageError>(const std::string&
if (lineNumber != -1 && columnNumber != -1)
{
errors.push_back(StorageError(id, message, fatal, indexed, filePath, lineNumber, columnNumber));
errors.push_back(StorageError(id, message, filePath, lineNumber, columnNumber, fatal, indexed));
id++;
}
+1 -1
View File
@@ -47,7 +47,7 @@ public:
Id addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type);
Id addComponentAccess(Id nodeId, int type);
Id addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol);
Id addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint lineNumber, uint columnNumber);
Id addError(const std::string& message, const FilePath& filePath, uint lineNumber, uint columnNumber, bool fatal, bool indexed);
void removeElement(Id id);
void removeElements(const std::vector<Id>& ids);
+3 -3
View File
@@ -160,11 +160,11 @@ void Storage::inject(Storage* injected)
{
addError(
injectedData.message,
injectedData.fatal,
injectedData.indexed,
injectedData.filePath,
injectedData.lineNumber,
injectedData.columnNumber
injectedData.columnNumber,
injectedData.fatal,
injectedData.indexed
);
}
);
+1 -1
View File
@@ -22,7 +22,7 @@ public:
virtual void addSourceLocation(Id elementId, Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol, int type) = 0;
virtual void addComponentAccess(Id nodeId , int type) = 0;
virtual void addCommentLocation(Id fileNodeId, uint startLine, uint startCol, uint endLine, uint endCol) = 0;
virtual void addError(const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint startLine, uint startCol) = 0;
virtual void addError(const std::string& message, const FilePath& filePath, uint startLine, uint startCol, bool fatal, bool indexed) = 0;
virtual void forEachFile(std::function<void(const Id /*id*/, const StorageFile& /*data*/)> callback) const = 0;
virtual void forEachNode(std::function<void(const Id /*id*/, const StorageNode& /*data*/)> callback) const = 0;
+19 -9
View File
@@ -3,6 +3,7 @@
#include <string>
#include "utility/file/FilePath.h"
#include "utility/types.h"
#include "data/DefinitionType.h"
@@ -171,30 +172,39 @@ struct StorageError
StorageError()
: id(0)
, message("")
, fatal(0)
, indexed(0)
, filePath("")
, lineNumber(-1)
, columnNumber(-1)
, fatal(0)
, indexed(0)
{}
StorageError(Id id, const std::string& message, bool fatal, bool indexed, const std::string& filePath, uint lineNumber, uint columnNumber)
StorageError(
Id id,
const std::string& message,
const FilePath& filePath,
uint lineNumber,
uint columnNumber,
bool fatal,
bool indexed
)
: id(id)
, message(message)
, fatal(fatal)
, indexed(indexed)
, filePath(filePath)
, lineNumber(lineNumber)
, columnNumber(columnNumber)
, fatal(fatal)
, indexed(indexed)
{}
Id id;
std::string message;
bool fatal;
bool indexed;
std::string filePath;
FilePath filePath;
uint lineNumber;
uint columnNumber;
bool fatal;
bool indexed;
};
#endif // STORAGE_TYPES_H
+2 -3
View File
@@ -15,7 +15,6 @@
#include "data/ErrorCountInfo.h"
#include "data/ErrorInfo.h"
#include "data/StorageStats.h"
#include "data/StorageTypes.h"
class Graph;
class TextAccess;
@@ -70,8 +69,8 @@ public:
virtual StorageStats getStorageStats() const = 0;
virtual ErrorCountInfo getErrorCount() const = 0;
virtual std::vector<StorageError> getErrors() const = 0;
virtual std::vector<StorageError> getAllErrors() const = 0;
virtual std::vector<ErrorInfo> getErrors() const = 0;
virtual std::vector<ErrorInfo> getAllErrors() const = 0;
virtual std::shared_ptr<TokenLocationCollection> getErrorTokenLocations(std::vector<ErrorInfo>* errors) const = 0;
};
+9 -9
View File
@@ -274,8 +274,8 @@ ErrorCountInfo StorageAccessProxy::getErrorCount() const
{
ErrorCountInfo info;
std::vector<StorageError> storageErrors = getErrors();
for (const StorageError& error : storageErrors)
std::vector<ErrorInfo> errors = getErrors();
for (const ErrorInfo& error : errors)
{
info.total++;
@@ -288,14 +288,14 @@ ErrorCountInfo StorageAccessProxy::getErrorCount() const
return info;
}
std::vector<StorageError> StorageAccessProxy::getErrors() const
std::vector<ErrorInfo> StorageAccessProxy::getErrors() const
{
if (hasSubject())
{
std::vector<StorageError> errors = m_subject->getAllErrors();;
std::vector<StorageError> filteredErrors;
std::vector<ErrorInfo> errors = m_subject->getAllErrors();;
std::vector<ErrorInfo> filteredErrors;
for (const StorageError& error : errors)
for (const ErrorInfo& error : errors)
{
if (m_errorFilter.filter(error))
{
@@ -306,17 +306,17 @@ std::vector<StorageError> StorageAccessProxy::getErrors() const
return filteredErrors;
}
return std::vector<StorageError>();
return std::vector<ErrorInfo>();
}
std::vector<StorageError> StorageAccessProxy::getAllErrors() const
std::vector<ErrorInfo> StorageAccessProxy::getAllErrors() const
{
if (hasSubject())
{
return m_subject->getAllErrors();
}
return std::vector<StorageError>();
return std::vector<ErrorInfo>();
}
std::shared_ptr<TokenLocationCollection> StorageAccessProxy::getErrorTokenLocations(std::vector<ErrorInfo>* errors) const
+2 -3
View File
@@ -4,7 +4,6 @@
#include "data/access/StorageAccess.h"
#include "data/ErrorFilter.h"
#include "data/StorageTypes.h"
#include "utility/messaging/MessageListener.h"
#include "utility/messaging/type/MessageErrorFilterChanged.h"
@@ -65,8 +64,8 @@ public:
virtual StorageStats getStorageStats() const;
virtual ErrorCountInfo getErrorCount() const;
virtual std::vector<StorageError> getErrors() const;
virtual std::vector<StorageError> getAllErrors() const;
virtual std::vector<ErrorInfo> getErrors() const;
virtual std::vector<ErrorInfo> getAllErrors() const;
virtual std::shared_ptr<TokenLocationCollection> getErrorTokenLocations(std::vector<ErrorInfo>* errors) const;
+1 -1
View File
@@ -634,7 +634,7 @@ void ParserClientImpl::addError(const std::string& message, bool fatal, bool ind
return;
}
m_storage->addError(message, fatal, indexed, location.filePath.str(), location.startLineNumber, location.startColumnNumber);
m_storage->addError(message, location.filePath, location.startLineNumber, location.startColumnNumber, fatal, indexed);
}
void ParserClientImpl::log(std::string type, std::string str, const ParseLocation& location) const
+1 -1
View File
@@ -230,7 +230,7 @@ size_t QtCodeNavigator::getFatalErrorCountForFile(const FilePath& filePath) cons
for (const std::pair<Id, ErrorInfo>& p : m_errorInfos)
{
const ErrorInfo& error = p.second;
if (error.filePath == filePath && error.isFatal)
if (error.filePath == filePath && error.fatal)
{
fatalErrorCount++;
}
+7 -7
View File
@@ -119,7 +119,7 @@ void QtErrorView::clear()
m_clearFunctor();
}
void QtErrorView::addError(const StorageError& error)
void QtErrorView::addError(const ErrorInfo& error)
{
m_addErrorFunctor(error);
}
@@ -133,7 +133,7 @@ void QtErrorView::doRefreshView()
{
m_model->removeRows(0, m_model->rowCount());
for (StorageError error : m_errors)
for (ErrorInfo error : m_errors)
{
addErrorToTable(error);
}
@@ -149,7 +149,7 @@ void QtErrorView::doClear()
m_errors.clear();
}
void QtErrorView::doAddError(const StorageError& error)
void QtErrorView::doAddError(const ErrorInfo& error)
{
m_errors.push_back(error);
@@ -189,7 +189,7 @@ void QtErrorView::setStyleSheet() const
);
}
void QtErrorView::addErrorToTable(const StorageError& error)
void QtErrorView::addErrorToTable(const ErrorInfo& error)
{
if (!isShownError(error))
{
@@ -208,8 +208,8 @@ void QtErrorView::addErrorToTable(const StorageError& error)
m_model->setItem(rowNumber, COLUMN::MESSAGE, new QStandardItem(error.message.c_str()));
std::string errorPngPath = ResourcePaths::getGuiPath() + "/indexing_dialog/error.png";
m_model->item(rowNumber, COLUMN::MESSAGE)->setIcon(QIcon(QString(errorPngPath.c_str())));
m_model->setItem(rowNumber, COLUMN::FILE, new QStandardItem(error.filePath.c_str()));
m_model->item(rowNumber, COLUMN::FILE)->setToolTip(error.filePath.c_str());
m_model->setItem(rowNumber, COLUMN::FILE, new QStandardItem(error.filePath.str().c_str()));
m_model->item(rowNumber, COLUMN::FILE)->setToolTip(error.filePath.str().c_str());
m_model->setItem(rowNumber, COLUMN::LINE, new QStandardItem(QString::number(error.lineNumber)));
m_model->setItem(rowNumber, COLUMN::INDEXED, new QStandardItem(error.indexed ? "yes" : "no"));
m_model->setItem(rowNumber, COLUMN::ID, new QStandardItem(QString::number(error.id)));
@@ -242,7 +242,7 @@ QCheckBox* QtErrorView::createFilterCheckbox(const QString& name, bool checked,
return checkbox;
}
bool QtErrorView::isShownError(const StorageError& error)
bool QtErrorView::isShownError(const ErrorInfo& error)
{
if (!error.fatal && error.indexed && m_showErrors->checkState() == Qt::Checked)
{
+6 -6
View File
@@ -29,7 +29,7 @@ public:
// ErrorView implementation
virtual void clear();
virtual void addError(const StorageError& error);
virtual void addError(const ErrorInfo& error);
virtual void setErrorId(Id errorId);
private:
@@ -44,19 +44,19 @@ private:
void doRefreshView();
void doClear();
void doAddError(const StorageError& error);
void doAddError(const ErrorInfo& error);
void doSetErrorId(Id errorId);
void setStyleSheet() const;
void addErrorToTable(const StorageError& error);
void addErrorToTable(const ErrorInfo& error);
QCheckBox* createFilterCheckbox(const QString& name, bool checked, QBoxLayout* layout);
bool isShownError(const StorageError& error);
bool isShownError(const ErrorInfo& error);
QtThreadedFunctor<void> m_clearFunctor;
QtThreadedFunctor<void> m_refreshFunctor;
QtThreadedFunctor<const StorageError&> m_addErrorFunctor;
QtThreadedFunctor<const ErrorInfo&> m_addErrorFunctor;
QtThreadedFunctor<Id> m_setErrorIdFunctor;
QCheckBox* m_showErrors;
@@ -67,7 +67,7 @@ private:
QStandardItemModel* m_model;
QtTable* m_table;
std::vector<StorageError> m_errors;
std::vector<ErrorInfo> m_errors;
QPalette* m_palette;
bool m_ignoreNextSelection;