Commit 3629aa90 authored by Christian Stenger's avatar Christian Stenger
Browse files

Fetch current project always before accessing



This fixes two different crashes when TestCodeParser tried
to access m_currentProject, but the object this pointer was
referencing had been deleted already.

Change-Id: Ie59e027394e613a8ef1e4f32f97abed6e8cb007a
Reviewed-by: default avatarTim Jenssen <tim.jenssen@theqtcompany.com>
parent 2aa7ce73
......@@ -49,7 +49,6 @@ namespace Internal {
TestCodeParser::TestCodeParser(TestTreeModel *parent)
: QObject(parent),
m_model(parent),
m_currentProject(0),
m_parserEnabled(true),
m_pendingUpdate(false)
{
......@@ -70,6 +69,14 @@ void TestCodeParser::emitUpdateTestTree()
QTimer::singleShot(1000, this, SLOT(updateTestTree()));
}
ProjectExplorer::Project *currentProject()
{
const ProjectExplorer::SessionManager *session = ProjectExplorer::SessionManager::instance();
if (!session || !session->hasProjects())
return 0;
return session->startupProject();
}
void TestCodeParser::updateTestTree()
{
if (!m_parserEnabled) {
......@@ -83,29 +90,15 @@ void TestCodeParser::updateTestTree()
clearMaps();
m_model->removeAllAutoTests();
m_model->removeAllQuickTests();
const ProjectExplorer::SessionManager *session = ProjectExplorer::SessionManager::instance();
if (!session || !session->hasProjects()) {
if (m_currentProject) {
if (QmakeProjectManager::QmakeProject *qmproj
= qobject_cast<QmakeProjectManager::QmakeProject *>(m_currentProject)) {
disconnect(qmproj, &QmakeProjectManager::QmakeProject::proFilesEvaluated,
this, &TestCodeParser::onProFileEvaluated);
}
if (ProjectExplorer::Project *proj = currentProject()) {
if (auto qmakeProject = qobject_cast<QmakeProjectManager::QmakeProject *>(proj)) {
connect(qmakeProject, &QmakeProjectManager::QmakeProject::proFilesEvaluated,
this, &TestCodeParser::onProFileEvaluated, Qt::UniqueConnection);
}
m_currentProject = 0;
} else
return;
}
m_currentProject = session->startupProject();
if (!m_currentProject)
return;
else {
if (QmakeProjectManager::QmakeProject *qmproj
= qobject_cast<QmakeProjectManager::QmakeProject *>(m_currentProject)) {
connect(qmproj, &QmakeProjectManager::QmakeProject::proFilesEvaluated,
this, &TestCodeParser::onProFileEvaluated);
}
}
scanForTests();
m_pendingUpdate = false;
}
......@@ -568,7 +561,8 @@ void TestCodeParser::handleQtQuickTest(CPlusPlus::Document::Ptr doc)
void TestCodeParser::onCppDocumentUpdated(const CPlusPlus::Document::Ptr &doc)
{
if (!m_currentProject)
ProjectExplorer::Project *project = currentProject();
if (!project)
return;
const QString fileName = doc->fileName();
if (m_cppDocMap.contains(fileName)) {
......@@ -577,7 +571,7 @@ void TestCodeParser::onCppDocumentUpdated(const CPlusPlus::Document::Ptr &doc)
qDebug("Skipped due revision equality"); // added to verify if this ever happens..
return;
}
} else if (!m_currentProject->files(ProjectExplorer::Project::AllFiles).contains(fileName)) {
} else if (!project->files(ProjectExplorer::Project::AllFiles).contains(fileName)) {
return;
}
checkDocumentForTestCode(doc);
......@@ -585,7 +579,8 @@ void TestCodeParser::onCppDocumentUpdated(const CPlusPlus::Document::Ptr &doc)
void TestCodeParser::onQmlDocumentUpdated(const QmlJS::Document::Ptr &doc)
{
if (!m_currentProject)
ProjectExplorer::Project *project = currentProject();
if (!project)
return;
const QString fileName = doc->fileName();
if (m_quickDocMap.contains(fileName)) {
......@@ -593,7 +588,7 @@ void TestCodeParser::onQmlDocumentUpdated(const QmlJS::Document::Ptr &doc)
qDebug("Skipped due revision equality (QML)"); // added to verify this ever happens....
return;
}
} else if (!m_currentProject->files(ProjectExplorer::Project::AllFiles).contains(fileName)) {
} else if (!project->files(ProjectExplorer::Project::AllFiles).contains(fileName)) {
// what if the file is not listed inside the pro file, but will be used anyway?
return;
}
......@@ -627,7 +622,7 @@ void TestCodeParser::scanForTests(const QStringList &fileList)
{
QStringList list;
if (fileList.isEmpty()) {
list = m_currentProject->files(ProjectExplorer::Project::AllFiles);
list = currentProject()->files(ProjectExplorer::Project::AllFiles);
} else {
list << fileList;
}
......@@ -767,11 +762,12 @@ void TestCodeParser::onAllTasksFinished(Core::Id type)
void TestCodeParser::onProFileEvaluated()
{
if (!m_currentProject)
ProjectExplorer::Project *project = currentProject();
if (!project)
return;
CppTools::CppModelManager *cppMM = CppTools::CppModelManager::instance();
const QList<CppTools::ProjectPart::Ptr> pp = cppMM->projectInfo(m_currentProject).projectParts();
const QList<CppTools::ProjectPart::Ptr> pp = cppMM->projectInfo(project).projectParts();
foreach (const CppTools::ProjectPart::Ptr &p, pp) {
if (!p->selectedForBuilding)
removeTestsIfNecessaryByProFile(p->projectFile);
......
......@@ -26,10 +26,6 @@
#include <QObject>
#include <QMap>
namespace ProjectExplorer {
class Project;
}
namespace Core {
class Id;
}
......@@ -71,7 +67,6 @@ private:
TestTreeModel *m_model;
QMap<QString, TestInfo> m_cppDocMap;
QMap<QString, TestInfo> m_quickDocMap;
ProjectExplorer::Project *m_currentProject;
bool m_parserEnabled;
bool m_pendingUpdate;
};
......
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