Commit 488bf917 authored by Nikolai Kosjar's avatar Nikolai Kosjar

CppTools: Always check for a valid BuiltinEditorDocumentParser*

This fixes a crash if the include hierarchy sidebar is invoked with the
clang code model. BuiltinEditorDocumentParser::get(editorFilePath)
returns 0 in that case.

Task-number: QTCREATORBUG-13553
Change-Id: I9292691c8156bdaaffcac1c3864201ba8a6cbdef
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@theqtcompany.com>
parent 2fc4acbc
......@@ -40,6 +40,7 @@
#include <cplusplus/CppDocument.h>
#include <utils/fileutils.h>
#include <utils/qtcassert.h>
#include <QSet>
......@@ -183,8 +184,9 @@ void CppIncludeHierarchyModel::fetchMore(const QModelIndex &parent)
}
if (item == m_includesItem) {
const Snapshot editorDocumentSnapshot
= BuiltinEditorDocumentParser::get(editorFilePath)->snapshot();
auto *parser = BuiltinEditorDocumentParser::get(editorFilePath);
QTC_ASSERT(parser, return);
const Snapshot editorDocumentSnapshot = parser->snapshot();
buildHierarchyIncludes_helper(parentItem->filePath(), parentItem,
editorDocumentSnapshot, &cyclic);
} else {
......@@ -284,7 +286,9 @@ void CppIncludeHierarchyModel::buildHierarchyIncludes(const QString &currentFile
return;
const QString editorFilePath = m_editor->document()->filePath();
const Snapshot snapshot = BuiltinEditorDocumentParser::get(editorFilePath)->snapshot();
auto *parser = BuiltinEditorDocumentParser::get(editorFilePath);
QTC_ASSERT(parser, return);
const Snapshot snapshot = parser->snapshot();
QSet<QString> cyclic;
buildHierarchyIncludes_helper(currentFilePath, m_includesItem, snapshot, &cyclic);
}
......
......@@ -946,7 +946,8 @@ void CppToolsPlugin::test_modelmanager_precompiled_headers()
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
QVERIFY(mm->isCppEditor(editor));
BuiltinEditorDocumentParser *parser = BuiltinEditorDocumentParser::get(fileName);
auto *parser = BuiltinEditorDocumentParser::get(fileName);
QVERIFY(parser);
parser->setUsePrecompiledHeaders(true);
parser->update(mm->workingCopy());
......
......@@ -143,7 +143,7 @@ void CppToolsPlugin::test_cppsourceprocessor_includes_cyclic()
// Check editor snapshot
const QString filePath = editor->document()->filePath();
BuiltinEditorDocumentParser *parser = BuiltinEditorDocumentParser::get(filePath);
auto *parser = BuiltinEditorDocumentParser::get(filePath);
QVERIFY(parser);
Snapshot snapshot = parser->snapshot();
QCOMPARE(snapshot.size(), 3); // Configuration file included
......
......@@ -196,9 +196,14 @@ public:
}
// Compare
const Document::Ptr cppDocument = BuiltinEditorDocumentParser::get(cppFile)->document();
BuiltinEditorDocumentParser *cppDocumentParser = BuiltinEditorDocumentParser::get(cppFile);
QVERIFY(cppDocumentParser);
const Document::Ptr cppDocument = cppDocumentParser->document();
QVERIFY(checkDiagsnosticMessages(cppDocument));
const Document::Ptr hDocument = BuiltinEditorDocumentParser::get(hFile)->document();
BuiltinEditorDocumentParser *hDocumentParser = BuiltinEditorDocumentParser::get(hFile);
QVERIFY(hDocumentParser);
const Document::Ptr hDocument = hDocumentParser->document();
QVERIFY(checkDiagsnosticMessages(hDocument));
QVERIFY(documentContainsFunctionDefinition(cppDocument,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment