forked from qt-creator/qt-creator
Clang: Clean up exceptions
* Extract common stuff into the base class ClangException * Remove unused exceptions TranslationUnitParseErrorException and TranslationUnitReparseErrorException * Do not send error messages to the Qt Creator side. The messages were only generated when the backend crashed and while it was not yet fully re-initialized (e.g. do code completion right after crash where the document was not yet registered at the backend). Change-Id: I91d98d5ef681ad487f7a2fd66f78fa7cd1e958df Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -27,197 +27,51 @@
|
||||
|
||||
namespace ClangBackEnd {
|
||||
|
||||
const char *ClangBaseException::what() const Q_DECL_NOEXCEPT
|
||||
{
|
||||
return m_info.constData();
|
||||
}
|
||||
|
||||
ProjectPartDoNotExistException::ProjectPartDoNotExistException(
|
||||
const Utf8StringVector &projectPartIds)
|
||||
: projectPartIds_(projectPartIds)
|
||||
{
|
||||
}
|
||||
|
||||
const Utf8StringVector &ProjectPartDoNotExistException::projectPartIds() const
|
||||
{
|
||||
return projectPartIds_;
|
||||
}
|
||||
|
||||
const char *ProjectPartDoNotExistException::what() const Q_DECL_NOEXCEPT
|
||||
{
|
||||
if (what_.isEmpty())
|
||||
what_ += Utf8StringLiteral("ProjectPart files ")
|
||||
+ projectPartIds().join(Utf8StringLiteral(", "))
|
||||
+ Utf8StringLiteral(" does not exist!");
|
||||
|
||||
return what_.constData();
|
||||
}
|
||||
|
||||
DocumentAlreadyExistsException::DocumentAlreadyExistsException(
|
||||
const FileContainer &fileContainer)
|
||||
: fileContainer_(fileContainer)
|
||||
{
|
||||
m_info += Utf8StringLiteral("ProjectPart files ")
|
||||
+ projectPartIds.join(Utf8StringLiteral(", "))
|
||||
+ Utf8StringLiteral(" does not exist!");
|
||||
}
|
||||
|
||||
DocumentAlreadyExistsException::DocumentAlreadyExistsException(
|
||||
const Utf8String &filePath,
|
||||
const Utf8String &projectPartId)
|
||||
: fileContainer_(filePath, projectPartId)
|
||||
{
|
||||
m_info += Utf8StringLiteral("Document '")
|
||||
+ filePath
|
||||
+ Utf8StringLiteral("' with the project part id '")
|
||||
+ projectPartId
|
||||
+ Utf8StringLiteral("' already exists!");
|
||||
}
|
||||
|
||||
const FileContainer &DocumentAlreadyExistsException::fileContainer() const
|
||||
DocumentDoesNotExistException::DocumentDoesNotExistException(const Utf8String &filePath,
|
||||
const Utf8String &projectPartId)
|
||||
{
|
||||
return fileContainer_;
|
||||
}
|
||||
|
||||
const char *DocumentAlreadyExistsException::what() const Q_DECL_NOEXCEPT
|
||||
{
|
||||
if (what_.isEmpty()) {
|
||||
what_ += Utf8StringLiteral("Translation unit '")
|
||||
+ fileContainer_.filePath()
|
||||
+ Utf8StringLiteral("' with the project part id '")
|
||||
+ fileContainer_.projectPartId()
|
||||
+ Utf8StringLiteral("' already exists!");
|
||||
}
|
||||
|
||||
return what_.constData();
|
||||
}
|
||||
|
||||
DocumentDoesNotExistException::DocumentDoesNotExistException(
|
||||
const FileContainer &fileContainer)
|
||||
: fileContainer_(fileContainer)
|
||||
{
|
||||
}
|
||||
|
||||
DocumentDoesNotExistException::DocumentDoesNotExistException(
|
||||
const Utf8String &filePath,
|
||||
const Utf8String &projectPartId)
|
||||
: fileContainer_(filePath, projectPartId)
|
||||
{
|
||||
}
|
||||
|
||||
const FileContainer &DocumentDoesNotExistException::fileContainer() const
|
||||
{
|
||||
return fileContainer_;
|
||||
}
|
||||
|
||||
const char *DocumentDoesNotExistException::what() const Q_DECL_NOEXCEPT
|
||||
{
|
||||
if (what_.isEmpty())
|
||||
what_ += Utf8StringLiteral("Translation unit '")
|
||||
+ fileContainer_.filePath()
|
||||
+ Utf8StringLiteral("' with the project part id '")
|
||||
+ fileContainer_.projectPartId()
|
||||
+ Utf8StringLiteral("' does not exits!");
|
||||
|
||||
return what_.constData();
|
||||
m_info += Utf8StringLiteral("Document '")
|
||||
+ filePath
|
||||
+ Utf8StringLiteral("' with the project part id '")
|
||||
+ projectPartId
|
||||
+ Utf8StringLiteral("' does not exits!");
|
||||
}
|
||||
|
||||
DocumentFileDoesNotExistException::DocumentFileDoesNotExistException(
|
||||
const Utf8String &filePath)
|
||||
: filePath_(filePath)
|
||||
{
|
||||
m_info += Utf8StringLiteral("File ")
|
||||
+ filePath
|
||||
+ Utf8StringLiteral(" does not exist in file system!");
|
||||
}
|
||||
|
||||
const Utf8String &DocumentFileDoesNotExistException::filePath() const
|
||||
DocumentIsNullException::DocumentIsNullException()
|
||||
{
|
||||
return filePath_;
|
||||
}
|
||||
|
||||
const char *DocumentFileDoesNotExistException::what() const Q_DECL_NOEXCEPT
|
||||
{
|
||||
if (what_.isEmpty())
|
||||
what_ += Utf8StringLiteral("File ")
|
||||
+ filePath()
|
||||
+ Utf8StringLiteral(" does not exist in file system!");
|
||||
|
||||
return what_.constData();
|
||||
}
|
||||
|
||||
const char *DocumentIsNullException::what() const Q_DECL_NOEXCEPT
|
||||
{
|
||||
return "Tried to access a null TranslationUnit!";
|
||||
}
|
||||
|
||||
TranslationUnitParseErrorException::TranslationUnitParseErrorException(
|
||||
const Utf8String &filePath,
|
||||
const Utf8String &projectPartId,
|
||||
CXErrorCode errorCode)
|
||||
: filePath_(filePath),
|
||||
projectPartId_(projectPartId),
|
||||
errorCode_(errorCode)
|
||||
{
|
||||
}
|
||||
|
||||
const Utf8String &TranslationUnitParseErrorException::filePath() const
|
||||
{
|
||||
return filePath_;
|
||||
}
|
||||
|
||||
const Utf8String &TranslationUnitParseErrorException::projectPartId() const
|
||||
{
|
||||
return projectPartId_;
|
||||
}
|
||||
|
||||
#define RETURN_TEXT_FOR_CASE(enumValue) case enumValue: return #enumValue
|
||||
static const char *errorCodeToText(CXErrorCode errorCode)
|
||||
{
|
||||
switch (errorCode) {
|
||||
RETURN_TEXT_FOR_CASE(CXError_Success);
|
||||
RETURN_TEXT_FOR_CASE(CXError_Failure);
|
||||
RETURN_TEXT_FOR_CASE(CXError_Crashed);
|
||||
RETURN_TEXT_FOR_CASE(CXError_InvalidArguments);
|
||||
RETURN_TEXT_FOR_CASE(CXError_ASTReadError);
|
||||
}
|
||||
|
||||
return "UnknownCXErrorCode";
|
||||
}
|
||||
#undef RETURN_TEXT_FOR_CASE
|
||||
|
||||
const char *TranslationUnitParseErrorException::what() const Q_DECL_NOEXCEPT
|
||||
{
|
||||
if (what_.isEmpty()) {
|
||||
what_ += Utf8StringLiteral("clang_parseTranslationUnit() failed for file ")
|
||||
+ filePath()
|
||||
+ Utf8StringLiteral(" in project ")
|
||||
+ projectPartId()
|
||||
+ Utf8StringLiteral(": ")
|
||||
+ Utf8String::fromUtf8(errorCodeToText(errorCode_))
|
||||
+ Utf8StringLiteral(".");
|
||||
}
|
||||
|
||||
return what_.constData();
|
||||
}
|
||||
|
||||
TranslationUnitReparseErrorException::TranslationUnitReparseErrorException(
|
||||
const Utf8String &filePath,
|
||||
const Utf8String &projectPartId,
|
||||
int errorCode)
|
||||
: filePath_(filePath),
|
||||
projectPartId_(projectPartId),
|
||||
errorCode_(errorCode)
|
||||
{
|
||||
}
|
||||
|
||||
const Utf8String &TranslationUnitReparseErrorException::filePath() const
|
||||
{
|
||||
return filePath_;
|
||||
}
|
||||
|
||||
const Utf8String &TranslationUnitReparseErrorException::projectPartId() const
|
||||
{
|
||||
return projectPartId_;
|
||||
}
|
||||
|
||||
const char *TranslationUnitReparseErrorException::what() const Q_DECL_NOEXCEPT
|
||||
{
|
||||
if (what_.isEmpty()) {
|
||||
what_ += Utf8StringLiteral("clang_reparseTranslationUnit() failed for file ")
|
||||
+ filePath()
|
||||
+ Utf8StringLiteral(" in project ")
|
||||
+ projectPartId()
|
||||
+ Utf8StringLiteral(": ")
|
||||
+ Utf8String::fromString(QString::number(errorCode_))
|
||||
+ Utf8StringLiteral(".");
|
||||
}
|
||||
|
||||
return what_.constData();
|
||||
m_info = Utf8String::fromUtf8("Tried to access a null Document!");
|
||||
}
|
||||
|
||||
} // namespace ClangBackEnd
|
||||
|
||||
Reference in New Issue
Block a user